/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 | 4.89k | { |
47 | 4.89k | PyObject *return_value = NULL; |
48 | 4.89k | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
49 | | |
50 | 4.89k | #define NUM_KEYWORDS 3 |
51 | 4.89k | static struct { |
52 | 4.89k | PyGC_Head _this_is_not_used; |
53 | 4.89k | PyObject_VAR_HEAD |
54 | 4.89k | Py_hash_t ob_hash; |
55 | 4.89k | PyObject *ob_item[NUM_KEYWORDS]; |
56 | 4.89k | } _kwtuple = { |
57 | 4.89k | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
58 | 4.89k | .ob_hash = -1, |
59 | 4.89k | .ob_item = { &_Py_ID(path), &_Py_ID(dir_fd), &_Py_ID(follow_symlinks), }, |
60 | 4.89k | }; |
61 | 4.89k | #undef NUM_KEYWORDS |
62 | 4.89k | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
63 | | |
64 | | #else // !Py_BUILD_CORE |
65 | | # define KWTUPLE NULL |
66 | | #endif // !Py_BUILD_CORE |
67 | | |
68 | 4.89k | static const char * const _keywords[] = {"path", "dir_fd", "follow_symlinks", NULL}; |
69 | 4.89k | static _PyArg_Parser _parser = { |
70 | 4.89k | .keywords = _keywords, |
71 | 4.89k | .fname = "stat", |
72 | 4.89k | .kwtuple = KWTUPLE, |
73 | 4.89k | }; |
74 | 4.89k | #undef KWTUPLE |
75 | 4.89k | PyObject *argsbuf[3]; |
76 | 4.89k | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
77 | 4.89k | path_t path = PATH_T_INITIALIZE_P("stat", "path", 0, 0, 0, 1); |
78 | 4.89k | int dir_fd = DEFAULT_DIR_FD; |
79 | 4.89k | int follow_symlinks = 1; |
80 | | |
81 | 4.89k | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
82 | 4.89k | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
83 | 4.89k | if (!args) { |
84 | 0 | goto exit; |
85 | 0 | } |
86 | 4.89k | if (!path_converter(args[0], &path)) { |
87 | 0 | goto exit; |
88 | 0 | } |
89 | 4.89k | if (!noptargs) { |
90 | 4.89k | goto skip_optional_kwonly; |
91 | 4.89k | } |
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 | 4.89k | skip_optional_kwonly: |
105 | 4.89k | return_value = os_stat_impl(module, &path, dir_fd, follow_symlinks); |
106 | | |
107 | 4.89k | exit: |
108 | | /* Cleanup for path */ |
109 | 4.89k | path_cleanup(&path); |
110 | | |
111 | 4.89k | return return_value; |
112 | 4.89k | } |
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 user\n" |
219 | | " 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 | 119 | { |
1639 | 119 | PyObject *return_value = NULL; |
1640 | 119 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
1641 | | |
1642 | 119 | #define NUM_KEYWORDS 1 |
1643 | 119 | static struct { |
1644 | 119 | PyGC_Head _this_is_not_used; |
1645 | 119 | PyObject_VAR_HEAD |
1646 | 119 | Py_hash_t ob_hash; |
1647 | 119 | PyObject *ob_item[NUM_KEYWORDS]; |
1648 | 119 | } _kwtuple = { |
1649 | 119 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
1650 | 119 | .ob_hash = -1, |
1651 | 119 | .ob_item = { &_Py_ID(path), }, |
1652 | 119 | }; |
1653 | 119 | #undef NUM_KEYWORDS |
1654 | 119 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
1655 | | |
1656 | | #else // !Py_BUILD_CORE |
1657 | | # define KWTUPLE NULL |
1658 | | #endif // !Py_BUILD_CORE |
1659 | | |
1660 | 119 | static const char * const _keywords[] = {"path", NULL}; |
1661 | 119 | static _PyArg_Parser _parser = { |
1662 | 119 | .keywords = _keywords, |
1663 | 119 | .fname = "listdir", |
1664 | 119 | .kwtuple = KWTUPLE, |
1665 | 119 | }; |
1666 | 119 | #undef KWTUPLE |
1667 | 119 | PyObject *argsbuf[1]; |
1668 | 119 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; |
1669 | 119 | path_t path = PATH_T_INITIALIZE_P("listdir", "path", 1, 0, 0, PATH_HAVE_FDOPENDIR); |
1670 | | |
1671 | 119 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
1672 | 119 | /*minpos*/ 0, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
1673 | 119 | if (!args) { |
1674 | 0 | goto exit; |
1675 | 0 | } |
1676 | 119 | if (!noptargs) { |
1677 | 0 | goto skip_optional_pos; |
1678 | 0 | } |
1679 | 119 | if (!path_converter(args[0], &path)) { |
1680 | 0 | goto exit; |
1681 | 0 | } |
1682 | 119 | skip_optional_pos: |
1683 | 119 | return_value = os_listdir_impl(module, &path); |
1684 | | |
1685 | 119 | exit: |
1686 | | /* Cleanup for path */ |
1687 | 119 | path_cleanup(&path); |
1688 | | |
1689 | 119 | return return_value; |
1690 | 119 | } |
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_CAST(os__path_splitroot), METH_FASTCALL|METH_KEYWORDS, 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 *const *args, Py_ssize_t nargs, PyObject *kwnames) |
2060 | | { |
2061 | | PyObject *return_value = NULL; |
2062 | | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
2063 | | |
2064 | | #define NUM_KEYWORDS 1 |
2065 | | static struct { |
2066 | | PyGC_Head _this_is_not_used; |
2067 | | PyObject_VAR_HEAD |
2068 | | Py_hash_t ob_hash; |
2069 | | PyObject *ob_item[NUM_KEYWORDS]; |
2070 | | } _kwtuple = { |
2071 | | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
2072 | | .ob_hash = -1, |
2073 | | .ob_item = { &_Py_ID(path), }, |
2074 | | }; |
2075 | | #undef NUM_KEYWORDS |
2076 | | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
2077 | | |
2078 | | #else // !Py_BUILD_CORE |
2079 | | # define KWTUPLE NULL |
2080 | | #endif // !Py_BUILD_CORE |
2081 | | |
2082 | | static const char * const _keywords[] = {"path", NULL}; |
2083 | | static _PyArg_Parser _parser = { |
2084 | | .keywords = _keywords, |
2085 | | .fname = "_path_splitroot", |
2086 | | .kwtuple = KWTUPLE, |
2087 | | }; |
2088 | | #undef KWTUPLE |
2089 | | PyObject *argsbuf[1]; |
2090 | | path_t path = PATH_T_INITIALIZE_P("_path_splitroot", "path", 0, 0, 0, 0); |
2091 | | |
2092 | | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
2093 | | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
2094 | | if (!args) { |
2095 | | goto exit; |
2096 | | } |
2097 | | if (!path_converter(args[0], &path)) { |
2098 | | goto exit; |
2099 | | } |
2100 | | return_value = os__path_splitroot_impl(module, &path); |
2101 | | |
2102 | | exit: |
2103 | | /* Cleanup for path */ |
2104 | | path_cleanup(&path); |
2105 | | |
2106 | | return return_value; |
2107 | | } |
2108 | | |
2109 | | #endif /* defined(MS_WINDOWS) */ |
2110 | | |
2111 | | #if defined(MS_WINDOWS) |
2112 | | |
2113 | | PyDoc_STRVAR(os__path_exists__doc__, |
2114 | | "_path_exists($module, /, path)\n" |
2115 | | "--\n" |
2116 | | "\n" |
2117 | | "Test whether a path exists. Returns False for broken symbolic links."); |
2118 | | |
2119 | | #define OS__PATH_EXISTS_METHODDEF \ |
2120 | | {"_path_exists", _PyCFunction_CAST(os__path_exists), METH_FASTCALL|METH_KEYWORDS, os__path_exists__doc__}, |
2121 | | |
2122 | | static int |
2123 | | os__path_exists_impl(PyObject *module, path_t *path); |
2124 | | |
2125 | | static PyObject * |
2126 | | os__path_exists(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
2127 | | { |
2128 | | PyObject *return_value = NULL; |
2129 | | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
2130 | | |
2131 | | #define NUM_KEYWORDS 1 |
2132 | | static struct { |
2133 | | PyGC_Head _this_is_not_used; |
2134 | | PyObject_VAR_HEAD |
2135 | | Py_hash_t ob_hash; |
2136 | | PyObject *ob_item[NUM_KEYWORDS]; |
2137 | | } _kwtuple = { |
2138 | | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
2139 | | .ob_hash = -1, |
2140 | | .ob_item = { &_Py_ID(path), }, |
2141 | | }; |
2142 | | #undef NUM_KEYWORDS |
2143 | | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
2144 | | |
2145 | | #else // !Py_BUILD_CORE |
2146 | | # define KWTUPLE NULL |
2147 | | #endif // !Py_BUILD_CORE |
2148 | | |
2149 | | static const char * const _keywords[] = {"path", NULL}; |
2150 | | static _PyArg_Parser _parser = { |
2151 | | .keywords = _keywords, |
2152 | | .fname = "_path_exists", |
2153 | | .kwtuple = KWTUPLE, |
2154 | | }; |
2155 | | #undef KWTUPLE |
2156 | | PyObject *argsbuf[1]; |
2157 | | path_t path = PATH_T_INITIALIZE_P("_path_exists", "path", 0, 0, 1, 1); |
2158 | | int _return_value; |
2159 | | |
2160 | | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
2161 | | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
2162 | | if (!args) { |
2163 | | goto exit; |
2164 | | } |
2165 | | if (!path_converter(args[0], &path)) { |
2166 | | goto exit; |
2167 | | } |
2168 | | _return_value = os__path_exists_impl(module, &path); |
2169 | | if ((_return_value == -1) && PyErr_Occurred()) { |
2170 | | goto exit; |
2171 | | } |
2172 | | return_value = PyBool_FromLong((long)_return_value); |
2173 | | |
2174 | | exit: |
2175 | | /* Cleanup for path */ |
2176 | | path_cleanup(&path); |
2177 | | |
2178 | | return return_value; |
2179 | | } |
2180 | | |
2181 | | #endif /* defined(MS_WINDOWS) */ |
2182 | | |
2183 | | #if defined(MS_WINDOWS) |
2184 | | |
2185 | | PyDoc_STRVAR(os__path_lexists__doc__, |
2186 | | "_path_lexists($module, /, path)\n" |
2187 | | "--\n" |
2188 | | "\n" |
2189 | | "Test whether a path exists. Returns True for broken symbolic links."); |
2190 | | |
2191 | | #define OS__PATH_LEXISTS_METHODDEF \ |
2192 | | {"_path_lexists", _PyCFunction_CAST(os__path_lexists), METH_FASTCALL|METH_KEYWORDS, os__path_lexists__doc__}, |
2193 | | |
2194 | | static int |
2195 | | os__path_lexists_impl(PyObject *module, path_t *path); |
2196 | | |
2197 | | static PyObject * |
2198 | | os__path_lexists(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
2199 | | { |
2200 | | PyObject *return_value = NULL; |
2201 | | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
2202 | | |
2203 | | #define NUM_KEYWORDS 1 |
2204 | | static struct { |
2205 | | PyGC_Head _this_is_not_used; |
2206 | | PyObject_VAR_HEAD |
2207 | | Py_hash_t ob_hash; |
2208 | | PyObject *ob_item[NUM_KEYWORDS]; |
2209 | | } _kwtuple = { |
2210 | | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
2211 | | .ob_hash = -1, |
2212 | | .ob_item = { &_Py_ID(path), }, |
2213 | | }; |
2214 | | #undef NUM_KEYWORDS |
2215 | | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
2216 | | |
2217 | | #else // !Py_BUILD_CORE |
2218 | | # define KWTUPLE NULL |
2219 | | #endif // !Py_BUILD_CORE |
2220 | | |
2221 | | static const char * const _keywords[] = {"path", NULL}; |
2222 | | static _PyArg_Parser _parser = { |
2223 | | .keywords = _keywords, |
2224 | | .fname = "_path_lexists", |
2225 | | .kwtuple = KWTUPLE, |
2226 | | }; |
2227 | | #undef KWTUPLE |
2228 | | PyObject *argsbuf[1]; |
2229 | | path_t path = PATH_T_INITIALIZE_P("_path_lexists", "path", 0, 0, 1, 1); |
2230 | | int _return_value; |
2231 | | |
2232 | | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
2233 | | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
2234 | | if (!args) { |
2235 | | goto exit; |
2236 | | } |
2237 | | if (!path_converter(args[0], &path)) { |
2238 | | goto exit; |
2239 | | } |
2240 | | _return_value = os__path_lexists_impl(module, &path); |
2241 | | if ((_return_value == -1) && PyErr_Occurred()) { |
2242 | | goto exit; |
2243 | | } |
2244 | | return_value = PyBool_FromLong((long)_return_value); |
2245 | | |
2246 | | exit: |
2247 | | /* Cleanup for path */ |
2248 | | path_cleanup(&path); |
2249 | | |
2250 | | return return_value; |
2251 | | } |
2252 | | |
2253 | | #endif /* defined(MS_WINDOWS) */ |
2254 | | |
2255 | | #if defined(MS_WINDOWS) |
2256 | | |
2257 | | PyDoc_STRVAR(os__path_isdir__doc__, |
2258 | | "_path_isdir($module, /, s)\n" |
2259 | | "--\n" |
2260 | | "\n" |
2261 | | "Return true if the pathname refers to an existing directory."); |
2262 | | |
2263 | | #define OS__PATH_ISDIR_METHODDEF \ |
2264 | | {"_path_isdir", _PyCFunction_CAST(os__path_isdir), METH_FASTCALL|METH_KEYWORDS, os__path_isdir__doc__}, |
2265 | | |
2266 | | static int |
2267 | | os__path_isdir_impl(PyObject *module, path_t *path); |
2268 | | |
2269 | | static PyObject * |
2270 | | os__path_isdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
2271 | | { |
2272 | | PyObject *return_value = NULL; |
2273 | | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
2274 | | |
2275 | | #define NUM_KEYWORDS 1 |
2276 | | static struct { |
2277 | | PyGC_Head _this_is_not_used; |
2278 | | PyObject_VAR_HEAD |
2279 | | Py_hash_t ob_hash; |
2280 | | PyObject *ob_item[NUM_KEYWORDS]; |
2281 | | } _kwtuple = { |
2282 | | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
2283 | | .ob_hash = -1, |
2284 | | .ob_item = { _Py_LATIN1_CHR('s'), }, |
2285 | | }; |
2286 | | #undef NUM_KEYWORDS |
2287 | | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
2288 | | |
2289 | | #else // !Py_BUILD_CORE |
2290 | | # define KWTUPLE NULL |
2291 | | #endif // !Py_BUILD_CORE |
2292 | | |
2293 | | static const char * const _keywords[] = {"s", NULL}; |
2294 | | static _PyArg_Parser _parser = { |
2295 | | .keywords = _keywords, |
2296 | | .fname = "_path_isdir", |
2297 | | .kwtuple = KWTUPLE, |
2298 | | }; |
2299 | | #undef KWTUPLE |
2300 | | PyObject *argsbuf[1]; |
2301 | | path_t path = PATH_T_INITIALIZE_P("_path_isdir", "path", 0, 0, 1, 1); |
2302 | | int _return_value; |
2303 | | |
2304 | | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
2305 | | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
2306 | | if (!args) { |
2307 | | goto exit; |
2308 | | } |
2309 | | if (!path_converter(args[0], &path)) { |
2310 | | goto exit; |
2311 | | } |
2312 | | _return_value = os__path_isdir_impl(module, &path); |
2313 | | if ((_return_value == -1) && PyErr_Occurred()) { |
2314 | | goto exit; |
2315 | | } |
2316 | | return_value = PyBool_FromLong((long)_return_value); |
2317 | | |
2318 | | exit: |
2319 | | /* Cleanup for path */ |
2320 | | path_cleanup(&path); |
2321 | | |
2322 | | return return_value; |
2323 | | } |
2324 | | |
2325 | | #endif /* defined(MS_WINDOWS) */ |
2326 | | |
2327 | | #if defined(MS_WINDOWS) |
2328 | | |
2329 | | PyDoc_STRVAR(os__path_isfile__doc__, |
2330 | | "_path_isfile($module, /, path)\n" |
2331 | | "--\n" |
2332 | | "\n" |
2333 | | "Test whether a path is a regular file"); |
2334 | | |
2335 | | #define OS__PATH_ISFILE_METHODDEF \ |
2336 | | {"_path_isfile", _PyCFunction_CAST(os__path_isfile), METH_FASTCALL|METH_KEYWORDS, os__path_isfile__doc__}, |
2337 | | |
2338 | | static int |
2339 | | os__path_isfile_impl(PyObject *module, path_t *path); |
2340 | | |
2341 | | static PyObject * |
2342 | | os__path_isfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
2343 | | { |
2344 | | PyObject *return_value = NULL; |
2345 | | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
2346 | | |
2347 | | #define NUM_KEYWORDS 1 |
2348 | | static struct { |
2349 | | PyGC_Head _this_is_not_used; |
2350 | | PyObject_VAR_HEAD |
2351 | | Py_hash_t ob_hash; |
2352 | | PyObject *ob_item[NUM_KEYWORDS]; |
2353 | | } _kwtuple = { |
2354 | | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
2355 | | .ob_hash = -1, |
2356 | | .ob_item = { &_Py_ID(path), }, |
2357 | | }; |
2358 | | #undef NUM_KEYWORDS |
2359 | | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
2360 | | |
2361 | | #else // !Py_BUILD_CORE |
2362 | | # define KWTUPLE NULL |
2363 | | #endif // !Py_BUILD_CORE |
2364 | | |
2365 | | static const char * const _keywords[] = {"path", NULL}; |
2366 | | static _PyArg_Parser _parser = { |
2367 | | .keywords = _keywords, |
2368 | | .fname = "_path_isfile", |
2369 | | .kwtuple = KWTUPLE, |
2370 | | }; |
2371 | | #undef KWTUPLE |
2372 | | PyObject *argsbuf[1]; |
2373 | | path_t path = PATH_T_INITIALIZE_P("_path_isfile", "path", 0, 0, 1, 1); |
2374 | | int _return_value; |
2375 | | |
2376 | | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
2377 | | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
2378 | | if (!args) { |
2379 | | goto exit; |
2380 | | } |
2381 | | if (!path_converter(args[0], &path)) { |
2382 | | goto exit; |
2383 | | } |
2384 | | _return_value = os__path_isfile_impl(module, &path); |
2385 | | if ((_return_value == -1) && PyErr_Occurred()) { |
2386 | | goto exit; |
2387 | | } |
2388 | | return_value = PyBool_FromLong((long)_return_value); |
2389 | | |
2390 | | exit: |
2391 | | /* Cleanup for path */ |
2392 | | path_cleanup(&path); |
2393 | | |
2394 | | return return_value; |
2395 | | } |
2396 | | |
2397 | | #endif /* defined(MS_WINDOWS) */ |
2398 | | |
2399 | | #if defined(MS_WINDOWS) |
2400 | | |
2401 | | PyDoc_STRVAR(os__path_islink__doc__, |
2402 | | "_path_islink($module, /, path)\n" |
2403 | | "--\n" |
2404 | | "\n" |
2405 | | "Test whether a path is a symbolic link"); |
2406 | | |
2407 | | #define OS__PATH_ISLINK_METHODDEF \ |
2408 | | {"_path_islink", _PyCFunction_CAST(os__path_islink), METH_FASTCALL|METH_KEYWORDS, os__path_islink__doc__}, |
2409 | | |
2410 | | static int |
2411 | | os__path_islink_impl(PyObject *module, path_t *path); |
2412 | | |
2413 | | static PyObject * |
2414 | | os__path_islink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
2415 | | { |
2416 | | PyObject *return_value = NULL; |
2417 | | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
2418 | | |
2419 | | #define NUM_KEYWORDS 1 |
2420 | | static struct { |
2421 | | PyGC_Head _this_is_not_used; |
2422 | | PyObject_VAR_HEAD |
2423 | | Py_hash_t ob_hash; |
2424 | | PyObject *ob_item[NUM_KEYWORDS]; |
2425 | | } _kwtuple = { |
2426 | | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
2427 | | .ob_hash = -1, |
2428 | | .ob_item = { &_Py_ID(path), }, |
2429 | | }; |
2430 | | #undef NUM_KEYWORDS |
2431 | | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
2432 | | |
2433 | | #else // !Py_BUILD_CORE |
2434 | | # define KWTUPLE NULL |
2435 | | #endif // !Py_BUILD_CORE |
2436 | | |
2437 | | static const char * const _keywords[] = {"path", NULL}; |
2438 | | static _PyArg_Parser _parser = { |
2439 | | .keywords = _keywords, |
2440 | | .fname = "_path_islink", |
2441 | | .kwtuple = KWTUPLE, |
2442 | | }; |
2443 | | #undef KWTUPLE |
2444 | | PyObject *argsbuf[1]; |
2445 | | path_t path = PATH_T_INITIALIZE_P("_path_islink", "path", 0, 0, 1, 1); |
2446 | | int _return_value; |
2447 | | |
2448 | | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
2449 | | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
2450 | | if (!args) { |
2451 | | goto exit; |
2452 | | } |
2453 | | if (!path_converter(args[0], &path)) { |
2454 | | goto exit; |
2455 | | } |
2456 | | _return_value = os__path_islink_impl(module, &path); |
2457 | | if ((_return_value == -1) && PyErr_Occurred()) { |
2458 | | goto exit; |
2459 | | } |
2460 | | return_value = PyBool_FromLong((long)_return_value); |
2461 | | |
2462 | | exit: |
2463 | | /* Cleanup for path */ |
2464 | | path_cleanup(&path); |
2465 | | |
2466 | | return return_value; |
2467 | | } |
2468 | | |
2469 | | #endif /* defined(MS_WINDOWS) */ |
2470 | | |
2471 | | #if defined(MS_WINDOWS) |
2472 | | |
2473 | | PyDoc_STRVAR(os__path_isjunction__doc__, |
2474 | | "_path_isjunction($module, /, path)\n" |
2475 | | "--\n" |
2476 | | "\n" |
2477 | | "Test whether a path is a junction"); |
2478 | | |
2479 | | #define OS__PATH_ISJUNCTION_METHODDEF \ |
2480 | | {"_path_isjunction", _PyCFunction_CAST(os__path_isjunction), METH_FASTCALL|METH_KEYWORDS, os__path_isjunction__doc__}, |
2481 | | |
2482 | | static int |
2483 | | os__path_isjunction_impl(PyObject *module, path_t *path); |
2484 | | |
2485 | | static PyObject * |
2486 | | os__path_isjunction(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
2487 | | { |
2488 | | PyObject *return_value = NULL; |
2489 | | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
2490 | | |
2491 | | #define NUM_KEYWORDS 1 |
2492 | | static struct { |
2493 | | PyGC_Head _this_is_not_used; |
2494 | | PyObject_VAR_HEAD |
2495 | | Py_hash_t ob_hash; |
2496 | | PyObject *ob_item[NUM_KEYWORDS]; |
2497 | | } _kwtuple = { |
2498 | | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
2499 | | .ob_hash = -1, |
2500 | | .ob_item = { &_Py_ID(path), }, |
2501 | | }; |
2502 | | #undef NUM_KEYWORDS |
2503 | | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
2504 | | |
2505 | | #else // !Py_BUILD_CORE |
2506 | | # define KWTUPLE NULL |
2507 | | #endif // !Py_BUILD_CORE |
2508 | | |
2509 | | static const char * const _keywords[] = {"path", NULL}; |
2510 | | static _PyArg_Parser _parser = { |
2511 | | .keywords = _keywords, |
2512 | | .fname = "_path_isjunction", |
2513 | | .kwtuple = KWTUPLE, |
2514 | | }; |
2515 | | #undef KWTUPLE |
2516 | | PyObject *argsbuf[1]; |
2517 | | path_t path = PATH_T_INITIALIZE_P("_path_isjunction", "path", 0, 0, 1, 1); |
2518 | | int _return_value; |
2519 | | |
2520 | | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
2521 | | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
2522 | | if (!args) { |
2523 | | goto exit; |
2524 | | } |
2525 | | if (!path_converter(args[0], &path)) { |
2526 | | goto exit; |
2527 | | } |
2528 | | _return_value = os__path_isjunction_impl(module, &path); |
2529 | | if ((_return_value == -1) && PyErr_Occurred()) { |
2530 | | goto exit; |
2531 | | } |
2532 | | return_value = PyBool_FromLong((long)_return_value); |
2533 | | |
2534 | | exit: |
2535 | | /* Cleanup for path */ |
2536 | | path_cleanup(&path); |
2537 | | |
2538 | | return return_value; |
2539 | | } |
2540 | | |
2541 | | #endif /* defined(MS_WINDOWS) */ |
2542 | | |
2543 | | PyDoc_STRVAR(os__path_splitroot_ex__doc__, |
2544 | | "_path_splitroot_ex($module, /, p)\n" |
2545 | | "--\n" |
2546 | | "\n" |
2547 | | "Split a pathname into drive, root and tail.\n" |
2548 | | "\n" |
2549 | | "The tail contains anything after the root."); |
2550 | | |
2551 | | #define OS__PATH_SPLITROOT_EX_METHODDEF \ |
2552 | | {"_path_splitroot_ex", _PyCFunction_CAST(os__path_splitroot_ex), METH_FASTCALL|METH_KEYWORDS, os__path_splitroot_ex__doc__}, |
2553 | | |
2554 | | static PyObject * |
2555 | | os__path_splitroot_ex_impl(PyObject *module, path_t *path); |
2556 | | |
2557 | | static PyObject * |
2558 | | os__path_splitroot_ex(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
2559 | 0 | { |
2560 | 0 | PyObject *return_value = NULL; |
2561 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
2562 | |
|
2563 | 0 | #define NUM_KEYWORDS 1 |
2564 | 0 | static struct { |
2565 | 0 | PyGC_Head _this_is_not_used; |
2566 | 0 | PyObject_VAR_HEAD |
2567 | 0 | Py_hash_t ob_hash; |
2568 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
2569 | 0 | } _kwtuple = { |
2570 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
2571 | 0 | .ob_hash = -1, |
2572 | 0 | .ob_item = { _Py_LATIN1_CHR('p'), }, |
2573 | 0 | }; |
2574 | 0 | #undef NUM_KEYWORDS |
2575 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
2576 | |
|
2577 | | #else // !Py_BUILD_CORE |
2578 | | # define KWTUPLE NULL |
2579 | | #endif // !Py_BUILD_CORE |
2580 | |
|
2581 | 0 | static const char * const _keywords[] = {"p", NULL}; |
2582 | 0 | static _PyArg_Parser _parser = { |
2583 | 0 | .keywords = _keywords, |
2584 | 0 | .fname = "_path_splitroot_ex", |
2585 | 0 | .kwtuple = KWTUPLE, |
2586 | 0 | }; |
2587 | 0 | #undef KWTUPLE |
2588 | 0 | PyObject *argsbuf[1]; |
2589 | 0 | path_t path = PATH_T_INITIALIZE("_path_splitroot_ex", "path", 0, 1, 1, 0, 0); |
2590 | |
|
2591 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
2592 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
2593 | 0 | if (!args) { |
2594 | 0 | goto exit; |
2595 | 0 | } |
2596 | 0 | if (!path_converter(args[0], &path)) { |
2597 | 0 | goto exit; |
2598 | 0 | } |
2599 | 0 | return_value = os__path_splitroot_ex_impl(module, &path); |
2600 | |
|
2601 | 0 | exit: |
2602 | | /* Cleanup for path */ |
2603 | 0 | path_cleanup(&path); |
2604 | |
|
2605 | 0 | return return_value; |
2606 | 0 | } |
2607 | | |
2608 | | PyDoc_STRVAR(os__path_normpath__doc__, |
2609 | | "_path_normpath($module, /, path)\n" |
2610 | | "--\n" |
2611 | | "\n" |
2612 | | "Normalize path, eliminating double slashes, etc."); |
2613 | | |
2614 | | #define OS__PATH_NORMPATH_METHODDEF \ |
2615 | | {"_path_normpath", _PyCFunction_CAST(os__path_normpath), METH_FASTCALL|METH_KEYWORDS, os__path_normpath__doc__}, |
2616 | | |
2617 | | static PyObject * |
2618 | | os__path_normpath_impl(PyObject *module, path_t *path); |
2619 | | |
2620 | | static PyObject * |
2621 | | os__path_normpath(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
2622 | 80 | { |
2623 | 80 | PyObject *return_value = NULL; |
2624 | 80 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
2625 | | |
2626 | 80 | #define NUM_KEYWORDS 1 |
2627 | 80 | static struct { |
2628 | 80 | PyGC_Head _this_is_not_used; |
2629 | 80 | PyObject_VAR_HEAD |
2630 | 80 | Py_hash_t ob_hash; |
2631 | 80 | PyObject *ob_item[NUM_KEYWORDS]; |
2632 | 80 | } _kwtuple = { |
2633 | 80 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
2634 | 80 | .ob_hash = -1, |
2635 | 80 | .ob_item = { &_Py_ID(path), }, |
2636 | 80 | }; |
2637 | 80 | #undef NUM_KEYWORDS |
2638 | 80 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
2639 | | |
2640 | | #else // !Py_BUILD_CORE |
2641 | | # define KWTUPLE NULL |
2642 | | #endif // !Py_BUILD_CORE |
2643 | | |
2644 | 80 | static const char * const _keywords[] = {"path", NULL}; |
2645 | 80 | static _PyArg_Parser _parser = { |
2646 | 80 | .keywords = _keywords, |
2647 | 80 | .fname = "_path_normpath", |
2648 | 80 | .kwtuple = KWTUPLE, |
2649 | 80 | }; |
2650 | 80 | #undef KWTUPLE |
2651 | 80 | PyObject *argsbuf[1]; |
2652 | 80 | path_t path = PATH_T_INITIALIZE("_path_normpath", "path", 0, 1, 1, 0, 0); |
2653 | | |
2654 | 80 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
2655 | 80 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
2656 | 80 | if (!args) { |
2657 | 0 | goto exit; |
2658 | 0 | } |
2659 | 80 | if (!path_converter(args[0], &path)) { |
2660 | 0 | goto exit; |
2661 | 0 | } |
2662 | 80 | return_value = os__path_normpath_impl(module, &path); |
2663 | | |
2664 | 80 | exit: |
2665 | | /* Cleanup for path */ |
2666 | 80 | path_cleanup(&path); |
2667 | | |
2668 | 80 | return return_value; |
2669 | 80 | } |
2670 | | |
2671 | | PyDoc_STRVAR(os_mkdir__doc__, |
2672 | | "mkdir($module, /, path, mode=511, *, dir_fd=None)\n" |
2673 | | "--\n" |
2674 | | "\n" |
2675 | | "Create a directory.\n" |
2676 | | "\n" |
2677 | | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
2678 | | " and path should be relative; path will then be relative to that directory.\n" |
2679 | | "dir_fd may not be implemented on your platform.\n" |
2680 | | " If it is unavailable, using it will raise a NotImplementedError.\n" |
2681 | | "\n" |
2682 | | "The mode argument is ignored on Windows. Where it is used, the current umask\n" |
2683 | | "value is first masked out."); |
2684 | | |
2685 | | #define OS_MKDIR_METHODDEF \ |
2686 | | {"mkdir", _PyCFunction_CAST(os_mkdir), METH_FASTCALL|METH_KEYWORDS, os_mkdir__doc__}, |
2687 | | |
2688 | | static PyObject * |
2689 | | os_mkdir_impl(PyObject *module, path_t *path, int mode, int dir_fd); |
2690 | | |
2691 | | static PyObject * |
2692 | | os_mkdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
2693 | 0 | { |
2694 | 0 | PyObject *return_value = NULL; |
2695 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
2696 | |
|
2697 | 0 | #define NUM_KEYWORDS 3 |
2698 | 0 | static struct { |
2699 | 0 | PyGC_Head _this_is_not_used; |
2700 | 0 | PyObject_VAR_HEAD |
2701 | 0 | Py_hash_t ob_hash; |
2702 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
2703 | 0 | } _kwtuple = { |
2704 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
2705 | 0 | .ob_hash = -1, |
2706 | 0 | .ob_item = { &_Py_ID(path), &_Py_ID(mode), &_Py_ID(dir_fd), }, |
2707 | 0 | }; |
2708 | 0 | #undef NUM_KEYWORDS |
2709 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
2710 | |
|
2711 | | #else // !Py_BUILD_CORE |
2712 | | # define KWTUPLE NULL |
2713 | | #endif // !Py_BUILD_CORE |
2714 | |
|
2715 | 0 | static const char * const _keywords[] = {"path", "mode", "dir_fd", NULL}; |
2716 | 0 | static _PyArg_Parser _parser = { |
2717 | 0 | .keywords = _keywords, |
2718 | 0 | .fname = "mkdir", |
2719 | 0 | .kwtuple = KWTUPLE, |
2720 | 0 | }; |
2721 | 0 | #undef KWTUPLE |
2722 | 0 | PyObject *argsbuf[3]; |
2723 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
2724 | 0 | path_t path = PATH_T_INITIALIZE_P("mkdir", "path", 0, 0, 0, 0); |
2725 | 0 | int mode = 511; |
2726 | 0 | int dir_fd = DEFAULT_DIR_FD; |
2727 | |
|
2728 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
2729 | 0 | /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
2730 | 0 | if (!args) { |
2731 | 0 | goto exit; |
2732 | 0 | } |
2733 | 0 | if (!path_converter(args[0], &path)) { |
2734 | 0 | goto exit; |
2735 | 0 | } |
2736 | 0 | if (!noptargs) { |
2737 | 0 | goto skip_optional_pos; |
2738 | 0 | } |
2739 | 0 | if (args[1]) { |
2740 | 0 | mode = PyLong_AsInt(args[1]); |
2741 | 0 | if (mode == -1 && PyErr_Occurred()) { |
2742 | 0 | goto exit; |
2743 | 0 | } |
2744 | 0 | if (!--noptargs) { |
2745 | 0 | goto skip_optional_pos; |
2746 | 0 | } |
2747 | 0 | } |
2748 | 0 | skip_optional_pos: |
2749 | 0 | if (!noptargs) { |
2750 | 0 | goto skip_optional_kwonly; |
2751 | 0 | } |
2752 | 0 | if (!MKDIRAT_DIR_FD_CONVERTER(args[2], &dir_fd)) { |
2753 | 0 | goto exit; |
2754 | 0 | } |
2755 | 0 | skip_optional_kwonly: |
2756 | 0 | return_value = os_mkdir_impl(module, &path, mode, dir_fd); |
2757 | |
|
2758 | 0 | exit: |
2759 | | /* Cleanup for path */ |
2760 | 0 | path_cleanup(&path); |
2761 | |
|
2762 | 0 | return return_value; |
2763 | 0 | } |
2764 | | |
2765 | | #if defined(HAVE_NICE) |
2766 | | |
2767 | | PyDoc_STRVAR(os_nice__doc__, |
2768 | | "nice($module, increment, /)\n" |
2769 | | "--\n" |
2770 | | "\n" |
2771 | | "Add increment to the priority of process and return the new priority."); |
2772 | | |
2773 | | #define OS_NICE_METHODDEF \ |
2774 | | {"nice", (PyCFunction)os_nice, METH_O, os_nice__doc__}, |
2775 | | |
2776 | | static PyObject * |
2777 | | os_nice_impl(PyObject *module, int increment); |
2778 | | |
2779 | | static PyObject * |
2780 | | os_nice(PyObject *module, PyObject *arg) |
2781 | 0 | { |
2782 | 0 | PyObject *return_value = NULL; |
2783 | 0 | int increment; |
2784 | |
|
2785 | 0 | increment = PyLong_AsInt(arg); |
2786 | 0 | if (increment == -1 && PyErr_Occurred()) { |
2787 | 0 | goto exit; |
2788 | 0 | } |
2789 | 0 | return_value = os_nice_impl(module, increment); |
2790 | |
|
2791 | 0 | exit: |
2792 | 0 | return return_value; |
2793 | 0 | } |
2794 | | |
2795 | | #endif /* defined(HAVE_NICE) */ |
2796 | | |
2797 | | #if defined(HAVE_GETPRIORITY) |
2798 | | |
2799 | | PyDoc_STRVAR(os_getpriority__doc__, |
2800 | | "getpriority($module, /, which, who)\n" |
2801 | | "--\n" |
2802 | | "\n" |
2803 | | "Return program scheduling priority."); |
2804 | | |
2805 | | #define OS_GETPRIORITY_METHODDEF \ |
2806 | | {"getpriority", _PyCFunction_CAST(os_getpriority), METH_FASTCALL|METH_KEYWORDS, os_getpriority__doc__}, |
2807 | | |
2808 | | static PyObject * |
2809 | | os_getpriority_impl(PyObject *module, int which, int who); |
2810 | | |
2811 | | static PyObject * |
2812 | | os_getpriority(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
2813 | 0 | { |
2814 | 0 | PyObject *return_value = NULL; |
2815 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
2816 | |
|
2817 | 0 | #define NUM_KEYWORDS 2 |
2818 | 0 | static struct { |
2819 | 0 | PyGC_Head _this_is_not_used; |
2820 | 0 | PyObject_VAR_HEAD |
2821 | 0 | Py_hash_t ob_hash; |
2822 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
2823 | 0 | } _kwtuple = { |
2824 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
2825 | 0 | .ob_hash = -1, |
2826 | 0 | .ob_item = { &_Py_ID(which), &_Py_ID(who), }, |
2827 | 0 | }; |
2828 | 0 | #undef NUM_KEYWORDS |
2829 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
2830 | |
|
2831 | | #else // !Py_BUILD_CORE |
2832 | | # define KWTUPLE NULL |
2833 | | #endif // !Py_BUILD_CORE |
2834 | |
|
2835 | 0 | static const char * const _keywords[] = {"which", "who", NULL}; |
2836 | 0 | static _PyArg_Parser _parser = { |
2837 | 0 | .keywords = _keywords, |
2838 | 0 | .fname = "getpriority", |
2839 | 0 | .kwtuple = KWTUPLE, |
2840 | 0 | }; |
2841 | 0 | #undef KWTUPLE |
2842 | 0 | PyObject *argsbuf[2]; |
2843 | 0 | int which; |
2844 | 0 | int who; |
2845 | |
|
2846 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
2847 | 0 | /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
2848 | 0 | if (!args) { |
2849 | 0 | goto exit; |
2850 | 0 | } |
2851 | 0 | which = PyLong_AsInt(args[0]); |
2852 | 0 | if (which == -1 && PyErr_Occurred()) { |
2853 | 0 | goto exit; |
2854 | 0 | } |
2855 | 0 | who = PyLong_AsInt(args[1]); |
2856 | 0 | if (who == -1 && PyErr_Occurred()) { |
2857 | 0 | goto exit; |
2858 | 0 | } |
2859 | 0 | return_value = os_getpriority_impl(module, which, who); |
2860 | |
|
2861 | 0 | exit: |
2862 | 0 | return return_value; |
2863 | 0 | } |
2864 | | |
2865 | | #endif /* defined(HAVE_GETPRIORITY) */ |
2866 | | |
2867 | | #if defined(HAVE_SETPRIORITY) |
2868 | | |
2869 | | PyDoc_STRVAR(os_setpriority__doc__, |
2870 | | "setpriority($module, /, which, who, priority)\n" |
2871 | | "--\n" |
2872 | | "\n" |
2873 | | "Set program scheduling priority."); |
2874 | | |
2875 | | #define OS_SETPRIORITY_METHODDEF \ |
2876 | | {"setpriority", _PyCFunction_CAST(os_setpriority), METH_FASTCALL|METH_KEYWORDS, os_setpriority__doc__}, |
2877 | | |
2878 | | static PyObject * |
2879 | | os_setpriority_impl(PyObject *module, int which, int who, int priority); |
2880 | | |
2881 | | static PyObject * |
2882 | | os_setpriority(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
2883 | 0 | { |
2884 | 0 | PyObject *return_value = NULL; |
2885 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
2886 | |
|
2887 | 0 | #define NUM_KEYWORDS 3 |
2888 | 0 | static struct { |
2889 | 0 | PyGC_Head _this_is_not_used; |
2890 | 0 | PyObject_VAR_HEAD |
2891 | 0 | Py_hash_t ob_hash; |
2892 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
2893 | 0 | } _kwtuple = { |
2894 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
2895 | 0 | .ob_hash = -1, |
2896 | 0 | .ob_item = { &_Py_ID(which), &_Py_ID(who), &_Py_ID(priority), }, |
2897 | 0 | }; |
2898 | 0 | #undef NUM_KEYWORDS |
2899 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
2900 | |
|
2901 | | #else // !Py_BUILD_CORE |
2902 | | # define KWTUPLE NULL |
2903 | | #endif // !Py_BUILD_CORE |
2904 | |
|
2905 | 0 | static const char * const _keywords[] = {"which", "who", "priority", NULL}; |
2906 | 0 | static _PyArg_Parser _parser = { |
2907 | 0 | .keywords = _keywords, |
2908 | 0 | .fname = "setpriority", |
2909 | 0 | .kwtuple = KWTUPLE, |
2910 | 0 | }; |
2911 | 0 | #undef KWTUPLE |
2912 | 0 | PyObject *argsbuf[3]; |
2913 | 0 | int which; |
2914 | 0 | int who; |
2915 | 0 | int priority; |
2916 | |
|
2917 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
2918 | 0 | /*minpos*/ 3, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
2919 | 0 | if (!args) { |
2920 | 0 | goto exit; |
2921 | 0 | } |
2922 | 0 | which = PyLong_AsInt(args[0]); |
2923 | 0 | if (which == -1 && PyErr_Occurred()) { |
2924 | 0 | goto exit; |
2925 | 0 | } |
2926 | 0 | who = PyLong_AsInt(args[1]); |
2927 | 0 | if (who == -1 && PyErr_Occurred()) { |
2928 | 0 | goto exit; |
2929 | 0 | } |
2930 | 0 | priority = PyLong_AsInt(args[2]); |
2931 | 0 | if (priority == -1 && PyErr_Occurred()) { |
2932 | 0 | goto exit; |
2933 | 0 | } |
2934 | 0 | return_value = os_setpriority_impl(module, which, who, priority); |
2935 | |
|
2936 | 0 | exit: |
2937 | 0 | return return_value; |
2938 | 0 | } |
2939 | | |
2940 | | #endif /* defined(HAVE_SETPRIORITY) */ |
2941 | | |
2942 | | PyDoc_STRVAR(os_rename__doc__, |
2943 | | "rename($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None)\n" |
2944 | | "--\n" |
2945 | | "\n" |
2946 | | "Rename a file or directory.\n" |
2947 | | "\n" |
2948 | | "If either src_dir_fd or dst_dir_fd is not None, it should be a file\n" |
2949 | | " descriptor open to a directory, and the respective path string (src or dst)\n" |
2950 | | " should be relative; the path will then be relative to that directory.\n" |
2951 | | "src_dir_fd and dst_dir_fd, may not be implemented on your platform.\n" |
2952 | | " If they are unavailable, using them will raise a NotImplementedError."); |
2953 | | |
2954 | | #define OS_RENAME_METHODDEF \ |
2955 | | {"rename", _PyCFunction_CAST(os_rename), METH_FASTCALL|METH_KEYWORDS, os_rename__doc__}, |
2956 | | |
2957 | | static PyObject * |
2958 | | os_rename_impl(PyObject *module, path_t *src, path_t *dst, int src_dir_fd, |
2959 | | int dst_dir_fd); |
2960 | | |
2961 | | static PyObject * |
2962 | | os_rename(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
2963 | 0 | { |
2964 | 0 | PyObject *return_value = NULL; |
2965 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
2966 | |
|
2967 | 0 | #define NUM_KEYWORDS 4 |
2968 | 0 | static struct { |
2969 | 0 | PyGC_Head _this_is_not_used; |
2970 | 0 | PyObject_VAR_HEAD |
2971 | 0 | Py_hash_t ob_hash; |
2972 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
2973 | 0 | } _kwtuple = { |
2974 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
2975 | 0 | .ob_hash = -1, |
2976 | 0 | .ob_item = { &_Py_ID(src), &_Py_ID(dst), &_Py_ID(src_dir_fd), &_Py_ID(dst_dir_fd), }, |
2977 | 0 | }; |
2978 | 0 | #undef NUM_KEYWORDS |
2979 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
2980 | |
|
2981 | | #else // !Py_BUILD_CORE |
2982 | | # define KWTUPLE NULL |
2983 | | #endif // !Py_BUILD_CORE |
2984 | |
|
2985 | 0 | static const char * const _keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", NULL}; |
2986 | 0 | static _PyArg_Parser _parser = { |
2987 | 0 | .keywords = _keywords, |
2988 | 0 | .fname = "rename", |
2989 | 0 | .kwtuple = KWTUPLE, |
2990 | 0 | }; |
2991 | 0 | #undef KWTUPLE |
2992 | 0 | PyObject *argsbuf[4]; |
2993 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2; |
2994 | 0 | path_t src = PATH_T_INITIALIZE_P("rename", "src", 0, 0, 0, 0); |
2995 | 0 | path_t dst = PATH_T_INITIALIZE_P("rename", "dst", 0, 0, 0, 0); |
2996 | 0 | int src_dir_fd = DEFAULT_DIR_FD; |
2997 | 0 | int dst_dir_fd = DEFAULT_DIR_FD; |
2998 | |
|
2999 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
3000 | 0 | /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
3001 | 0 | if (!args) { |
3002 | 0 | goto exit; |
3003 | 0 | } |
3004 | 0 | if (!path_converter(args[0], &src)) { |
3005 | 0 | goto exit; |
3006 | 0 | } |
3007 | 0 | if (!path_converter(args[1], &dst)) { |
3008 | 0 | goto exit; |
3009 | 0 | } |
3010 | 0 | if (!noptargs) { |
3011 | 0 | goto skip_optional_kwonly; |
3012 | 0 | } |
3013 | 0 | if (args[2]) { |
3014 | 0 | if (!dir_fd_converter(args[2], &src_dir_fd)) { |
3015 | 0 | goto exit; |
3016 | 0 | } |
3017 | 0 | if (!--noptargs) { |
3018 | 0 | goto skip_optional_kwonly; |
3019 | 0 | } |
3020 | 0 | } |
3021 | 0 | if (!dir_fd_converter(args[3], &dst_dir_fd)) { |
3022 | 0 | goto exit; |
3023 | 0 | } |
3024 | 0 | skip_optional_kwonly: |
3025 | 0 | return_value = os_rename_impl(module, &src, &dst, src_dir_fd, dst_dir_fd); |
3026 | |
|
3027 | 0 | exit: |
3028 | | /* Cleanup for src */ |
3029 | 0 | path_cleanup(&src); |
3030 | | /* Cleanup for dst */ |
3031 | 0 | path_cleanup(&dst); |
3032 | |
|
3033 | 0 | return return_value; |
3034 | 0 | } |
3035 | | |
3036 | | PyDoc_STRVAR(os_replace__doc__, |
3037 | | "replace($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None)\n" |
3038 | | "--\n" |
3039 | | "\n" |
3040 | | "Rename a file or directory, overwriting the destination.\n" |
3041 | | "\n" |
3042 | | "If either src_dir_fd or dst_dir_fd is not None, it should be a file\n" |
3043 | | " descriptor open to a directory, and the respective path string (src or dst)\n" |
3044 | | " should be relative; the path will then be relative to that directory.\n" |
3045 | | "src_dir_fd and dst_dir_fd, may not be implemented on your platform.\n" |
3046 | | " If they are unavailable, using them will raise a NotImplementedError."); |
3047 | | |
3048 | | #define OS_REPLACE_METHODDEF \ |
3049 | | {"replace", _PyCFunction_CAST(os_replace), METH_FASTCALL|METH_KEYWORDS, os_replace__doc__}, |
3050 | | |
3051 | | static PyObject * |
3052 | | os_replace_impl(PyObject *module, path_t *src, path_t *dst, int src_dir_fd, |
3053 | | int dst_dir_fd); |
3054 | | |
3055 | | static PyObject * |
3056 | | os_replace(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
3057 | 218 | { |
3058 | 218 | PyObject *return_value = NULL; |
3059 | 218 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
3060 | | |
3061 | 218 | #define NUM_KEYWORDS 4 |
3062 | 218 | static struct { |
3063 | 218 | PyGC_Head _this_is_not_used; |
3064 | 218 | PyObject_VAR_HEAD |
3065 | 218 | Py_hash_t ob_hash; |
3066 | 218 | PyObject *ob_item[NUM_KEYWORDS]; |
3067 | 218 | } _kwtuple = { |
3068 | 218 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
3069 | 218 | .ob_hash = -1, |
3070 | 218 | .ob_item = { &_Py_ID(src), &_Py_ID(dst), &_Py_ID(src_dir_fd), &_Py_ID(dst_dir_fd), }, |
3071 | 218 | }; |
3072 | 218 | #undef NUM_KEYWORDS |
3073 | 218 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
3074 | | |
3075 | | #else // !Py_BUILD_CORE |
3076 | | # define KWTUPLE NULL |
3077 | | #endif // !Py_BUILD_CORE |
3078 | | |
3079 | 218 | static const char * const _keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", NULL}; |
3080 | 218 | static _PyArg_Parser _parser = { |
3081 | 218 | .keywords = _keywords, |
3082 | 218 | .fname = "replace", |
3083 | 218 | .kwtuple = KWTUPLE, |
3084 | 218 | }; |
3085 | 218 | #undef KWTUPLE |
3086 | 218 | PyObject *argsbuf[4]; |
3087 | 218 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2; |
3088 | 218 | path_t src = PATH_T_INITIALIZE_P("replace", "src", 0, 0, 0, 0); |
3089 | 218 | path_t dst = PATH_T_INITIALIZE_P("replace", "dst", 0, 0, 0, 0); |
3090 | 218 | int src_dir_fd = DEFAULT_DIR_FD; |
3091 | 218 | int dst_dir_fd = DEFAULT_DIR_FD; |
3092 | | |
3093 | 218 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
3094 | 218 | /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
3095 | 218 | if (!args) { |
3096 | 0 | goto exit; |
3097 | 0 | } |
3098 | 218 | if (!path_converter(args[0], &src)) { |
3099 | 0 | goto exit; |
3100 | 0 | } |
3101 | 218 | if (!path_converter(args[1], &dst)) { |
3102 | 0 | goto exit; |
3103 | 0 | } |
3104 | 218 | if (!noptargs) { |
3105 | 218 | goto skip_optional_kwonly; |
3106 | 218 | } |
3107 | 0 | if (args[2]) { |
3108 | 0 | if (!dir_fd_converter(args[2], &src_dir_fd)) { |
3109 | 0 | goto exit; |
3110 | 0 | } |
3111 | 0 | if (!--noptargs) { |
3112 | 0 | goto skip_optional_kwonly; |
3113 | 0 | } |
3114 | 0 | } |
3115 | 0 | if (!dir_fd_converter(args[3], &dst_dir_fd)) { |
3116 | 0 | goto exit; |
3117 | 0 | } |
3118 | 218 | skip_optional_kwonly: |
3119 | 218 | return_value = os_replace_impl(module, &src, &dst, src_dir_fd, dst_dir_fd); |
3120 | | |
3121 | 218 | exit: |
3122 | | /* Cleanup for src */ |
3123 | 218 | path_cleanup(&src); |
3124 | | /* Cleanup for dst */ |
3125 | 218 | path_cleanup(&dst); |
3126 | | |
3127 | 218 | return return_value; |
3128 | 218 | } |
3129 | | |
3130 | | PyDoc_STRVAR(os_rmdir__doc__, |
3131 | | "rmdir($module, /, path, *, dir_fd=None)\n" |
3132 | | "--\n" |
3133 | | "\n" |
3134 | | "Remove a directory.\n" |
3135 | | "\n" |
3136 | | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
3137 | | " and path should be relative; path will then be relative to that directory.\n" |
3138 | | "dir_fd may not be implemented on your platform.\n" |
3139 | | " If it is unavailable, using it will raise a NotImplementedError."); |
3140 | | |
3141 | | #define OS_RMDIR_METHODDEF \ |
3142 | | {"rmdir", _PyCFunction_CAST(os_rmdir), METH_FASTCALL|METH_KEYWORDS, os_rmdir__doc__}, |
3143 | | |
3144 | | static PyObject * |
3145 | | os_rmdir_impl(PyObject *module, path_t *path, int dir_fd); |
3146 | | |
3147 | | static PyObject * |
3148 | | os_rmdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
3149 | 0 | { |
3150 | 0 | PyObject *return_value = NULL; |
3151 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
3152 | |
|
3153 | 0 | #define NUM_KEYWORDS 2 |
3154 | 0 | static struct { |
3155 | 0 | PyGC_Head _this_is_not_used; |
3156 | 0 | PyObject_VAR_HEAD |
3157 | 0 | Py_hash_t ob_hash; |
3158 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
3159 | 0 | } _kwtuple = { |
3160 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
3161 | 0 | .ob_hash = -1, |
3162 | 0 | .ob_item = { &_Py_ID(path), &_Py_ID(dir_fd), }, |
3163 | 0 | }; |
3164 | 0 | #undef NUM_KEYWORDS |
3165 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
3166 | |
|
3167 | | #else // !Py_BUILD_CORE |
3168 | | # define KWTUPLE NULL |
3169 | | #endif // !Py_BUILD_CORE |
3170 | |
|
3171 | 0 | static const char * const _keywords[] = {"path", "dir_fd", NULL}; |
3172 | 0 | static _PyArg_Parser _parser = { |
3173 | 0 | .keywords = _keywords, |
3174 | 0 | .fname = "rmdir", |
3175 | 0 | .kwtuple = KWTUPLE, |
3176 | 0 | }; |
3177 | 0 | #undef KWTUPLE |
3178 | 0 | PyObject *argsbuf[2]; |
3179 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
3180 | 0 | path_t path = PATH_T_INITIALIZE_P("rmdir", "path", 0, 0, 0, 0); |
3181 | 0 | int dir_fd = DEFAULT_DIR_FD; |
3182 | |
|
3183 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
3184 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
3185 | 0 | if (!args) { |
3186 | 0 | goto exit; |
3187 | 0 | } |
3188 | 0 | if (!path_converter(args[0], &path)) { |
3189 | 0 | goto exit; |
3190 | 0 | } |
3191 | 0 | if (!noptargs) { |
3192 | 0 | goto skip_optional_kwonly; |
3193 | 0 | } |
3194 | 0 | if (!UNLINKAT_DIR_FD_CONVERTER(args[1], &dir_fd)) { |
3195 | 0 | goto exit; |
3196 | 0 | } |
3197 | 0 | skip_optional_kwonly: |
3198 | 0 | return_value = os_rmdir_impl(module, &path, dir_fd); |
3199 | |
|
3200 | 0 | exit: |
3201 | | /* Cleanup for path */ |
3202 | 0 | path_cleanup(&path); |
3203 | |
|
3204 | 0 | return return_value; |
3205 | 0 | } |
3206 | | |
3207 | | #if defined(HAVE_SYSTEM) && defined(MS_WINDOWS) |
3208 | | |
3209 | | PyDoc_STRVAR(os_system__doc__, |
3210 | | "system($module, /, command)\n" |
3211 | | "--\n" |
3212 | | "\n" |
3213 | | "Execute the command in a subshell."); |
3214 | | |
3215 | | #define OS_SYSTEM_METHODDEF \ |
3216 | | {"system", _PyCFunction_CAST(os_system), METH_FASTCALL|METH_KEYWORDS, os_system__doc__}, |
3217 | | |
3218 | | static long |
3219 | | os_system_impl(PyObject *module, const wchar_t *command); |
3220 | | |
3221 | | static PyObject * |
3222 | | os_system(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
3223 | | { |
3224 | | PyObject *return_value = NULL; |
3225 | | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
3226 | | |
3227 | | #define NUM_KEYWORDS 1 |
3228 | | static struct { |
3229 | | PyGC_Head _this_is_not_used; |
3230 | | PyObject_VAR_HEAD |
3231 | | Py_hash_t ob_hash; |
3232 | | PyObject *ob_item[NUM_KEYWORDS]; |
3233 | | } _kwtuple = { |
3234 | | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
3235 | | .ob_hash = -1, |
3236 | | .ob_item = { &_Py_ID(command), }, |
3237 | | }; |
3238 | | #undef NUM_KEYWORDS |
3239 | | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
3240 | | |
3241 | | #else // !Py_BUILD_CORE |
3242 | | # define KWTUPLE NULL |
3243 | | #endif // !Py_BUILD_CORE |
3244 | | |
3245 | | static const char * const _keywords[] = {"command", NULL}; |
3246 | | static _PyArg_Parser _parser = { |
3247 | | .keywords = _keywords, |
3248 | | .fname = "system", |
3249 | | .kwtuple = KWTUPLE, |
3250 | | }; |
3251 | | #undef KWTUPLE |
3252 | | PyObject *argsbuf[1]; |
3253 | | const wchar_t *command = NULL; |
3254 | | long _return_value; |
3255 | | |
3256 | | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
3257 | | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
3258 | | if (!args) { |
3259 | | goto exit; |
3260 | | } |
3261 | | if (!PyUnicode_Check(args[0])) { |
3262 | | _PyArg_BadArgument("system", "argument 'command'", "str", args[0]); |
3263 | | goto exit; |
3264 | | } |
3265 | | command = PyUnicode_AsWideCharString(args[0], NULL); |
3266 | | if (command == NULL) { |
3267 | | goto exit; |
3268 | | } |
3269 | | _return_value = os_system_impl(module, command); |
3270 | | if ((_return_value == -1) && PyErr_Occurred()) { |
3271 | | goto exit; |
3272 | | } |
3273 | | return_value = PyLong_FromLong(_return_value); |
3274 | | |
3275 | | exit: |
3276 | | /* Cleanup for command */ |
3277 | | PyMem_Free((void *)command); |
3278 | | |
3279 | | return return_value; |
3280 | | } |
3281 | | |
3282 | | #endif /* defined(HAVE_SYSTEM) && defined(MS_WINDOWS) */ |
3283 | | |
3284 | | #if defined(HAVE_SYSTEM) && !defined(MS_WINDOWS) |
3285 | | |
3286 | | PyDoc_STRVAR(os_system__doc__, |
3287 | | "system($module, /, command)\n" |
3288 | | "--\n" |
3289 | | "\n" |
3290 | | "Execute the command in a subshell."); |
3291 | | |
3292 | | #define OS_SYSTEM_METHODDEF \ |
3293 | | {"system", _PyCFunction_CAST(os_system), METH_FASTCALL|METH_KEYWORDS, os_system__doc__}, |
3294 | | |
3295 | | static long |
3296 | | os_system_impl(PyObject *module, PyObject *command); |
3297 | | |
3298 | | static PyObject * |
3299 | | os_system(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
3300 | 0 | { |
3301 | 0 | PyObject *return_value = NULL; |
3302 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
3303 | |
|
3304 | 0 | #define NUM_KEYWORDS 1 |
3305 | 0 | static struct { |
3306 | 0 | PyGC_Head _this_is_not_used; |
3307 | 0 | PyObject_VAR_HEAD |
3308 | 0 | Py_hash_t ob_hash; |
3309 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
3310 | 0 | } _kwtuple = { |
3311 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
3312 | 0 | .ob_hash = -1, |
3313 | 0 | .ob_item = { &_Py_ID(command), }, |
3314 | 0 | }; |
3315 | 0 | #undef NUM_KEYWORDS |
3316 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
3317 | |
|
3318 | | #else // !Py_BUILD_CORE |
3319 | | # define KWTUPLE NULL |
3320 | | #endif // !Py_BUILD_CORE |
3321 | |
|
3322 | 0 | static const char * const _keywords[] = {"command", NULL}; |
3323 | 0 | static _PyArg_Parser _parser = { |
3324 | 0 | .keywords = _keywords, |
3325 | 0 | .fname = "system", |
3326 | 0 | .kwtuple = KWTUPLE, |
3327 | 0 | }; |
3328 | 0 | #undef KWTUPLE |
3329 | 0 | PyObject *argsbuf[1]; |
3330 | 0 | PyObject *command = NULL; |
3331 | 0 | long _return_value; |
3332 | |
|
3333 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
3334 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
3335 | 0 | if (!args) { |
3336 | 0 | goto exit; |
3337 | 0 | } |
3338 | 0 | if (!PyUnicode_FSConverter(args[0], &command)) { |
3339 | 0 | goto exit; |
3340 | 0 | } |
3341 | 0 | _return_value = os_system_impl(module, command); |
3342 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
3343 | 0 | goto exit; |
3344 | 0 | } |
3345 | 0 | return_value = PyLong_FromLong(_return_value); |
3346 | |
|
3347 | 0 | exit: |
3348 | | /* Cleanup for command */ |
3349 | 0 | Py_XDECREF(command); |
3350 | |
|
3351 | 0 | return return_value; |
3352 | 0 | } |
3353 | | |
3354 | | #endif /* defined(HAVE_SYSTEM) && !defined(MS_WINDOWS) */ |
3355 | | |
3356 | | #if defined(HAVE_UMASK) |
3357 | | |
3358 | | PyDoc_STRVAR(os_umask__doc__, |
3359 | | "umask($module, mask, /)\n" |
3360 | | "--\n" |
3361 | | "\n" |
3362 | | "Set the current numeric umask and return the previous umask."); |
3363 | | |
3364 | | #define OS_UMASK_METHODDEF \ |
3365 | | {"umask", (PyCFunction)os_umask, METH_O, os_umask__doc__}, |
3366 | | |
3367 | | static PyObject * |
3368 | | os_umask_impl(PyObject *module, int mask); |
3369 | | |
3370 | | static PyObject * |
3371 | | os_umask(PyObject *module, PyObject *arg) |
3372 | 0 | { |
3373 | 0 | PyObject *return_value = NULL; |
3374 | 0 | int mask; |
3375 | |
|
3376 | 0 | mask = PyLong_AsInt(arg); |
3377 | 0 | if (mask == -1 && PyErr_Occurred()) { |
3378 | 0 | goto exit; |
3379 | 0 | } |
3380 | 0 | return_value = os_umask_impl(module, mask); |
3381 | |
|
3382 | 0 | exit: |
3383 | 0 | return return_value; |
3384 | 0 | } |
3385 | | |
3386 | | #endif /* defined(HAVE_UMASK) */ |
3387 | | |
3388 | | PyDoc_STRVAR(os_unlink__doc__, |
3389 | | "unlink($module, /, path, *, dir_fd=None)\n" |
3390 | | "--\n" |
3391 | | "\n" |
3392 | | "Remove a file (same as remove()).\n" |
3393 | | "\n" |
3394 | | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
3395 | | " and path should be relative; path will then be relative to that directory.\n" |
3396 | | "dir_fd may not be implemented on your platform.\n" |
3397 | | " If it is unavailable, using it will raise a NotImplementedError."); |
3398 | | |
3399 | | #define OS_UNLINK_METHODDEF \ |
3400 | | {"unlink", _PyCFunction_CAST(os_unlink), METH_FASTCALL|METH_KEYWORDS, os_unlink__doc__}, |
3401 | | |
3402 | | static PyObject * |
3403 | | os_unlink_impl(PyObject *module, path_t *path, int dir_fd); |
3404 | | |
3405 | | static PyObject * |
3406 | | os_unlink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
3407 | 0 | { |
3408 | 0 | PyObject *return_value = NULL; |
3409 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
3410 | |
|
3411 | 0 | #define NUM_KEYWORDS 2 |
3412 | 0 | static struct { |
3413 | 0 | PyGC_Head _this_is_not_used; |
3414 | 0 | PyObject_VAR_HEAD |
3415 | 0 | Py_hash_t ob_hash; |
3416 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
3417 | 0 | } _kwtuple = { |
3418 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
3419 | 0 | .ob_hash = -1, |
3420 | 0 | .ob_item = { &_Py_ID(path), &_Py_ID(dir_fd), }, |
3421 | 0 | }; |
3422 | 0 | #undef NUM_KEYWORDS |
3423 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
3424 | |
|
3425 | | #else // !Py_BUILD_CORE |
3426 | | # define KWTUPLE NULL |
3427 | | #endif // !Py_BUILD_CORE |
3428 | |
|
3429 | 0 | static const char * const _keywords[] = {"path", "dir_fd", NULL}; |
3430 | 0 | static _PyArg_Parser _parser = { |
3431 | 0 | .keywords = _keywords, |
3432 | 0 | .fname = "unlink", |
3433 | 0 | .kwtuple = KWTUPLE, |
3434 | 0 | }; |
3435 | 0 | #undef KWTUPLE |
3436 | 0 | PyObject *argsbuf[2]; |
3437 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
3438 | 0 | path_t path = PATH_T_INITIALIZE_P("unlink", "path", 0, 0, 0, 0); |
3439 | 0 | int dir_fd = DEFAULT_DIR_FD; |
3440 | |
|
3441 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
3442 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
3443 | 0 | if (!args) { |
3444 | 0 | goto exit; |
3445 | 0 | } |
3446 | 0 | if (!path_converter(args[0], &path)) { |
3447 | 0 | goto exit; |
3448 | 0 | } |
3449 | 0 | if (!noptargs) { |
3450 | 0 | goto skip_optional_kwonly; |
3451 | 0 | } |
3452 | 0 | if (!UNLINKAT_DIR_FD_CONVERTER(args[1], &dir_fd)) { |
3453 | 0 | goto exit; |
3454 | 0 | } |
3455 | 0 | skip_optional_kwonly: |
3456 | 0 | return_value = os_unlink_impl(module, &path, dir_fd); |
3457 | |
|
3458 | 0 | exit: |
3459 | | /* Cleanup for path */ |
3460 | 0 | path_cleanup(&path); |
3461 | |
|
3462 | 0 | return return_value; |
3463 | 0 | } |
3464 | | |
3465 | | PyDoc_STRVAR(os_remove__doc__, |
3466 | | "remove($module, /, path, *, dir_fd=None)\n" |
3467 | | "--\n" |
3468 | | "\n" |
3469 | | "Remove a file (same as unlink()).\n" |
3470 | | "\n" |
3471 | | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
3472 | | " and path should be relative; path will then be relative to that directory.\n" |
3473 | | "dir_fd may not be implemented on your platform.\n" |
3474 | | " If it is unavailable, using it will raise a NotImplementedError."); |
3475 | | |
3476 | | #define OS_REMOVE_METHODDEF \ |
3477 | | {"remove", _PyCFunction_CAST(os_remove), METH_FASTCALL|METH_KEYWORDS, os_remove__doc__}, |
3478 | | |
3479 | | static PyObject * |
3480 | | os_remove_impl(PyObject *module, path_t *path, int dir_fd); |
3481 | | |
3482 | | static PyObject * |
3483 | | os_remove(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
3484 | 0 | { |
3485 | 0 | PyObject *return_value = NULL; |
3486 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
3487 | |
|
3488 | 0 | #define NUM_KEYWORDS 2 |
3489 | 0 | static struct { |
3490 | 0 | PyGC_Head _this_is_not_used; |
3491 | 0 | PyObject_VAR_HEAD |
3492 | 0 | Py_hash_t ob_hash; |
3493 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
3494 | 0 | } _kwtuple = { |
3495 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
3496 | 0 | .ob_hash = -1, |
3497 | 0 | .ob_item = { &_Py_ID(path), &_Py_ID(dir_fd), }, |
3498 | 0 | }; |
3499 | 0 | #undef NUM_KEYWORDS |
3500 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
3501 | |
|
3502 | | #else // !Py_BUILD_CORE |
3503 | | # define KWTUPLE NULL |
3504 | | #endif // !Py_BUILD_CORE |
3505 | |
|
3506 | 0 | static const char * const _keywords[] = {"path", "dir_fd", NULL}; |
3507 | 0 | static _PyArg_Parser _parser = { |
3508 | 0 | .keywords = _keywords, |
3509 | 0 | .fname = "remove", |
3510 | 0 | .kwtuple = KWTUPLE, |
3511 | 0 | }; |
3512 | 0 | #undef KWTUPLE |
3513 | 0 | PyObject *argsbuf[2]; |
3514 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
3515 | 0 | path_t path = PATH_T_INITIALIZE_P("remove", "path", 0, 0, 0, 0); |
3516 | 0 | int dir_fd = DEFAULT_DIR_FD; |
3517 | |
|
3518 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
3519 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
3520 | 0 | if (!args) { |
3521 | 0 | goto exit; |
3522 | 0 | } |
3523 | 0 | if (!path_converter(args[0], &path)) { |
3524 | 0 | goto exit; |
3525 | 0 | } |
3526 | 0 | if (!noptargs) { |
3527 | 0 | goto skip_optional_kwonly; |
3528 | 0 | } |
3529 | 0 | if (!UNLINKAT_DIR_FD_CONVERTER(args[1], &dir_fd)) { |
3530 | 0 | goto exit; |
3531 | 0 | } |
3532 | 0 | skip_optional_kwonly: |
3533 | 0 | return_value = os_remove_impl(module, &path, dir_fd); |
3534 | |
|
3535 | 0 | exit: |
3536 | | /* Cleanup for path */ |
3537 | 0 | path_cleanup(&path); |
3538 | |
|
3539 | 0 | return return_value; |
3540 | 0 | } |
3541 | | |
3542 | | #if defined(HAVE_UNAME) |
3543 | | |
3544 | | PyDoc_STRVAR(os_uname__doc__, |
3545 | | "uname($module, /)\n" |
3546 | | "--\n" |
3547 | | "\n" |
3548 | | "Return an object identifying the current operating system.\n" |
3549 | | "\n" |
3550 | | "The object behaves like a named tuple with the following fields:\n" |
3551 | | " (sysname, nodename, release, version, machine)"); |
3552 | | |
3553 | | #define OS_UNAME_METHODDEF \ |
3554 | | {"uname", (PyCFunction)os_uname, METH_NOARGS, os_uname__doc__}, |
3555 | | |
3556 | | static PyObject * |
3557 | | os_uname_impl(PyObject *module); |
3558 | | |
3559 | | static PyObject * |
3560 | | os_uname(PyObject *module, PyObject *Py_UNUSED(ignored)) |
3561 | 0 | { |
3562 | 0 | return os_uname_impl(module); |
3563 | 0 | } |
3564 | | |
3565 | | #endif /* defined(HAVE_UNAME) */ |
3566 | | |
3567 | | PyDoc_STRVAR(os_utime__doc__, |
3568 | | "utime($module, /, path, times=None, *, ns=<unrepresentable>,\n" |
3569 | | " dir_fd=None, follow_symlinks=True)\n" |
3570 | | "--\n" |
3571 | | "\n" |
3572 | | "Set the access and modified time of path.\n" |
3573 | | "\n" |
3574 | | "path may always be specified as a string.\n" |
3575 | | "On some platforms, path may also be specified as an open file descriptor.\n" |
3576 | | " If this functionality is unavailable, using it raises an exception.\n" |
3577 | | "\n" |
3578 | | "If times is not None, it must be a tuple (atime, mtime);\n" |
3579 | | " atime and mtime should be expressed as float seconds since the epoch.\n" |
3580 | | "If ns is specified, it must be a tuple (atime_ns, mtime_ns);\n" |
3581 | | " atime_ns and mtime_ns should be expressed as integer nanoseconds\n" |
3582 | | " since the epoch.\n" |
3583 | | "If times is None and ns is unspecified, utime uses the current time.\n" |
3584 | | "Specifying tuples for both times and ns is an error.\n" |
3585 | | "\n" |
3586 | | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
3587 | | " and path should be relative; path will then be relative to that directory.\n" |
3588 | | "If follow_symlinks is False, and the last element of the path is a symbolic\n" |
3589 | | " link, utime will modify the symbolic link itself instead of the file the\n" |
3590 | | " link points to.\n" |
3591 | | "It is an error to use dir_fd or follow_symlinks when specifying path\n" |
3592 | | " as an open file descriptor.\n" |
3593 | | "dir_fd and follow_symlinks may not be available on your platform.\n" |
3594 | | " If they are unavailable, using them will raise a NotImplementedError."); |
3595 | | |
3596 | | #define OS_UTIME_METHODDEF \ |
3597 | | {"utime", _PyCFunction_CAST(os_utime), METH_FASTCALL|METH_KEYWORDS, os_utime__doc__}, |
3598 | | |
3599 | | static PyObject * |
3600 | | os_utime_impl(PyObject *module, path_t *path, PyObject *times, PyObject *ns, |
3601 | | int dir_fd, int follow_symlinks); |
3602 | | |
3603 | | static PyObject * |
3604 | | os_utime(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
3605 | 0 | { |
3606 | 0 | PyObject *return_value = NULL; |
3607 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
3608 | |
|
3609 | 0 | #define NUM_KEYWORDS 5 |
3610 | 0 | static struct { |
3611 | 0 | PyGC_Head _this_is_not_used; |
3612 | 0 | PyObject_VAR_HEAD |
3613 | 0 | Py_hash_t ob_hash; |
3614 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
3615 | 0 | } _kwtuple = { |
3616 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
3617 | 0 | .ob_hash = -1, |
3618 | 0 | .ob_item = { &_Py_ID(path), &_Py_ID(times), &_Py_ID(ns), &_Py_ID(dir_fd), &_Py_ID(follow_symlinks), }, |
3619 | 0 | }; |
3620 | 0 | #undef NUM_KEYWORDS |
3621 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
3622 | |
|
3623 | | #else // !Py_BUILD_CORE |
3624 | | # define KWTUPLE NULL |
3625 | | #endif // !Py_BUILD_CORE |
3626 | |
|
3627 | 0 | static const char * const _keywords[] = {"path", "times", "ns", "dir_fd", "follow_symlinks", NULL}; |
3628 | 0 | static _PyArg_Parser _parser = { |
3629 | 0 | .keywords = _keywords, |
3630 | 0 | .fname = "utime", |
3631 | 0 | .kwtuple = KWTUPLE, |
3632 | 0 | }; |
3633 | 0 | #undef KWTUPLE |
3634 | 0 | PyObject *argsbuf[5]; |
3635 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
3636 | 0 | path_t path = PATH_T_INITIALIZE_P("utime", "path", 0, 0, 0, PATH_UTIME_HAVE_FD); |
3637 | 0 | PyObject *times = Py_None; |
3638 | 0 | PyObject *ns = NULL; |
3639 | 0 | int dir_fd = DEFAULT_DIR_FD; |
3640 | 0 | int follow_symlinks = 1; |
3641 | |
|
3642 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
3643 | 0 | /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
3644 | 0 | if (!args) { |
3645 | 0 | goto exit; |
3646 | 0 | } |
3647 | 0 | if (!path_converter(args[0], &path)) { |
3648 | 0 | goto exit; |
3649 | 0 | } |
3650 | 0 | if (!noptargs) { |
3651 | 0 | goto skip_optional_pos; |
3652 | 0 | } |
3653 | 0 | if (args[1]) { |
3654 | 0 | times = args[1]; |
3655 | 0 | if (!--noptargs) { |
3656 | 0 | goto skip_optional_pos; |
3657 | 0 | } |
3658 | 0 | } |
3659 | 0 | skip_optional_pos: |
3660 | 0 | if (!noptargs) { |
3661 | 0 | goto skip_optional_kwonly; |
3662 | 0 | } |
3663 | 0 | if (args[2]) { |
3664 | 0 | ns = args[2]; |
3665 | 0 | if (!--noptargs) { |
3666 | 0 | goto skip_optional_kwonly; |
3667 | 0 | } |
3668 | 0 | } |
3669 | 0 | if (args[3]) { |
3670 | 0 | if (!FUTIMENSAT_DIR_FD_CONVERTER(args[3], &dir_fd)) { |
3671 | 0 | goto exit; |
3672 | 0 | } |
3673 | 0 | if (!--noptargs) { |
3674 | 0 | goto skip_optional_kwonly; |
3675 | 0 | } |
3676 | 0 | } |
3677 | 0 | follow_symlinks = PyObject_IsTrue(args[4]); |
3678 | 0 | if (follow_symlinks < 0) { |
3679 | 0 | goto exit; |
3680 | 0 | } |
3681 | 0 | skip_optional_kwonly: |
3682 | 0 | return_value = os_utime_impl(module, &path, times, ns, dir_fd, follow_symlinks); |
3683 | |
|
3684 | 0 | exit: |
3685 | | /* Cleanup for path */ |
3686 | 0 | path_cleanup(&path); |
3687 | |
|
3688 | 0 | return return_value; |
3689 | 0 | } |
3690 | | |
3691 | | PyDoc_STRVAR(os__exit__doc__, |
3692 | | "_exit($module, /, status)\n" |
3693 | | "--\n" |
3694 | | "\n" |
3695 | | "Exit to the system with specified status, without normal exit processing."); |
3696 | | |
3697 | | #define OS__EXIT_METHODDEF \ |
3698 | | {"_exit", _PyCFunction_CAST(os__exit), METH_FASTCALL|METH_KEYWORDS, os__exit__doc__}, |
3699 | | |
3700 | | static PyObject * |
3701 | | os__exit_impl(PyObject *module, int status); |
3702 | | |
3703 | | static PyObject * |
3704 | | os__exit(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
3705 | 0 | { |
3706 | 0 | PyObject *return_value = NULL; |
3707 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
3708 | |
|
3709 | 0 | #define NUM_KEYWORDS 1 |
3710 | 0 | static struct { |
3711 | 0 | PyGC_Head _this_is_not_used; |
3712 | 0 | PyObject_VAR_HEAD |
3713 | 0 | Py_hash_t ob_hash; |
3714 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
3715 | 0 | } _kwtuple = { |
3716 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
3717 | 0 | .ob_hash = -1, |
3718 | 0 | .ob_item = { &_Py_ID(status), }, |
3719 | 0 | }; |
3720 | 0 | #undef NUM_KEYWORDS |
3721 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
3722 | |
|
3723 | | #else // !Py_BUILD_CORE |
3724 | | # define KWTUPLE NULL |
3725 | | #endif // !Py_BUILD_CORE |
3726 | |
|
3727 | 0 | static const char * const _keywords[] = {"status", NULL}; |
3728 | 0 | static _PyArg_Parser _parser = { |
3729 | 0 | .keywords = _keywords, |
3730 | 0 | .fname = "_exit", |
3731 | 0 | .kwtuple = KWTUPLE, |
3732 | 0 | }; |
3733 | 0 | #undef KWTUPLE |
3734 | 0 | PyObject *argsbuf[1]; |
3735 | 0 | int status; |
3736 | |
|
3737 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
3738 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
3739 | 0 | if (!args) { |
3740 | 0 | goto exit; |
3741 | 0 | } |
3742 | 0 | status = PyLong_AsInt(args[0]); |
3743 | 0 | if (status == -1 && PyErr_Occurred()) { |
3744 | 0 | goto exit; |
3745 | 0 | } |
3746 | 0 | return_value = os__exit_impl(module, status); |
3747 | |
|
3748 | 0 | exit: |
3749 | 0 | return return_value; |
3750 | 0 | } |
3751 | | |
3752 | | #if defined(HAVE_EXECV) |
3753 | | |
3754 | | PyDoc_STRVAR(os_execv__doc__, |
3755 | | "execv($module, path, argv, /)\n" |
3756 | | "--\n" |
3757 | | "\n" |
3758 | | "Execute an executable path with arguments, replacing current process.\n" |
3759 | | "\n" |
3760 | | " path\n" |
3761 | | " Path of executable file.\n" |
3762 | | " argv\n" |
3763 | | " Tuple or list of strings."); |
3764 | | |
3765 | | #define OS_EXECV_METHODDEF \ |
3766 | | {"execv", _PyCFunction_CAST(os_execv), METH_FASTCALL, os_execv__doc__}, |
3767 | | |
3768 | | static PyObject * |
3769 | | os_execv_impl(PyObject *module, path_t *path, PyObject *argv); |
3770 | | |
3771 | | static PyObject * |
3772 | | os_execv(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
3773 | 0 | { |
3774 | 0 | PyObject *return_value = NULL; |
3775 | 0 | path_t path = PATH_T_INITIALIZE_P("execv", "path", 0, 0, 0, 0); |
3776 | 0 | PyObject *argv; |
3777 | |
|
3778 | 0 | if (!_PyArg_CheckPositional("execv", nargs, 2, 2)) { |
3779 | 0 | goto exit; |
3780 | 0 | } |
3781 | 0 | if (!path_converter(args[0], &path)) { |
3782 | 0 | goto exit; |
3783 | 0 | } |
3784 | 0 | argv = args[1]; |
3785 | 0 | return_value = os_execv_impl(module, &path, argv); |
3786 | |
|
3787 | 0 | exit: |
3788 | | /* Cleanup for path */ |
3789 | 0 | path_cleanup(&path); |
3790 | |
|
3791 | 0 | return return_value; |
3792 | 0 | } |
3793 | | |
3794 | | #endif /* defined(HAVE_EXECV) */ |
3795 | | |
3796 | | #if defined(HAVE_EXECV) |
3797 | | |
3798 | | PyDoc_STRVAR(os_execve__doc__, |
3799 | | "execve($module, /, path, argv, env)\n" |
3800 | | "--\n" |
3801 | | "\n" |
3802 | | "Execute an executable path with arguments, replacing current process.\n" |
3803 | | "\n" |
3804 | | " path\n" |
3805 | | " Path of executable file.\n" |
3806 | | " argv\n" |
3807 | | " Tuple or list of strings.\n" |
3808 | | " env\n" |
3809 | | " Dictionary of strings mapping to strings."); |
3810 | | |
3811 | | #define OS_EXECVE_METHODDEF \ |
3812 | | {"execve", _PyCFunction_CAST(os_execve), METH_FASTCALL|METH_KEYWORDS, os_execve__doc__}, |
3813 | | |
3814 | | static PyObject * |
3815 | | os_execve_impl(PyObject *module, path_t *path, PyObject *argv, PyObject *env); |
3816 | | |
3817 | | static PyObject * |
3818 | | os_execve(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
3819 | 0 | { |
3820 | 0 | PyObject *return_value = NULL; |
3821 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
3822 | |
|
3823 | 0 | #define NUM_KEYWORDS 3 |
3824 | 0 | static struct { |
3825 | 0 | PyGC_Head _this_is_not_used; |
3826 | 0 | PyObject_VAR_HEAD |
3827 | 0 | Py_hash_t ob_hash; |
3828 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
3829 | 0 | } _kwtuple = { |
3830 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
3831 | 0 | .ob_hash = -1, |
3832 | 0 | .ob_item = { &_Py_ID(path), &_Py_ID(argv), &_Py_ID(env), }, |
3833 | 0 | }; |
3834 | 0 | #undef NUM_KEYWORDS |
3835 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
3836 | |
|
3837 | | #else // !Py_BUILD_CORE |
3838 | | # define KWTUPLE NULL |
3839 | | #endif // !Py_BUILD_CORE |
3840 | |
|
3841 | 0 | static const char * const _keywords[] = {"path", "argv", "env", NULL}; |
3842 | 0 | static _PyArg_Parser _parser = { |
3843 | 0 | .keywords = _keywords, |
3844 | 0 | .fname = "execve", |
3845 | 0 | .kwtuple = KWTUPLE, |
3846 | 0 | }; |
3847 | 0 | #undef KWTUPLE |
3848 | 0 | PyObject *argsbuf[3]; |
3849 | 0 | path_t path = PATH_T_INITIALIZE_P("execve", "path", 0, 0, 0, PATH_HAVE_FEXECVE); |
3850 | 0 | PyObject *argv; |
3851 | 0 | PyObject *env; |
3852 | |
|
3853 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
3854 | 0 | /*minpos*/ 3, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
3855 | 0 | if (!args) { |
3856 | 0 | goto exit; |
3857 | 0 | } |
3858 | 0 | if (!path_converter(args[0], &path)) { |
3859 | 0 | goto exit; |
3860 | 0 | } |
3861 | 0 | argv = args[1]; |
3862 | 0 | env = args[2]; |
3863 | 0 | return_value = os_execve_impl(module, &path, argv, env); |
3864 | |
|
3865 | 0 | exit: |
3866 | | /* Cleanup for path */ |
3867 | 0 | path_cleanup(&path); |
3868 | |
|
3869 | 0 | return return_value; |
3870 | 0 | } |
3871 | | |
3872 | | #endif /* defined(HAVE_EXECV) */ |
3873 | | |
3874 | | #if defined(HAVE_POSIX_SPAWN) |
3875 | | |
3876 | | PyDoc_STRVAR(os_posix_spawn__doc__, |
3877 | | "posix_spawn($module, path, argv, env, /, *, file_actions=(),\n" |
3878 | | " setpgroup=<unrepresentable>, resetids=False, setsid=False,\n" |
3879 | | " setsigmask=(), setsigdef=(), scheduler=<unrepresentable>)\n" |
3880 | | "--\n" |
3881 | | "\n" |
3882 | | "Execute the program specified by path in a new process.\n" |
3883 | | "\n" |
3884 | | " path\n" |
3885 | | " Path of executable file.\n" |
3886 | | " argv\n" |
3887 | | " Tuple or list of strings.\n" |
3888 | | " env\n" |
3889 | | " Dictionary of strings mapping to strings.\n" |
3890 | | " file_actions\n" |
3891 | | " A sequence of file action tuples.\n" |
3892 | | " setpgroup\n" |
3893 | | " The pgroup to use with the POSIX_SPAWN_SETPGROUP flag.\n" |
3894 | | " resetids\n" |
3895 | | " If the value is `true` the POSIX_SPAWN_RESETIDS will be activated.\n" |
3896 | | " setsid\n" |
3897 | | " If the value is `true` the POSIX_SPAWN_SETSID or POSIX_SPAWN_SETSID_NP will be activated.\n" |
3898 | | " setsigmask\n" |
3899 | | " The sigmask to use with the POSIX_SPAWN_SETSIGMASK flag.\n" |
3900 | | " setsigdef\n" |
3901 | | " The sigmask to use with the POSIX_SPAWN_SETSIGDEF flag.\n" |
3902 | | " scheduler\n" |
3903 | | " A tuple with the scheduler policy (optional) and parameters."); |
3904 | | |
3905 | | #define OS_POSIX_SPAWN_METHODDEF \ |
3906 | | {"posix_spawn", _PyCFunction_CAST(os_posix_spawn), METH_FASTCALL|METH_KEYWORDS, os_posix_spawn__doc__}, |
3907 | | |
3908 | | static PyObject * |
3909 | | os_posix_spawn_impl(PyObject *module, path_t *path, PyObject *argv, |
3910 | | PyObject *env, PyObject *file_actions, |
3911 | | PyObject *setpgroup, int resetids, int setsid, |
3912 | | PyObject *setsigmask, PyObject *setsigdef, |
3913 | | PyObject *scheduler); |
3914 | | |
3915 | | static PyObject * |
3916 | | os_posix_spawn(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
3917 | 0 | { |
3918 | 0 | PyObject *return_value = NULL; |
3919 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
3920 | |
|
3921 | 0 | #define NUM_KEYWORDS 7 |
3922 | 0 | static struct { |
3923 | 0 | PyGC_Head _this_is_not_used; |
3924 | 0 | PyObject_VAR_HEAD |
3925 | 0 | Py_hash_t ob_hash; |
3926 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
3927 | 0 | } _kwtuple = { |
3928 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
3929 | 0 | .ob_hash = -1, |
3930 | 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), }, |
3931 | 0 | }; |
3932 | 0 | #undef NUM_KEYWORDS |
3933 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
3934 | |
|
3935 | | #else // !Py_BUILD_CORE |
3936 | | # define KWTUPLE NULL |
3937 | | #endif // !Py_BUILD_CORE |
3938 | |
|
3939 | 0 | static const char * const _keywords[] = {"", "", "", "file_actions", "setpgroup", "resetids", "setsid", "setsigmask", "setsigdef", "scheduler", NULL}; |
3940 | 0 | static _PyArg_Parser _parser = { |
3941 | 0 | .keywords = _keywords, |
3942 | 0 | .fname = "posix_spawn", |
3943 | 0 | .kwtuple = KWTUPLE, |
3944 | 0 | }; |
3945 | 0 | #undef KWTUPLE |
3946 | 0 | PyObject *argsbuf[10]; |
3947 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3; |
3948 | 0 | path_t path = PATH_T_INITIALIZE_P("posix_spawn", "path", 0, 0, 0, 0); |
3949 | 0 | PyObject *argv; |
3950 | 0 | PyObject *env; |
3951 | 0 | PyObject *file_actions = NULL; |
3952 | 0 | PyObject *setpgroup = NULL; |
3953 | 0 | int resetids = 0; |
3954 | 0 | int setsid = 0; |
3955 | 0 | PyObject *setsigmask = NULL; |
3956 | 0 | PyObject *setsigdef = NULL; |
3957 | 0 | PyObject *scheduler = NULL; |
3958 | |
|
3959 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
3960 | 0 | /*minpos*/ 3, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
3961 | 0 | if (!args) { |
3962 | 0 | goto exit; |
3963 | 0 | } |
3964 | 0 | if (!path_converter(args[0], &path)) { |
3965 | 0 | goto exit; |
3966 | 0 | } |
3967 | 0 | argv = args[1]; |
3968 | 0 | env = args[2]; |
3969 | 0 | if (!noptargs) { |
3970 | 0 | goto skip_optional_kwonly; |
3971 | 0 | } |
3972 | 0 | if (args[3]) { |
3973 | 0 | file_actions = args[3]; |
3974 | 0 | if (!--noptargs) { |
3975 | 0 | goto skip_optional_kwonly; |
3976 | 0 | } |
3977 | 0 | } |
3978 | 0 | if (args[4]) { |
3979 | 0 | setpgroup = args[4]; |
3980 | 0 | if (!--noptargs) { |
3981 | 0 | goto skip_optional_kwonly; |
3982 | 0 | } |
3983 | 0 | } |
3984 | 0 | if (args[5]) { |
3985 | 0 | resetids = PyObject_IsTrue(args[5]); |
3986 | 0 | if (resetids < 0) { |
3987 | 0 | goto exit; |
3988 | 0 | } |
3989 | 0 | if (!--noptargs) { |
3990 | 0 | goto skip_optional_kwonly; |
3991 | 0 | } |
3992 | 0 | } |
3993 | 0 | if (args[6]) { |
3994 | 0 | setsid = PyObject_IsTrue(args[6]); |
3995 | 0 | if (setsid < 0) { |
3996 | 0 | goto exit; |
3997 | 0 | } |
3998 | 0 | if (!--noptargs) { |
3999 | 0 | goto skip_optional_kwonly; |
4000 | 0 | } |
4001 | 0 | } |
4002 | 0 | if (args[7]) { |
4003 | 0 | setsigmask = args[7]; |
4004 | 0 | if (!--noptargs) { |
4005 | 0 | goto skip_optional_kwonly; |
4006 | 0 | } |
4007 | 0 | } |
4008 | 0 | if (args[8]) { |
4009 | 0 | setsigdef = args[8]; |
4010 | 0 | if (!--noptargs) { |
4011 | 0 | goto skip_optional_kwonly; |
4012 | 0 | } |
4013 | 0 | } |
4014 | 0 | scheduler = args[9]; |
4015 | 0 | skip_optional_kwonly: |
4016 | 0 | return_value = os_posix_spawn_impl(module, &path, argv, env, file_actions, setpgroup, resetids, setsid, setsigmask, setsigdef, scheduler); |
4017 | |
|
4018 | 0 | exit: |
4019 | | /* Cleanup for path */ |
4020 | 0 | path_cleanup(&path); |
4021 | |
|
4022 | 0 | return return_value; |
4023 | 0 | } |
4024 | | |
4025 | | #endif /* defined(HAVE_POSIX_SPAWN) */ |
4026 | | |
4027 | | #if defined(HAVE_POSIX_SPAWNP) |
4028 | | |
4029 | | PyDoc_STRVAR(os_posix_spawnp__doc__, |
4030 | | "posix_spawnp($module, path, argv, env, /, *, file_actions=(),\n" |
4031 | | " setpgroup=<unrepresentable>, resetids=False, setsid=False,\n" |
4032 | | " setsigmask=(), setsigdef=(), scheduler=<unrepresentable>)\n" |
4033 | | "--\n" |
4034 | | "\n" |
4035 | | "Execute the program specified by path in a new process.\n" |
4036 | | "\n" |
4037 | | " path\n" |
4038 | | " Path of executable file.\n" |
4039 | | " argv\n" |
4040 | | " Tuple or list of strings.\n" |
4041 | | " env\n" |
4042 | | " Dictionary of strings mapping to strings.\n" |
4043 | | " file_actions\n" |
4044 | | " A sequence of file action tuples.\n" |
4045 | | " setpgroup\n" |
4046 | | " The pgroup to use with the POSIX_SPAWN_SETPGROUP flag.\n" |
4047 | | " resetids\n" |
4048 | | " If the value is `True` the POSIX_SPAWN_RESETIDS will be activated.\n" |
4049 | | " setsid\n" |
4050 | | " If the value is `True` the POSIX_SPAWN_SETSID or POSIX_SPAWN_SETSID_NP will be activated.\n" |
4051 | | " setsigmask\n" |
4052 | | " The sigmask to use with the POSIX_SPAWN_SETSIGMASK flag.\n" |
4053 | | " setsigdef\n" |
4054 | | " The sigmask to use with the POSIX_SPAWN_SETSIGDEF flag.\n" |
4055 | | " scheduler\n" |
4056 | | " A tuple with the scheduler policy (optional) and parameters."); |
4057 | | |
4058 | | #define OS_POSIX_SPAWNP_METHODDEF \ |
4059 | | {"posix_spawnp", _PyCFunction_CAST(os_posix_spawnp), METH_FASTCALL|METH_KEYWORDS, os_posix_spawnp__doc__}, |
4060 | | |
4061 | | static PyObject * |
4062 | | os_posix_spawnp_impl(PyObject *module, path_t *path, PyObject *argv, |
4063 | | PyObject *env, PyObject *file_actions, |
4064 | | PyObject *setpgroup, int resetids, int setsid, |
4065 | | PyObject *setsigmask, PyObject *setsigdef, |
4066 | | PyObject *scheduler); |
4067 | | |
4068 | | static PyObject * |
4069 | | os_posix_spawnp(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
4070 | 0 | { |
4071 | 0 | PyObject *return_value = NULL; |
4072 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
4073 | |
|
4074 | 0 | #define NUM_KEYWORDS 7 |
4075 | 0 | static struct { |
4076 | 0 | PyGC_Head _this_is_not_used; |
4077 | 0 | PyObject_VAR_HEAD |
4078 | 0 | Py_hash_t ob_hash; |
4079 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
4080 | 0 | } _kwtuple = { |
4081 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
4082 | 0 | .ob_hash = -1, |
4083 | 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), }, |
4084 | 0 | }; |
4085 | 0 | #undef NUM_KEYWORDS |
4086 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
4087 | |
|
4088 | | #else // !Py_BUILD_CORE |
4089 | | # define KWTUPLE NULL |
4090 | | #endif // !Py_BUILD_CORE |
4091 | |
|
4092 | 0 | static const char * const _keywords[] = {"", "", "", "file_actions", "setpgroup", "resetids", "setsid", "setsigmask", "setsigdef", "scheduler", NULL}; |
4093 | 0 | static _PyArg_Parser _parser = { |
4094 | 0 | .keywords = _keywords, |
4095 | 0 | .fname = "posix_spawnp", |
4096 | 0 | .kwtuple = KWTUPLE, |
4097 | 0 | }; |
4098 | 0 | #undef KWTUPLE |
4099 | 0 | PyObject *argsbuf[10]; |
4100 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3; |
4101 | 0 | path_t path = PATH_T_INITIALIZE_P("posix_spawnp", "path", 0, 0, 0, 0); |
4102 | 0 | PyObject *argv; |
4103 | 0 | PyObject *env; |
4104 | 0 | PyObject *file_actions = NULL; |
4105 | 0 | PyObject *setpgroup = NULL; |
4106 | 0 | int resetids = 0; |
4107 | 0 | int setsid = 0; |
4108 | 0 | PyObject *setsigmask = NULL; |
4109 | 0 | PyObject *setsigdef = NULL; |
4110 | 0 | PyObject *scheduler = NULL; |
4111 | |
|
4112 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
4113 | 0 | /*minpos*/ 3, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
4114 | 0 | if (!args) { |
4115 | 0 | goto exit; |
4116 | 0 | } |
4117 | 0 | if (!path_converter(args[0], &path)) { |
4118 | 0 | goto exit; |
4119 | 0 | } |
4120 | 0 | argv = args[1]; |
4121 | 0 | env = args[2]; |
4122 | 0 | if (!noptargs) { |
4123 | 0 | goto skip_optional_kwonly; |
4124 | 0 | } |
4125 | 0 | if (args[3]) { |
4126 | 0 | file_actions = args[3]; |
4127 | 0 | if (!--noptargs) { |
4128 | 0 | goto skip_optional_kwonly; |
4129 | 0 | } |
4130 | 0 | } |
4131 | 0 | if (args[4]) { |
4132 | 0 | setpgroup = args[4]; |
4133 | 0 | if (!--noptargs) { |
4134 | 0 | goto skip_optional_kwonly; |
4135 | 0 | } |
4136 | 0 | } |
4137 | 0 | if (args[5]) { |
4138 | 0 | resetids = PyObject_IsTrue(args[5]); |
4139 | 0 | if (resetids < 0) { |
4140 | 0 | goto exit; |
4141 | 0 | } |
4142 | 0 | if (!--noptargs) { |
4143 | 0 | goto skip_optional_kwonly; |
4144 | 0 | } |
4145 | 0 | } |
4146 | 0 | if (args[6]) { |
4147 | 0 | setsid = PyObject_IsTrue(args[6]); |
4148 | 0 | if (setsid < 0) { |
4149 | 0 | goto exit; |
4150 | 0 | } |
4151 | 0 | if (!--noptargs) { |
4152 | 0 | goto skip_optional_kwonly; |
4153 | 0 | } |
4154 | 0 | } |
4155 | 0 | if (args[7]) { |
4156 | 0 | setsigmask = args[7]; |
4157 | 0 | if (!--noptargs) { |
4158 | 0 | goto skip_optional_kwonly; |
4159 | 0 | } |
4160 | 0 | } |
4161 | 0 | if (args[8]) { |
4162 | 0 | setsigdef = args[8]; |
4163 | 0 | if (!--noptargs) { |
4164 | 0 | goto skip_optional_kwonly; |
4165 | 0 | } |
4166 | 0 | } |
4167 | 0 | scheduler = args[9]; |
4168 | 0 | skip_optional_kwonly: |
4169 | 0 | return_value = os_posix_spawnp_impl(module, &path, argv, env, file_actions, setpgroup, resetids, setsid, setsigmask, setsigdef, scheduler); |
4170 | |
|
4171 | 0 | exit: |
4172 | | /* Cleanup for path */ |
4173 | 0 | path_cleanup(&path); |
4174 | |
|
4175 | 0 | return return_value; |
4176 | 0 | } |
4177 | | |
4178 | | #endif /* defined(HAVE_POSIX_SPAWNP) */ |
4179 | | |
4180 | | #if (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV) || defined(HAVE_RTPSPAWN)) |
4181 | | |
4182 | | PyDoc_STRVAR(os_spawnv__doc__, |
4183 | | "spawnv($module, mode, path, argv, /)\n" |
4184 | | "--\n" |
4185 | | "\n" |
4186 | | "Execute the program specified by path in a new process.\n" |
4187 | | "\n" |
4188 | | " mode\n" |
4189 | | " Mode of process creation.\n" |
4190 | | " path\n" |
4191 | | " Path of executable file.\n" |
4192 | | " argv\n" |
4193 | | " Tuple or list of strings."); |
4194 | | |
4195 | | #define OS_SPAWNV_METHODDEF \ |
4196 | | {"spawnv", _PyCFunction_CAST(os_spawnv), METH_FASTCALL, os_spawnv__doc__}, |
4197 | | |
4198 | | static PyObject * |
4199 | | os_spawnv_impl(PyObject *module, int mode, path_t *path, PyObject *argv); |
4200 | | |
4201 | | static PyObject * |
4202 | | os_spawnv(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
4203 | | { |
4204 | | PyObject *return_value = NULL; |
4205 | | int mode; |
4206 | | path_t path = PATH_T_INITIALIZE_P("spawnv", "path", 0, 0, 0, 0); |
4207 | | PyObject *argv; |
4208 | | |
4209 | | if (!_PyArg_CheckPositional("spawnv", nargs, 3, 3)) { |
4210 | | goto exit; |
4211 | | } |
4212 | | mode = PyLong_AsInt(args[0]); |
4213 | | if (mode == -1 && PyErr_Occurred()) { |
4214 | | goto exit; |
4215 | | } |
4216 | | if (!path_converter(args[1], &path)) { |
4217 | | goto exit; |
4218 | | } |
4219 | | argv = args[2]; |
4220 | | return_value = os_spawnv_impl(module, mode, &path, argv); |
4221 | | |
4222 | | exit: |
4223 | | /* Cleanup for path */ |
4224 | | path_cleanup(&path); |
4225 | | |
4226 | | return return_value; |
4227 | | } |
4228 | | |
4229 | | #endif /* (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV) || defined(HAVE_RTPSPAWN)) */ |
4230 | | |
4231 | | #if (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV) || defined(HAVE_RTPSPAWN)) |
4232 | | |
4233 | | PyDoc_STRVAR(os_spawnve__doc__, |
4234 | | "spawnve($module, mode, path, argv, env, /)\n" |
4235 | | "--\n" |
4236 | | "\n" |
4237 | | "Execute the program specified by path in a new process.\n" |
4238 | | "\n" |
4239 | | " mode\n" |
4240 | | " Mode of process creation.\n" |
4241 | | " path\n" |
4242 | | " Path of executable file.\n" |
4243 | | " argv\n" |
4244 | | " Tuple or list of strings.\n" |
4245 | | " env\n" |
4246 | | " Dictionary of strings mapping to strings."); |
4247 | | |
4248 | | #define OS_SPAWNVE_METHODDEF \ |
4249 | | {"spawnve", _PyCFunction_CAST(os_spawnve), METH_FASTCALL, os_spawnve__doc__}, |
4250 | | |
4251 | | static PyObject * |
4252 | | os_spawnve_impl(PyObject *module, int mode, path_t *path, PyObject *argv, |
4253 | | PyObject *env); |
4254 | | |
4255 | | static PyObject * |
4256 | | os_spawnve(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
4257 | | { |
4258 | | PyObject *return_value = NULL; |
4259 | | int mode; |
4260 | | path_t path = PATH_T_INITIALIZE_P("spawnve", "path", 0, 0, 0, 0); |
4261 | | PyObject *argv; |
4262 | | PyObject *env; |
4263 | | |
4264 | | if (!_PyArg_CheckPositional("spawnve", nargs, 4, 4)) { |
4265 | | goto exit; |
4266 | | } |
4267 | | mode = PyLong_AsInt(args[0]); |
4268 | | if (mode == -1 && PyErr_Occurred()) { |
4269 | | goto exit; |
4270 | | } |
4271 | | if (!path_converter(args[1], &path)) { |
4272 | | goto exit; |
4273 | | } |
4274 | | argv = args[2]; |
4275 | | env = args[3]; |
4276 | | return_value = os_spawnve_impl(module, mode, &path, argv, env); |
4277 | | |
4278 | | exit: |
4279 | | /* Cleanup for path */ |
4280 | | path_cleanup(&path); |
4281 | | |
4282 | | return return_value; |
4283 | | } |
4284 | | |
4285 | | #endif /* (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV) || defined(HAVE_RTPSPAWN)) */ |
4286 | | |
4287 | | #if defined(HAVE_FORK) |
4288 | | |
4289 | | PyDoc_STRVAR(os_register_at_fork__doc__, |
4290 | | "register_at_fork($module, /, *, before=<unrepresentable>,\n" |
4291 | | " after_in_child=<unrepresentable>,\n" |
4292 | | " after_in_parent=<unrepresentable>)\n" |
4293 | | "--\n" |
4294 | | "\n" |
4295 | | "Register callables to be called when forking a new process.\n" |
4296 | | "\n" |
4297 | | " before\n" |
4298 | | " A callable to be called in the parent before the fork() syscall.\n" |
4299 | | " after_in_child\n" |
4300 | | " A callable to be called in the child after fork().\n" |
4301 | | " after_in_parent\n" |
4302 | | " A callable to be called in the parent after fork().\n" |
4303 | | "\n" |
4304 | | "\'before\' callbacks are called in reverse order.\n" |
4305 | | "\'after_in_child\' and \'after_in_parent\' callbacks are called in order."); |
4306 | | |
4307 | | #define OS_REGISTER_AT_FORK_METHODDEF \ |
4308 | | {"register_at_fork", _PyCFunction_CAST(os_register_at_fork), METH_FASTCALL|METH_KEYWORDS, os_register_at_fork__doc__}, |
4309 | | |
4310 | | static PyObject * |
4311 | | os_register_at_fork_impl(PyObject *module, PyObject *before, |
4312 | | PyObject *after_in_child, PyObject *after_in_parent); |
4313 | | |
4314 | | static PyObject * |
4315 | | os_register_at_fork(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
4316 | 2 | { |
4317 | 2 | PyObject *return_value = NULL; |
4318 | 2 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
4319 | | |
4320 | 2 | #define NUM_KEYWORDS 3 |
4321 | 2 | static struct { |
4322 | 2 | PyGC_Head _this_is_not_used; |
4323 | 2 | PyObject_VAR_HEAD |
4324 | 2 | Py_hash_t ob_hash; |
4325 | 2 | PyObject *ob_item[NUM_KEYWORDS]; |
4326 | 2 | } _kwtuple = { |
4327 | 2 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
4328 | 2 | .ob_hash = -1, |
4329 | 2 | .ob_item = { &_Py_ID(before), &_Py_ID(after_in_child), &_Py_ID(after_in_parent), }, |
4330 | 2 | }; |
4331 | 2 | #undef NUM_KEYWORDS |
4332 | 2 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
4333 | | |
4334 | | #else // !Py_BUILD_CORE |
4335 | | # define KWTUPLE NULL |
4336 | | #endif // !Py_BUILD_CORE |
4337 | | |
4338 | 2 | static const char * const _keywords[] = {"before", "after_in_child", "after_in_parent", NULL}; |
4339 | 2 | static _PyArg_Parser _parser = { |
4340 | 2 | .keywords = _keywords, |
4341 | 2 | .fname = "register_at_fork", |
4342 | 2 | .kwtuple = KWTUPLE, |
4343 | 2 | }; |
4344 | 2 | #undef KWTUPLE |
4345 | 2 | PyObject *argsbuf[3]; |
4346 | 2 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; |
4347 | 2 | PyObject *before = NULL; |
4348 | 2 | PyObject *after_in_child = NULL; |
4349 | 2 | PyObject *after_in_parent = NULL; |
4350 | | |
4351 | 2 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
4352 | 2 | /*minpos*/ 0, /*maxpos*/ 0, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
4353 | 2 | if (!args) { |
4354 | 0 | goto exit; |
4355 | 0 | } |
4356 | 2 | if (!noptargs) { |
4357 | 0 | goto skip_optional_kwonly; |
4358 | 0 | } |
4359 | 2 | if (args[0]) { |
4360 | 0 | before = args[0]; |
4361 | 0 | if (!--noptargs) { |
4362 | 0 | goto skip_optional_kwonly; |
4363 | 0 | } |
4364 | 0 | } |
4365 | 2 | if (args[1]) { |
4366 | 2 | after_in_child = args[1]; |
4367 | 2 | if (!--noptargs) { |
4368 | 2 | goto skip_optional_kwonly; |
4369 | 2 | } |
4370 | 2 | } |
4371 | 0 | after_in_parent = args[2]; |
4372 | 2 | skip_optional_kwonly: |
4373 | 2 | return_value = os_register_at_fork_impl(module, before, after_in_child, after_in_parent); |
4374 | | |
4375 | 2 | exit: |
4376 | 2 | return return_value; |
4377 | 2 | } |
4378 | | |
4379 | | #endif /* defined(HAVE_FORK) */ |
4380 | | |
4381 | | #if defined(HAVE_FORK1) |
4382 | | |
4383 | | PyDoc_STRVAR(os_fork1__doc__, |
4384 | | "fork1($module, /)\n" |
4385 | | "--\n" |
4386 | | "\n" |
4387 | | "Fork a child process with a single multiplexed (i.e., not bound) thread.\n" |
4388 | | "\n" |
4389 | | "Return 0 to child process and PID of child to parent process."); |
4390 | | |
4391 | | #define OS_FORK1_METHODDEF \ |
4392 | | {"fork1", (PyCFunction)os_fork1, METH_NOARGS, os_fork1__doc__}, |
4393 | | |
4394 | | static PyObject * |
4395 | | os_fork1_impl(PyObject *module); |
4396 | | |
4397 | | static PyObject * |
4398 | | os_fork1(PyObject *module, PyObject *Py_UNUSED(ignored)) |
4399 | | { |
4400 | | return os_fork1_impl(module); |
4401 | | } |
4402 | | |
4403 | | #endif /* defined(HAVE_FORK1) */ |
4404 | | |
4405 | | #if defined(HAVE_FORK) |
4406 | | |
4407 | | PyDoc_STRVAR(os_fork__doc__, |
4408 | | "fork($module, /)\n" |
4409 | | "--\n" |
4410 | | "\n" |
4411 | | "Fork a child process.\n" |
4412 | | "\n" |
4413 | | "Return 0 to child process and PID of child to parent process."); |
4414 | | |
4415 | | #define OS_FORK_METHODDEF \ |
4416 | | {"fork", (PyCFunction)os_fork, METH_NOARGS, os_fork__doc__}, |
4417 | | |
4418 | | static PyObject * |
4419 | | os_fork_impl(PyObject *module); |
4420 | | |
4421 | | static PyObject * |
4422 | | os_fork(PyObject *module, PyObject *Py_UNUSED(ignored)) |
4423 | 0 | { |
4424 | 0 | return os_fork_impl(module); |
4425 | 0 | } |
4426 | | |
4427 | | #endif /* defined(HAVE_FORK) */ |
4428 | | |
4429 | | #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) |
4430 | | |
4431 | | PyDoc_STRVAR(os_sched_get_priority_max__doc__, |
4432 | | "sched_get_priority_max($module, /, policy)\n" |
4433 | | "--\n" |
4434 | | "\n" |
4435 | | "Get the maximum scheduling priority for policy."); |
4436 | | |
4437 | | #define OS_SCHED_GET_PRIORITY_MAX_METHODDEF \ |
4438 | | {"sched_get_priority_max", _PyCFunction_CAST(os_sched_get_priority_max), METH_FASTCALL|METH_KEYWORDS, os_sched_get_priority_max__doc__}, |
4439 | | |
4440 | | static PyObject * |
4441 | | os_sched_get_priority_max_impl(PyObject *module, int policy); |
4442 | | |
4443 | | static PyObject * |
4444 | | os_sched_get_priority_max(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
4445 | 0 | { |
4446 | 0 | PyObject *return_value = NULL; |
4447 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
4448 | |
|
4449 | 0 | #define NUM_KEYWORDS 1 |
4450 | 0 | static struct { |
4451 | 0 | PyGC_Head _this_is_not_used; |
4452 | 0 | PyObject_VAR_HEAD |
4453 | 0 | Py_hash_t ob_hash; |
4454 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
4455 | 0 | } _kwtuple = { |
4456 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
4457 | 0 | .ob_hash = -1, |
4458 | 0 | .ob_item = { &_Py_ID(policy), }, |
4459 | 0 | }; |
4460 | 0 | #undef NUM_KEYWORDS |
4461 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
4462 | |
|
4463 | | #else // !Py_BUILD_CORE |
4464 | | # define KWTUPLE NULL |
4465 | | #endif // !Py_BUILD_CORE |
4466 | |
|
4467 | 0 | static const char * const _keywords[] = {"policy", NULL}; |
4468 | 0 | static _PyArg_Parser _parser = { |
4469 | 0 | .keywords = _keywords, |
4470 | 0 | .fname = "sched_get_priority_max", |
4471 | 0 | .kwtuple = KWTUPLE, |
4472 | 0 | }; |
4473 | 0 | #undef KWTUPLE |
4474 | 0 | PyObject *argsbuf[1]; |
4475 | 0 | int policy; |
4476 | |
|
4477 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
4478 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
4479 | 0 | if (!args) { |
4480 | 0 | goto exit; |
4481 | 0 | } |
4482 | 0 | policy = PyLong_AsInt(args[0]); |
4483 | 0 | if (policy == -1 && PyErr_Occurred()) { |
4484 | 0 | goto exit; |
4485 | 0 | } |
4486 | 0 | return_value = os_sched_get_priority_max_impl(module, policy); |
4487 | |
|
4488 | 0 | exit: |
4489 | 0 | return return_value; |
4490 | 0 | } |
4491 | | |
4492 | | #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) */ |
4493 | | |
4494 | | #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) |
4495 | | |
4496 | | PyDoc_STRVAR(os_sched_get_priority_min__doc__, |
4497 | | "sched_get_priority_min($module, /, policy)\n" |
4498 | | "--\n" |
4499 | | "\n" |
4500 | | "Get the minimum scheduling priority for policy."); |
4501 | | |
4502 | | #define OS_SCHED_GET_PRIORITY_MIN_METHODDEF \ |
4503 | | {"sched_get_priority_min", _PyCFunction_CAST(os_sched_get_priority_min), METH_FASTCALL|METH_KEYWORDS, os_sched_get_priority_min__doc__}, |
4504 | | |
4505 | | static PyObject * |
4506 | | os_sched_get_priority_min_impl(PyObject *module, int policy); |
4507 | | |
4508 | | static PyObject * |
4509 | | os_sched_get_priority_min(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
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(policy), }, |
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[] = {"policy", NULL}; |
4533 | 0 | static _PyArg_Parser _parser = { |
4534 | 0 | .keywords = _keywords, |
4535 | 0 | .fname = "sched_get_priority_min", |
4536 | 0 | .kwtuple = KWTUPLE, |
4537 | 0 | }; |
4538 | 0 | #undef KWTUPLE |
4539 | 0 | PyObject *argsbuf[1]; |
4540 | 0 | int policy; |
4541 | |
|
4542 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
4543 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
4544 | 0 | if (!args) { |
4545 | 0 | goto exit; |
4546 | 0 | } |
4547 | 0 | policy = PyLong_AsInt(args[0]); |
4548 | 0 | if (policy == -1 && PyErr_Occurred()) { |
4549 | 0 | goto exit; |
4550 | 0 | } |
4551 | 0 | return_value = os_sched_get_priority_min_impl(module, policy); |
4552 | |
|
4553 | 0 | exit: |
4554 | 0 | return return_value; |
4555 | 0 | } |
4556 | | |
4557 | | #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) */ |
4558 | | |
4559 | | #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) |
4560 | | |
4561 | | PyDoc_STRVAR(os_sched_getscheduler__doc__, |
4562 | | "sched_getscheduler($module, pid, /)\n" |
4563 | | "--\n" |
4564 | | "\n" |
4565 | | "Get the scheduling policy for the process identified by pid.\n" |
4566 | | "\n" |
4567 | | "Passing 0 for pid returns the scheduling policy for the calling process."); |
4568 | | |
4569 | | #define OS_SCHED_GETSCHEDULER_METHODDEF \ |
4570 | | {"sched_getscheduler", (PyCFunction)os_sched_getscheduler, METH_O, os_sched_getscheduler__doc__}, |
4571 | | |
4572 | | static PyObject * |
4573 | | os_sched_getscheduler_impl(PyObject *module, pid_t pid); |
4574 | | |
4575 | | static PyObject * |
4576 | | os_sched_getscheduler(PyObject *module, PyObject *arg) |
4577 | 0 | { |
4578 | 0 | PyObject *return_value = NULL; |
4579 | 0 | pid_t pid; |
4580 | |
|
4581 | 0 | pid = PyLong_AsPid(arg); |
4582 | 0 | if (pid == (pid_t)(-1) && PyErr_Occurred()) { |
4583 | 0 | goto exit; |
4584 | 0 | } |
4585 | 0 | return_value = os_sched_getscheduler_impl(module, pid); |
4586 | |
|
4587 | 0 | exit: |
4588 | 0 | return return_value; |
4589 | 0 | } |
4590 | | |
4591 | | #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) */ |
4592 | | |
4593 | | #if defined(HAVE_SCHED_H) && (defined(HAVE_SCHED_SETPARAM) || defined(HAVE_SCHED_SETSCHEDULER) || defined(POSIX_SPAWN_SETSCHEDULER) || defined(POSIX_SPAWN_SETSCHEDPARAM)) |
4594 | | |
4595 | | PyDoc_STRVAR(os_sched_param__doc__, |
4596 | | "sched_param(sched_priority)\n" |
4597 | | "--\n" |
4598 | | "\n" |
4599 | | "Currently has only one field: sched_priority\n" |
4600 | | "\n" |
4601 | | " sched_priority\n" |
4602 | | " A scheduling parameter."); |
4603 | | |
4604 | | static PyObject * |
4605 | | os_sched_param_impl(PyTypeObject *type, PyObject *sched_priority); |
4606 | | |
4607 | | static PyObject * |
4608 | | os_sched_param(PyTypeObject *type, PyObject *args, PyObject *kwargs) |
4609 | 0 | { |
4610 | 0 | PyObject *return_value = NULL; |
4611 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
4612 | |
|
4613 | 0 | #define NUM_KEYWORDS 1 |
4614 | 0 | static struct { |
4615 | 0 | PyGC_Head _this_is_not_used; |
4616 | 0 | PyObject_VAR_HEAD |
4617 | 0 | Py_hash_t ob_hash; |
4618 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
4619 | 0 | } _kwtuple = { |
4620 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
4621 | 0 | .ob_hash = -1, |
4622 | 0 | .ob_item = { &_Py_ID(sched_priority), }, |
4623 | 0 | }; |
4624 | 0 | #undef NUM_KEYWORDS |
4625 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
4626 | |
|
4627 | | #else // !Py_BUILD_CORE |
4628 | | # define KWTUPLE NULL |
4629 | | #endif // !Py_BUILD_CORE |
4630 | |
|
4631 | 0 | static const char * const _keywords[] = {"sched_priority", NULL}; |
4632 | 0 | static _PyArg_Parser _parser = { |
4633 | 0 | .keywords = _keywords, |
4634 | 0 | .fname = "sched_param", |
4635 | 0 | .kwtuple = KWTUPLE, |
4636 | 0 | }; |
4637 | 0 | #undef KWTUPLE |
4638 | 0 | PyObject *argsbuf[1]; |
4639 | 0 | PyObject * const *fastargs; |
4640 | 0 | Py_ssize_t nargs = PyTuple_GET_SIZE(args); |
4641 | 0 | PyObject *sched_priority; |
4642 | |
|
4643 | 0 | fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, |
4644 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
4645 | 0 | if (!fastargs) { |
4646 | 0 | goto exit; |
4647 | 0 | } |
4648 | 0 | sched_priority = fastargs[0]; |
4649 | 0 | return_value = os_sched_param_impl(type, sched_priority); |
4650 | |
|
4651 | 0 | exit: |
4652 | 0 | return return_value; |
4653 | 0 | } |
4654 | | |
4655 | | #endif /* defined(HAVE_SCHED_H) && (defined(HAVE_SCHED_SETPARAM) || defined(HAVE_SCHED_SETSCHEDULER) || defined(POSIX_SPAWN_SETSCHEDULER) || defined(POSIX_SPAWN_SETSCHEDPARAM)) */ |
4656 | | |
4657 | | #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) |
4658 | | |
4659 | | PyDoc_STRVAR(os_sched_setscheduler__doc__, |
4660 | | "sched_setscheduler($module, pid, policy, param, /)\n" |
4661 | | "--\n" |
4662 | | "\n" |
4663 | | "Set the scheduling policy for the process identified by pid.\n" |
4664 | | "\n" |
4665 | | "If pid is 0, the calling process is changed.\n" |
4666 | | "param is an instance of sched_param."); |
4667 | | |
4668 | | #define OS_SCHED_SETSCHEDULER_METHODDEF \ |
4669 | | {"sched_setscheduler", _PyCFunction_CAST(os_sched_setscheduler), METH_FASTCALL, os_sched_setscheduler__doc__}, |
4670 | | |
4671 | | static PyObject * |
4672 | | os_sched_setscheduler_impl(PyObject *module, pid_t pid, int policy, |
4673 | | PyObject *param_obj); |
4674 | | |
4675 | | static PyObject * |
4676 | | os_sched_setscheduler(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
4677 | 0 | { |
4678 | 0 | PyObject *return_value = NULL; |
4679 | 0 | pid_t pid; |
4680 | 0 | int policy; |
4681 | 0 | PyObject *param_obj; |
4682 | |
|
4683 | 0 | if (!_PyArg_CheckPositional("sched_setscheduler", nargs, 3, 3)) { |
4684 | 0 | goto exit; |
4685 | 0 | } |
4686 | 0 | pid = PyLong_AsPid(args[0]); |
4687 | 0 | if (pid == (pid_t)(-1) && PyErr_Occurred()) { |
4688 | 0 | goto exit; |
4689 | 0 | } |
4690 | 0 | policy = PyLong_AsInt(args[1]); |
4691 | 0 | if (policy == -1 && PyErr_Occurred()) { |
4692 | 0 | goto exit; |
4693 | 0 | } |
4694 | 0 | param_obj = args[2]; |
4695 | 0 | return_value = os_sched_setscheduler_impl(module, pid, policy, param_obj); |
4696 | |
|
4697 | 0 | exit: |
4698 | 0 | return return_value; |
4699 | 0 | } |
4700 | | |
4701 | | #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) */ |
4702 | | |
4703 | | #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) |
4704 | | |
4705 | | PyDoc_STRVAR(os_sched_getparam__doc__, |
4706 | | "sched_getparam($module, pid, /)\n" |
4707 | | "--\n" |
4708 | | "\n" |
4709 | | "Returns scheduling parameters for the process identified by pid.\n" |
4710 | | "\n" |
4711 | | "If pid is 0, returns parameters for the calling process.\n" |
4712 | | "Return value is an instance of sched_param."); |
4713 | | |
4714 | | #define OS_SCHED_GETPARAM_METHODDEF \ |
4715 | | {"sched_getparam", (PyCFunction)os_sched_getparam, METH_O, os_sched_getparam__doc__}, |
4716 | | |
4717 | | static PyObject * |
4718 | | os_sched_getparam_impl(PyObject *module, pid_t pid); |
4719 | | |
4720 | | static PyObject * |
4721 | | os_sched_getparam(PyObject *module, PyObject *arg) |
4722 | 0 | { |
4723 | 0 | PyObject *return_value = NULL; |
4724 | 0 | pid_t pid; |
4725 | |
|
4726 | 0 | pid = PyLong_AsPid(arg); |
4727 | 0 | if (pid == (pid_t)(-1) && PyErr_Occurred()) { |
4728 | 0 | goto exit; |
4729 | 0 | } |
4730 | 0 | return_value = os_sched_getparam_impl(module, pid); |
4731 | |
|
4732 | 0 | exit: |
4733 | 0 | return return_value; |
4734 | 0 | } |
4735 | | |
4736 | | #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) */ |
4737 | | |
4738 | | #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) |
4739 | | |
4740 | | PyDoc_STRVAR(os_sched_setparam__doc__, |
4741 | | "sched_setparam($module, pid, param, /)\n" |
4742 | | "--\n" |
4743 | | "\n" |
4744 | | "Set scheduling parameters for the process identified by pid.\n" |
4745 | | "\n" |
4746 | | "If pid is 0, sets parameters for the calling process.\n" |
4747 | | "param should be an instance of sched_param."); |
4748 | | |
4749 | | #define OS_SCHED_SETPARAM_METHODDEF \ |
4750 | | {"sched_setparam", _PyCFunction_CAST(os_sched_setparam), METH_FASTCALL, os_sched_setparam__doc__}, |
4751 | | |
4752 | | static PyObject * |
4753 | | os_sched_setparam_impl(PyObject *module, pid_t pid, PyObject *param_obj); |
4754 | | |
4755 | | static PyObject * |
4756 | | os_sched_setparam(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
4757 | 0 | { |
4758 | 0 | PyObject *return_value = NULL; |
4759 | 0 | pid_t pid; |
4760 | 0 | PyObject *param_obj; |
4761 | |
|
4762 | 0 | if (!_PyArg_CheckPositional("sched_setparam", nargs, 2, 2)) { |
4763 | 0 | goto exit; |
4764 | 0 | } |
4765 | 0 | pid = PyLong_AsPid(args[0]); |
4766 | 0 | if (pid == (pid_t)(-1) && PyErr_Occurred()) { |
4767 | 0 | goto exit; |
4768 | 0 | } |
4769 | 0 | param_obj = args[1]; |
4770 | 0 | return_value = os_sched_setparam_impl(module, pid, param_obj); |
4771 | |
|
4772 | 0 | exit: |
4773 | 0 | return return_value; |
4774 | 0 | } |
4775 | | |
4776 | | #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) */ |
4777 | | |
4778 | | #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_RR_GET_INTERVAL) |
4779 | | |
4780 | | PyDoc_STRVAR(os_sched_rr_get_interval__doc__, |
4781 | | "sched_rr_get_interval($module, pid, /)\n" |
4782 | | "--\n" |
4783 | | "\n" |
4784 | | "Return the round-robin quantum for the process identified by pid, in seconds.\n" |
4785 | | "\n" |
4786 | | "Value returned is a float."); |
4787 | | |
4788 | | #define OS_SCHED_RR_GET_INTERVAL_METHODDEF \ |
4789 | | {"sched_rr_get_interval", (PyCFunction)os_sched_rr_get_interval, METH_O, os_sched_rr_get_interval__doc__}, |
4790 | | |
4791 | | static double |
4792 | | os_sched_rr_get_interval_impl(PyObject *module, pid_t pid); |
4793 | | |
4794 | | static PyObject * |
4795 | | os_sched_rr_get_interval(PyObject *module, PyObject *arg) |
4796 | 0 | { |
4797 | 0 | PyObject *return_value = NULL; |
4798 | 0 | pid_t pid; |
4799 | 0 | double _return_value; |
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_rr_get_interval_impl(module, pid); |
4806 | 0 | if ((_return_value == -1.0) && PyErr_Occurred()) { |
4807 | 0 | goto exit; |
4808 | 0 | } |
4809 | 0 | return_value = PyFloat_FromDouble(_return_value); |
4810 | |
|
4811 | 0 | exit: |
4812 | 0 | return return_value; |
4813 | 0 | } |
4814 | | |
4815 | | #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_RR_GET_INTERVAL) */ |
4816 | | |
4817 | | #if defined(HAVE_SCHED_H) |
4818 | | |
4819 | | PyDoc_STRVAR(os_sched_yield__doc__, |
4820 | | "sched_yield($module, /)\n" |
4821 | | "--\n" |
4822 | | "\n" |
4823 | | "Voluntarily relinquish the CPU."); |
4824 | | |
4825 | | #define OS_SCHED_YIELD_METHODDEF \ |
4826 | | {"sched_yield", (PyCFunction)os_sched_yield, METH_NOARGS, os_sched_yield__doc__}, |
4827 | | |
4828 | | static PyObject * |
4829 | | os_sched_yield_impl(PyObject *module); |
4830 | | |
4831 | | static PyObject * |
4832 | | os_sched_yield(PyObject *module, PyObject *Py_UNUSED(ignored)) |
4833 | 0 | { |
4834 | 0 | return os_sched_yield_impl(module); |
4835 | 0 | } |
4836 | | |
4837 | | #endif /* defined(HAVE_SCHED_H) */ |
4838 | | |
4839 | | #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) |
4840 | | |
4841 | | PyDoc_STRVAR(os_sched_setaffinity__doc__, |
4842 | | "sched_setaffinity($module, pid, mask, /)\n" |
4843 | | "--\n" |
4844 | | "\n" |
4845 | | "Set the CPU affinity of the process identified by pid to mask.\n" |
4846 | | "\n" |
4847 | | "mask should be an iterable of integers identifying CPUs."); |
4848 | | |
4849 | | #define OS_SCHED_SETAFFINITY_METHODDEF \ |
4850 | | {"sched_setaffinity", _PyCFunction_CAST(os_sched_setaffinity), METH_FASTCALL, os_sched_setaffinity__doc__}, |
4851 | | |
4852 | | static PyObject * |
4853 | | os_sched_setaffinity_impl(PyObject *module, pid_t pid, PyObject *mask); |
4854 | | |
4855 | | static PyObject * |
4856 | | os_sched_setaffinity(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
4857 | 0 | { |
4858 | 0 | PyObject *return_value = NULL; |
4859 | 0 | pid_t pid; |
4860 | 0 | PyObject *mask; |
4861 | |
|
4862 | 0 | if (!_PyArg_CheckPositional("sched_setaffinity", nargs, 2, 2)) { |
4863 | 0 | goto exit; |
4864 | 0 | } |
4865 | 0 | pid = PyLong_AsPid(args[0]); |
4866 | 0 | if (pid == (pid_t)(-1) && PyErr_Occurred()) { |
4867 | 0 | goto exit; |
4868 | 0 | } |
4869 | 0 | mask = args[1]; |
4870 | 0 | return_value = os_sched_setaffinity_impl(module, pid, mask); |
4871 | |
|
4872 | 0 | exit: |
4873 | 0 | return return_value; |
4874 | 0 | } |
4875 | | |
4876 | | #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) */ |
4877 | | |
4878 | | #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) |
4879 | | |
4880 | | PyDoc_STRVAR(os_sched_getaffinity__doc__, |
4881 | | "sched_getaffinity($module, pid, /)\n" |
4882 | | "--\n" |
4883 | | "\n" |
4884 | | "Return the affinity of the process identified by pid (or the current process if zero).\n" |
4885 | | "\n" |
4886 | | "The affinity is returned as a set of CPU identifiers."); |
4887 | | |
4888 | | #define OS_SCHED_GETAFFINITY_METHODDEF \ |
4889 | | {"sched_getaffinity", (PyCFunction)os_sched_getaffinity, METH_O, os_sched_getaffinity__doc__}, |
4890 | | |
4891 | | static PyObject * |
4892 | | os_sched_getaffinity_impl(PyObject *module, pid_t pid); |
4893 | | |
4894 | | static PyObject * |
4895 | | os_sched_getaffinity(PyObject *module, PyObject *arg) |
4896 | 0 | { |
4897 | 0 | PyObject *return_value = NULL; |
4898 | 0 | pid_t pid; |
4899 | |
|
4900 | 0 | pid = PyLong_AsPid(arg); |
4901 | 0 | if (pid == (pid_t)(-1) && PyErr_Occurred()) { |
4902 | 0 | goto exit; |
4903 | 0 | } |
4904 | 0 | return_value = os_sched_getaffinity_impl(module, pid); |
4905 | |
|
4906 | 0 | exit: |
4907 | 0 | return return_value; |
4908 | 0 | } |
4909 | | |
4910 | | #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) */ |
4911 | | |
4912 | | #if defined(HAVE_POSIX_OPENPT) |
4913 | | |
4914 | | PyDoc_STRVAR(os_posix_openpt__doc__, |
4915 | | "posix_openpt($module, oflag, /)\n" |
4916 | | "--\n" |
4917 | | "\n" |
4918 | | "Open and return a file descriptor for a master pseudo-terminal device.\n" |
4919 | | "\n" |
4920 | | "Performs a posix_openpt() C function call. The oflag argument is used to\n" |
4921 | | "set file status flags and file access modes as specified in the manual page\n" |
4922 | | "of posix_openpt() of your system."); |
4923 | | |
4924 | | #define OS_POSIX_OPENPT_METHODDEF \ |
4925 | | {"posix_openpt", (PyCFunction)os_posix_openpt, METH_O, os_posix_openpt__doc__}, |
4926 | | |
4927 | | static int |
4928 | | os_posix_openpt_impl(PyObject *module, int oflag); |
4929 | | |
4930 | | static PyObject * |
4931 | | os_posix_openpt(PyObject *module, PyObject *arg) |
4932 | 0 | { |
4933 | 0 | PyObject *return_value = NULL; |
4934 | 0 | int oflag; |
4935 | 0 | int _return_value; |
4936 | |
|
4937 | 0 | oflag = PyLong_AsInt(arg); |
4938 | 0 | if (oflag == -1 && PyErr_Occurred()) { |
4939 | 0 | goto exit; |
4940 | 0 | } |
4941 | 0 | _return_value = os_posix_openpt_impl(module, oflag); |
4942 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
4943 | 0 | goto exit; |
4944 | 0 | } |
4945 | 0 | return_value = PyLong_FromLong((long)_return_value); |
4946 | |
|
4947 | 0 | exit: |
4948 | 0 | return return_value; |
4949 | 0 | } |
4950 | | |
4951 | | #endif /* defined(HAVE_POSIX_OPENPT) */ |
4952 | | |
4953 | | #if defined(HAVE_GRANTPT) |
4954 | | |
4955 | | PyDoc_STRVAR(os_grantpt__doc__, |
4956 | | "grantpt($module, fd, /)\n" |
4957 | | "--\n" |
4958 | | "\n" |
4959 | | "Grant access to the slave pseudo-terminal device.\n" |
4960 | | "\n" |
4961 | | " fd\n" |
4962 | | " File descriptor of a master pseudo-terminal device.\n" |
4963 | | "\n" |
4964 | | "Performs a grantpt() C function call."); |
4965 | | |
4966 | | #define OS_GRANTPT_METHODDEF \ |
4967 | | {"grantpt", (PyCFunction)os_grantpt, METH_O, os_grantpt__doc__}, |
4968 | | |
4969 | | static PyObject * |
4970 | | os_grantpt_impl(PyObject *module, int fd); |
4971 | | |
4972 | | static PyObject * |
4973 | | os_grantpt(PyObject *module, PyObject *arg) |
4974 | 0 | { |
4975 | 0 | PyObject *return_value = NULL; |
4976 | 0 | int fd; |
4977 | |
|
4978 | 0 | fd = PyObject_AsFileDescriptor(arg); |
4979 | 0 | if (fd < 0) { |
4980 | 0 | goto exit; |
4981 | 0 | } |
4982 | 0 | return_value = os_grantpt_impl(module, fd); |
4983 | |
|
4984 | 0 | exit: |
4985 | 0 | return return_value; |
4986 | 0 | } |
4987 | | |
4988 | | #endif /* defined(HAVE_GRANTPT) */ |
4989 | | |
4990 | | #if defined(HAVE_UNLOCKPT) |
4991 | | |
4992 | | PyDoc_STRVAR(os_unlockpt__doc__, |
4993 | | "unlockpt($module, fd, /)\n" |
4994 | | "--\n" |
4995 | | "\n" |
4996 | | "Unlock a pseudo-terminal master/slave pair.\n" |
4997 | | "\n" |
4998 | | " fd\n" |
4999 | | " File descriptor of a master pseudo-terminal device.\n" |
5000 | | "\n" |
5001 | | "Performs an unlockpt() C function call."); |
5002 | | |
5003 | | #define OS_UNLOCKPT_METHODDEF \ |
5004 | | {"unlockpt", (PyCFunction)os_unlockpt, METH_O, os_unlockpt__doc__}, |
5005 | | |
5006 | | static PyObject * |
5007 | | os_unlockpt_impl(PyObject *module, int fd); |
5008 | | |
5009 | | static PyObject * |
5010 | | os_unlockpt(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_unlockpt_impl(module, fd); |
5020 | |
|
5021 | 0 | exit: |
5022 | 0 | return return_value; |
5023 | 0 | } |
5024 | | |
5025 | | #endif /* defined(HAVE_UNLOCKPT) */ |
5026 | | |
5027 | | #if (defined(HAVE_PTSNAME) || defined(HAVE_PTSNAME_R)) |
5028 | | |
5029 | | PyDoc_STRVAR(os_ptsname__doc__, |
5030 | | "ptsname($module, fd, /)\n" |
5031 | | "--\n" |
5032 | | "\n" |
5033 | | "Return the name of the slave pseudo-terminal device.\n" |
5034 | | "\n" |
5035 | | " fd\n" |
5036 | | " File descriptor of a master pseudo-terminal device.\n" |
5037 | | "\n" |
5038 | | "If the ptsname_r() C function is available, it is called;\n" |
5039 | | "otherwise, performs a ptsname() C function call."); |
5040 | | |
5041 | | #define OS_PTSNAME_METHODDEF \ |
5042 | | {"ptsname", (PyCFunction)os_ptsname, METH_O, os_ptsname__doc__}, |
5043 | | |
5044 | | static PyObject * |
5045 | | os_ptsname_impl(PyObject *module, int fd); |
5046 | | |
5047 | | static PyObject * |
5048 | | os_ptsname(PyObject *module, PyObject *arg) |
5049 | 0 | { |
5050 | 0 | PyObject *return_value = NULL; |
5051 | 0 | int fd; |
5052 | |
|
5053 | 0 | fd = PyObject_AsFileDescriptor(arg); |
5054 | 0 | if (fd < 0) { |
5055 | 0 | goto exit; |
5056 | 0 | } |
5057 | 0 | return_value = os_ptsname_impl(module, fd); |
5058 | |
|
5059 | 0 | exit: |
5060 | 0 | return return_value; |
5061 | 0 | } |
5062 | | |
5063 | | #endif /* (defined(HAVE_PTSNAME) || defined(HAVE_PTSNAME_R)) */ |
5064 | | |
5065 | | #if (defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX)) |
5066 | | |
5067 | | PyDoc_STRVAR(os_openpty__doc__, |
5068 | | "openpty($module, /)\n" |
5069 | | "--\n" |
5070 | | "\n" |
5071 | | "Open a pseudo-terminal.\n" |
5072 | | "\n" |
5073 | | "Return a tuple of (master_fd, slave_fd) containing open file descriptors\n" |
5074 | | "for both the master and slave ends."); |
5075 | | |
5076 | | #define OS_OPENPTY_METHODDEF \ |
5077 | | {"openpty", (PyCFunction)os_openpty, METH_NOARGS, os_openpty__doc__}, |
5078 | | |
5079 | | static PyObject * |
5080 | | os_openpty_impl(PyObject *module); |
5081 | | |
5082 | | static PyObject * |
5083 | | os_openpty(PyObject *module, PyObject *Py_UNUSED(ignored)) |
5084 | 0 | { |
5085 | 0 | return os_openpty_impl(module); |
5086 | 0 | } |
5087 | | |
5088 | | #endif /* (defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX)) */ |
5089 | | |
5090 | | #if (defined(HAVE_LOGIN_TTY) || defined(HAVE_FALLBACK_LOGIN_TTY)) |
5091 | | |
5092 | | PyDoc_STRVAR(os_login_tty__doc__, |
5093 | | "login_tty($module, fd, /)\n" |
5094 | | "--\n" |
5095 | | "\n" |
5096 | | "Prepare the tty of which fd is a file descriptor for a new login session.\n" |
5097 | | "\n" |
5098 | | "Make the calling process a session leader; make the tty the\n" |
5099 | | "controlling tty, the stdin, the stdout, and the stderr of the\n" |
5100 | | "calling process; close fd."); |
5101 | | |
5102 | | #define OS_LOGIN_TTY_METHODDEF \ |
5103 | | {"login_tty", (PyCFunction)os_login_tty, METH_O, os_login_tty__doc__}, |
5104 | | |
5105 | | static PyObject * |
5106 | | os_login_tty_impl(PyObject *module, int fd); |
5107 | | |
5108 | | static PyObject * |
5109 | | os_login_tty(PyObject *module, PyObject *arg) |
5110 | 0 | { |
5111 | 0 | PyObject *return_value = NULL; |
5112 | 0 | int fd; |
5113 | |
|
5114 | 0 | fd = PyObject_AsFileDescriptor(arg); |
5115 | 0 | if (fd < 0) { |
5116 | 0 | goto exit; |
5117 | 0 | } |
5118 | 0 | return_value = os_login_tty_impl(module, fd); |
5119 | |
|
5120 | 0 | exit: |
5121 | 0 | return return_value; |
5122 | 0 | } |
5123 | | |
5124 | | #endif /* (defined(HAVE_LOGIN_TTY) || defined(HAVE_FALLBACK_LOGIN_TTY)) */ |
5125 | | |
5126 | | #if defined(HAVE_FORKPTY) |
5127 | | |
5128 | | PyDoc_STRVAR(os_forkpty__doc__, |
5129 | | "forkpty($module, /)\n" |
5130 | | "--\n" |
5131 | | "\n" |
5132 | | "Fork a new process with a new pseudo-terminal as controlling tty.\n" |
5133 | | "\n" |
5134 | | "Returns a tuple of (pid, master_fd).\n" |
5135 | | "Like fork(), return pid of 0 to the child process,\n" |
5136 | | "and pid of child to the parent process.\n" |
5137 | | "To both, return fd of newly opened pseudo-terminal."); |
5138 | | |
5139 | | #define OS_FORKPTY_METHODDEF \ |
5140 | | {"forkpty", (PyCFunction)os_forkpty, METH_NOARGS, os_forkpty__doc__}, |
5141 | | |
5142 | | static PyObject * |
5143 | | os_forkpty_impl(PyObject *module); |
5144 | | |
5145 | | static PyObject * |
5146 | | os_forkpty(PyObject *module, PyObject *Py_UNUSED(ignored)) |
5147 | 0 | { |
5148 | 0 | return os_forkpty_impl(module); |
5149 | 0 | } |
5150 | | |
5151 | | #endif /* defined(HAVE_FORKPTY) */ |
5152 | | |
5153 | | #if defined(HAVE_GETEGID) |
5154 | | |
5155 | | PyDoc_STRVAR(os_getegid__doc__, |
5156 | | "getegid($module, /)\n" |
5157 | | "--\n" |
5158 | | "\n" |
5159 | | "Return the current process\'s effective group id."); |
5160 | | |
5161 | | #define OS_GETEGID_METHODDEF \ |
5162 | | {"getegid", (PyCFunction)os_getegid, METH_NOARGS, os_getegid__doc__}, |
5163 | | |
5164 | | static PyObject * |
5165 | | os_getegid_impl(PyObject *module); |
5166 | | |
5167 | | static PyObject * |
5168 | | os_getegid(PyObject *module, PyObject *Py_UNUSED(ignored)) |
5169 | 16 | { |
5170 | 16 | return os_getegid_impl(module); |
5171 | 16 | } |
5172 | | |
5173 | | #endif /* defined(HAVE_GETEGID) */ |
5174 | | |
5175 | | #if defined(HAVE_GETEUID) |
5176 | | |
5177 | | PyDoc_STRVAR(os_geteuid__doc__, |
5178 | | "geteuid($module, /)\n" |
5179 | | "--\n" |
5180 | | "\n" |
5181 | | "Return the current process\'s effective user id."); |
5182 | | |
5183 | | #define OS_GETEUID_METHODDEF \ |
5184 | | {"geteuid", (PyCFunction)os_geteuid, METH_NOARGS, os_geteuid__doc__}, |
5185 | | |
5186 | | static PyObject * |
5187 | | os_geteuid_impl(PyObject *module); |
5188 | | |
5189 | | static PyObject * |
5190 | | os_geteuid(PyObject *module, PyObject *Py_UNUSED(ignored)) |
5191 | 16 | { |
5192 | 16 | return os_geteuid_impl(module); |
5193 | 16 | } |
5194 | | |
5195 | | #endif /* defined(HAVE_GETEUID) */ |
5196 | | |
5197 | | #if defined(HAVE_GETGID) |
5198 | | |
5199 | | PyDoc_STRVAR(os_getgid__doc__, |
5200 | | "getgid($module, /)\n" |
5201 | | "--\n" |
5202 | | "\n" |
5203 | | "Return the current process\'s group id."); |
5204 | | |
5205 | | #define OS_GETGID_METHODDEF \ |
5206 | | {"getgid", (PyCFunction)os_getgid, METH_NOARGS, os_getgid__doc__}, |
5207 | | |
5208 | | static PyObject * |
5209 | | os_getgid_impl(PyObject *module); |
5210 | | |
5211 | | static PyObject * |
5212 | | os_getgid(PyObject *module, PyObject *Py_UNUSED(ignored)) |
5213 | 16 | { |
5214 | 16 | return os_getgid_impl(module); |
5215 | 16 | } |
5216 | | |
5217 | | #endif /* defined(HAVE_GETGID) */ |
5218 | | |
5219 | | #if defined(HAVE_GETPID) |
5220 | | |
5221 | | PyDoc_STRVAR(os_getpid__doc__, |
5222 | | "getpid($module, /)\n" |
5223 | | "--\n" |
5224 | | "\n" |
5225 | | "Return the current process id."); |
5226 | | |
5227 | | #define OS_GETPID_METHODDEF \ |
5228 | | {"getpid", (PyCFunction)os_getpid, METH_NOARGS, os_getpid__doc__}, |
5229 | | |
5230 | | static PyObject * |
5231 | | os_getpid_impl(PyObject *module); |
5232 | | |
5233 | | static PyObject * |
5234 | | os_getpid(PyObject *module, PyObject *Py_UNUSED(ignored)) |
5235 | 0 | { |
5236 | 0 | return os_getpid_impl(module); |
5237 | 0 | } |
5238 | | |
5239 | | #endif /* defined(HAVE_GETPID) */ |
5240 | | |
5241 | | #if defined(HAVE_GETGROUPLIST) && defined(__APPLE__) |
5242 | | |
5243 | | PyDoc_STRVAR(os_getgrouplist__doc__, |
5244 | | "getgrouplist($module, user, group, /)\n" |
5245 | | "--\n" |
5246 | | "\n" |
5247 | | "Returns a list of groups to which a user belongs.\n" |
5248 | | "\n" |
5249 | | " user\n" |
5250 | | " username to lookup\n" |
5251 | | " group\n" |
5252 | | " base group id of the user"); |
5253 | | |
5254 | | #define OS_GETGROUPLIST_METHODDEF \ |
5255 | | {"getgrouplist", _PyCFunction_CAST(os_getgrouplist), METH_FASTCALL, os_getgrouplist__doc__}, |
5256 | | |
5257 | | static PyObject * |
5258 | | os_getgrouplist_impl(PyObject *module, const char *user, int basegid); |
5259 | | |
5260 | | static PyObject * |
5261 | | os_getgrouplist(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
5262 | | { |
5263 | | PyObject *return_value = NULL; |
5264 | | const char *user; |
5265 | | int basegid; |
5266 | | |
5267 | | if (!_PyArg_CheckPositional("getgrouplist", nargs, 2, 2)) { |
5268 | | goto exit; |
5269 | | } |
5270 | | if (!PyUnicode_Check(args[0])) { |
5271 | | _PyArg_BadArgument("getgrouplist", "argument 1", "str", args[0]); |
5272 | | goto exit; |
5273 | | } |
5274 | | Py_ssize_t user_length; |
5275 | | user = PyUnicode_AsUTF8AndSize(args[0], &user_length); |
5276 | | if (user == NULL) { |
5277 | | goto exit; |
5278 | | } |
5279 | | if (strlen(user) != (size_t)user_length) { |
5280 | | PyErr_SetString(PyExc_ValueError, "embedded null character"); |
5281 | | goto exit; |
5282 | | } |
5283 | | basegid = PyLong_AsInt(args[1]); |
5284 | | if (basegid == -1 && PyErr_Occurred()) { |
5285 | | goto exit; |
5286 | | } |
5287 | | return_value = os_getgrouplist_impl(module, user, basegid); |
5288 | | |
5289 | | exit: |
5290 | | return return_value; |
5291 | | } |
5292 | | |
5293 | | #endif /* defined(HAVE_GETGROUPLIST) && defined(__APPLE__) */ |
5294 | | |
5295 | | #if defined(HAVE_GETGROUPLIST) && !defined(__APPLE__) |
5296 | | |
5297 | | PyDoc_STRVAR(os_getgrouplist__doc__, |
5298 | | "getgrouplist($module, user, group, /)\n" |
5299 | | "--\n" |
5300 | | "\n" |
5301 | | "Returns a list of groups to which a user belongs.\n" |
5302 | | "\n" |
5303 | | " user\n" |
5304 | | " username to lookup\n" |
5305 | | " group\n" |
5306 | | " base group id of the user"); |
5307 | | |
5308 | | #define OS_GETGROUPLIST_METHODDEF \ |
5309 | | {"getgrouplist", _PyCFunction_CAST(os_getgrouplist), METH_FASTCALL, os_getgrouplist__doc__}, |
5310 | | |
5311 | | static PyObject * |
5312 | | os_getgrouplist_impl(PyObject *module, const char *user, gid_t basegid); |
5313 | | |
5314 | | static PyObject * |
5315 | | os_getgrouplist(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
5316 | 0 | { |
5317 | 0 | PyObject *return_value = NULL; |
5318 | 0 | const char *user; |
5319 | 0 | gid_t basegid; |
5320 | |
|
5321 | 0 | if (!_PyArg_CheckPositional("getgrouplist", nargs, 2, 2)) { |
5322 | 0 | goto exit; |
5323 | 0 | } |
5324 | 0 | if (!PyUnicode_Check(args[0])) { |
5325 | 0 | _PyArg_BadArgument("getgrouplist", "argument 1", "str", args[0]); |
5326 | 0 | goto exit; |
5327 | 0 | } |
5328 | 0 | Py_ssize_t user_length; |
5329 | 0 | user = PyUnicode_AsUTF8AndSize(args[0], &user_length); |
5330 | 0 | if (user == NULL) { |
5331 | 0 | goto exit; |
5332 | 0 | } |
5333 | 0 | if (strlen(user) != (size_t)user_length) { |
5334 | 0 | PyErr_SetString(PyExc_ValueError, "embedded null character"); |
5335 | 0 | goto exit; |
5336 | 0 | } |
5337 | 0 | if (!_Py_Gid_Converter(args[1], &basegid)) { |
5338 | 0 | goto exit; |
5339 | 0 | } |
5340 | 0 | return_value = os_getgrouplist_impl(module, user, basegid); |
5341 | |
|
5342 | 0 | exit: |
5343 | 0 | return return_value; |
5344 | 0 | } |
5345 | | |
5346 | | #endif /* defined(HAVE_GETGROUPLIST) && !defined(__APPLE__) */ |
5347 | | |
5348 | | #if defined(HAVE_GETGROUPS) |
5349 | | |
5350 | | PyDoc_STRVAR(os_getgroups__doc__, |
5351 | | "getgroups($module, /)\n" |
5352 | | "--\n" |
5353 | | "\n" |
5354 | | "Return list of supplemental group IDs for the process."); |
5355 | | |
5356 | | #define OS_GETGROUPS_METHODDEF \ |
5357 | | {"getgroups", (PyCFunction)os_getgroups, METH_NOARGS, os_getgroups__doc__}, |
5358 | | |
5359 | | static PyObject * |
5360 | | os_getgroups_impl(PyObject *module); |
5361 | | |
5362 | | static PyObject * |
5363 | | os_getgroups(PyObject *module, PyObject *Py_UNUSED(ignored)) |
5364 | 0 | { |
5365 | 0 | return os_getgroups_impl(module); |
5366 | 0 | } |
5367 | | |
5368 | | #endif /* defined(HAVE_GETGROUPS) */ |
5369 | | |
5370 | | #if defined(HAVE_INITGROUPS) && defined(__APPLE__) |
5371 | | |
5372 | | PyDoc_STRVAR(os_initgroups__doc__, |
5373 | | "initgroups($module, username, gid, /)\n" |
5374 | | "--\n" |
5375 | | "\n" |
5376 | | "Initialize the group access list.\n" |
5377 | | "\n" |
5378 | | "Call the system initgroups() to initialize the group access list with all of\n" |
5379 | | "the groups of which the specified username is a member, plus the specified\n" |
5380 | | "group id."); |
5381 | | |
5382 | | #define OS_INITGROUPS_METHODDEF \ |
5383 | | {"initgroups", _PyCFunction_CAST(os_initgroups), METH_FASTCALL, os_initgroups__doc__}, |
5384 | | |
5385 | | static PyObject * |
5386 | | os_initgroups_impl(PyObject *module, PyObject *oname, int gid); |
5387 | | |
5388 | | static PyObject * |
5389 | | os_initgroups(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
5390 | | { |
5391 | | PyObject *return_value = NULL; |
5392 | | PyObject *oname = NULL; |
5393 | | int gid; |
5394 | | |
5395 | | if (!_PyArg_CheckPositional("initgroups", nargs, 2, 2)) { |
5396 | | goto exit; |
5397 | | } |
5398 | | if (!PyUnicode_FSConverter(args[0], &oname)) { |
5399 | | goto exit; |
5400 | | } |
5401 | | gid = PyLong_AsInt(args[1]); |
5402 | | if (gid == -1 && PyErr_Occurred()) { |
5403 | | goto exit; |
5404 | | } |
5405 | | return_value = os_initgroups_impl(module, oname, gid); |
5406 | | |
5407 | | exit: |
5408 | | /* Cleanup for oname */ |
5409 | | Py_XDECREF(oname); |
5410 | | |
5411 | | return return_value; |
5412 | | } |
5413 | | |
5414 | | #endif /* defined(HAVE_INITGROUPS) && defined(__APPLE__) */ |
5415 | | |
5416 | | #if defined(HAVE_INITGROUPS) && !defined(__APPLE__) |
5417 | | |
5418 | | PyDoc_STRVAR(os_initgroups__doc__, |
5419 | | "initgroups($module, username, gid, /)\n" |
5420 | | "--\n" |
5421 | | "\n" |
5422 | | "Initialize the group access list.\n" |
5423 | | "\n" |
5424 | | "Call the system initgroups() to initialize the group access list with all of\n" |
5425 | | "the groups of which the specified username is a member, plus the specified\n" |
5426 | | "group id."); |
5427 | | |
5428 | | #define OS_INITGROUPS_METHODDEF \ |
5429 | | {"initgroups", _PyCFunction_CAST(os_initgroups), METH_FASTCALL, os_initgroups__doc__}, |
5430 | | |
5431 | | static PyObject * |
5432 | | os_initgroups_impl(PyObject *module, PyObject *oname, gid_t gid); |
5433 | | |
5434 | | static PyObject * |
5435 | | os_initgroups(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
5436 | 0 | { |
5437 | 0 | PyObject *return_value = NULL; |
5438 | 0 | PyObject *oname = NULL; |
5439 | 0 | gid_t gid; |
5440 | |
|
5441 | 0 | if (!_PyArg_CheckPositional("initgroups", nargs, 2, 2)) { |
5442 | 0 | goto exit; |
5443 | 0 | } |
5444 | 0 | if (!PyUnicode_FSConverter(args[0], &oname)) { |
5445 | 0 | goto exit; |
5446 | 0 | } |
5447 | 0 | if (!_Py_Gid_Converter(args[1], &gid)) { |
5448 | 0 | goto exit; |
5449 | 0 | } |
5450 | 0 | return_value = os_initgroups_impl(module, oname, gid); |
5451 | |
|
5452 | 0 | exit: |
5453 | | /* Cleanup for oname */ |
5454 | 0 | Py_XDECREF(oname); |
5455 | |
|
5456 | 0 | return return_value; |
5457 | 0 | } |
5458 | | |
5459 | | #endif /* defined(HAVE_INITGROUPS) && !defined(__APPLE__) */ |
5460 | | |
5461 | | #if defined(HAVE_GETPGID) |
5462 | | |
5463 | | PyDoc_STRVAR(os_getpgid__doc__, |
5464 | | "getpgid($module, /, pid)\n" |
5465 | | "--\n" |
5466 | | "\n" |
5467 | | "Call the system call getpgid(), and return the result."); |
5468 | | |
5469 | | #define OS_GETPGID_METHODDEF \ |
5470 | | {"getpgid", _PyCFunction_CAST(os_getpgid), METH_FASTCALL|METH_KEYWORDS, os_getpgid__doc__}, |
5471 | | |
5472 | | static PyObject * |
5473 | | os_getpgid_impl(PyObject *module, pid_t pid); |
5474 | | |
5475 | | static PyObject * |
5476 | | os_getpgid(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
5477 | 0 | { |
5478 | 0 | PyObject *return_value = NULL; |
5479 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
5480 | |
|
5481 | 0 | #define NUM_KEYWORDS 1 |
5482 | 0 | static struct { |
5483 | 0 | PyGC_Head _this_is_not_used; |
5484 | 0 | PyObject_VAR_HEAD |
5485 | 0 | Py_hash_t ob_hash; |
5486 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
5487 | 0 | } _kwtuple = { |
5488 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
5489 | 0 | .ob_hash = -1, |
5490 | 0 | .ob_item = { &_Py_ID(pid), }, |
5491 | 0 | }; |
5492 | 0 | #undef NUM_KEYWORDS |
5493 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
5494 | |
|
5495 | | #else // !Py_BUILD_CORE |
5496 | | # define KWTUPLE NULL |
5497 | | #endif // !Py_BUILD_CORE |
5498 | |
|
5499 | 0 | static const char * const _keywords[] = {"pid", NULL}; |
5500 | 0 | static _PyArg_Parser _parser = { |
5501 | 0 | .keywords = _keywords, |
5502 | 0 | .fname = "getpgid", |
5503 | 0 | .kwtuple = KWTUPLE, |
5504 | 0 | }; |
5505 | 0 | #undef KWTUPLE |
5506 | 0 | PyObject *argsbuf[1]; |
5507 | 0 | pid_t pid; |
5508 | |
|
5509 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
5510 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
5511 | 0 | if (!args) { |
5512 | 0 | goto exit; |
5513 | 0 | } |
5514 | 0 | pid = PyLong_AsPid(args[0]); |
5515 | 0 | if (pid == (pid_t)(-1) && PyErr_Occurred()) { |
5516 | 0 | goto exit; |
5517 | 0 | } |
5518 | 0 | return_value = os_getpgid_impl(module, pid); |
5519 | |
|
5520 | 0 | exit: |
5521 | 0 | return return_value; |
5522 | 0 | } |
5523 | | |
5524 | | #endif /* defined(HAVE_GETPGID) */ |
5525 | | |
5526 | | #if defined(HAVE_GETPGRP) |
5527 | | |
5528 | | PyDoc_STRVAR(os_getpgrp__doc__, |
5529 | | "getpgrp($module, /)\n" |
5530 | | "--\n" |
5531 | | "\n" |
5532 | | "Return the current process group id."); |
5533 | | |
5534 | | #define OS_GETPGRP_METHODDEF \ |
5535 | | {"getpgrp", (PyCFunction)os_getpgrp, METH_NOARGS, os_getpgrp__doc__}, |
5536 | | |
5537 | | static PyObject * |
5538 | | os_getpgrp_impl(PyObject *module); |
5539 | | |
5540 | | static PyObject * |
5541 | | os_getpgrp(PyObject *module, PyObject *Py_UNUSED(ignored)) |
5542 | 0 | { |
5543 | 0 | return os_getpgrp_impl(module); |
5544 | 0 | } |
5545 | | |
5546 | | #endif /* defined(HAVE_GETPGRP) */ |
5547 | | |
5548 | | #if defined(HAVE_SETPGRP) |
5549 | | |
5550 | | PyDoc_STRVAR(os_setpgrp__doc__, |
5551 | | "setpgrp($module, /)\n" |
5552 | | "--\n" |
5553 | | "\n" |
5554 | | "Make the current process the leader of its process group."); |
5555 | | |
5556 | | #define OS_SETPGRP_METHODDEF \ |
5557 | | {"setpgrp", (PyCFunction)os_setpgrp, METH_NOARGS, os_setpgrp__doc__}, |
5558 | | |
5559 | | static PyObject * |
5560 | | os_setpgrp_impl(PyObject *module); |
5561 | | |
5562 | | static PyObject * |
5563 | | os_setpgrp(PyObject *module, PyObject *Py_UNUSED(ignored)) |
5564 | 0 | { |
5565 | 0 | return os_setpgrp_impl(module); |
5566 | 0 | } |
5567 | | |
5568 | | #endif /* defined(HAVE_SETPGRP) */ |
5569 | | |
5570 | | #if defined(HAVE_GETPPID) |
5571 | | |
5572 | | PyDoc_STRVAR(os_getppid__doc__, |
5573 | | "getppid($module, /)\n" |
5574 | | "--\n" |
5575 | | "\n" |
5576 | | "Return the parent\'s process id.\n" |
5577 | | "\n" |
5578 | | "If the parent process has already exited, Windows machines will still\n" |
5579 | | "return its id; others systems will return the id of the \'init\' process (1)."); |
5580 | | |
5581 | | #define OS_GETPPID_METHODDEF \ |
5582 | | {"getppid", (PyCFunction)os_getppid, METH_NOARGS, os_getppid__doc__}, |
5583 | | |
5584 | | static PyObject * |
5585 | | os_getppid_impl(PyObject *module); |
5586 | | |
5587 | | static PyObject * |
5588 | | os_getppid(PyObject *module, PyObject *Py_UNUSED(ignored)) |
5589 | 0 | { |
5590 | 0 | return os_getppid_impl(module); |
5591 | 0 | } |
5592 | | |
5593 | | #endif /* defined(HAVE_GETPPID) */ |
5594 | | |
5595 | | #if defined(HAVE_GETLOGIN) |
5596 | | |
5597 | | PyDoc_STRVAR(os_getlogin__doc__, |
5598 | | "getlogin($module, /)\n" |
5599 | | "--\n" |
5600 | | "\n" |
5601 | | "Return the actual login name."); |
5602 | | |
5603 | | #define OS_GETLOGIN_METHODDEF \ |
5604 | | {"getlogin", (PyCFunction)os_getlogin, METH_NOARGS, os_getlogin__doc__}, |
5605 | | |
5606 | | static PyObject * |
5607 | | os_getlogin_impl(PyObject *module); |
5608 | | |
5609 | | static PyObject * |
5610 | | os_getlogin(PyObject *module, PyObject *Py_UNUSED(ignored)) |
5611 | 0 | { |
5612 | 0 | return os_getlogin_impl(module); |
5613 | 0 | } |
5614 | | |
5615 | | #endif /* defined(HAVE_GETLOGIN) */ |
5616 | | |
5617 | | #if defined(HAVE_GETUID) |
5618 | | |
5619 | | PyDoc_STRVAR(os_getuid__doc__, |
5620 | | "getuid($module, /)\n" |
5621 | | "--\n" |
5622 | | "\n" |
5623 | | "Return the current process\'s user id."); |
5624 | | |
5625 | | #define OS_GETUID_METHODDEF \ |
5626 | | {"getuid", (PyCFunction)os_getuid, METH_NOARGS, os_getuid__doc__}, |
5627 | | |
5628 | | static PyObject * |
5629 | | os_getuid_impl(PyObject *module); |
5630 | | |
5631 | | static PyObject * |
5632 | | os_getuid(PyObject *module, PyObject *Py_UNUSED(ignored)) |
5633 | 16 | { |
5634 | 16 | return os_getuid_impl(module); |
5635 | 16 | } |
5636 | | |
5637 | | #endif /* defined(HAVE_GETUID) */ |
5638 | | |
5639 | | #if defined(HAVE_KILL) |
5640 | | |
5641 | | PyDoc_STRVAR(os_kill__doc__, |
5642 | | "kill($module, pid, signal, /)\n" |
5643 | | "--\n" |
5644 | | "\n" |
5645 | | "Kill a process with a signal."); |
5646 | | |
5647 | | #define OS_KILL_METHODDEF \ |
5648 | | {"kill", _PyCFunction_CAST(os_kill), METH_FASTCALL, os_kill__doc__}, |
5649 | | |
5650 | | static PyObject * |
5651 | | os_kill_impl(PyObject *module, pid_t pid, Py_ssize_t signal); |
5652 | | |
5653 | | static PyObject * |
5654 | | os_kill(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
5655 | 0 | { |
5656 | 0 | PyObject *return_value = NULL; |
5657 | 0 | pid_t pid; |
5658 | 0 | Py_ssize_t signal; |
5659 | |
|
5660 | 0 | if (!_PyArg_CheckPositional("kill", nargs, 2, 2)) { |
5661 | 0 | goto exit; |
5662 | 0 | } |
5663 | 0 | pid = PyLong_AsPid(args[0]); |
5664 | 0 | if (pid == (pid_t)(-1) && PyErr_Occurred()) { |
5665 | 0 | goto exit; |
5666 | 0 | } |
5667 | 0 | { |
5668 | 0 | Py_ssize_t ival = -1; |
5669 | 0 | PyObject *iobj = _PyNumber_Index(args[1]); |
5670 | 0 | if (iobj != NULL) { |
5671 | 0 | ival = PyLong_AsSsize_t(iobj); |
5672 | 0 | Py_DECREF(iobj); |
5673 | 0 | } |
5674 | 0 | if (ival == -1 && PyErr_Occurred()) { |
5675 | 0 | goto exit; |
5676 | 0 | } |
5677 | 0 | signal = ival; |
5678 | 0 | } |
5679 | 0 | return_value = os_kill_impl(module, pid, signal); |
5680 | |
|
5681 | 0 | exit: |
5682 | 0 | return return_value; |
5683 | 0 | } |
5684 | | |
5685 | | #endif /* defined(HAVE_KILL) */ |
5686 | | |
5687 | | #if defined(HAVE_KILLPG) |
5688 | | |
5689 | | PyDoc_STRVAR(os_killpg__doc__, |
5690 | | "killpg($module, pgid, signal, /)\n" |
5691 | | "--\n" |
5692 | | "\n" |
5693 | | "Kill a process group with a signal."); |
5694 | | |
5695 | | #define OS_KILLPG_METHODDEF \ |
5696 | | {"killpg", _PyCFunction_CAST(os_killpg), METH_FASTCALL, os_killpg__doc__}, |
5697 | | |
5698 | | static PyObject * |
5699 | | os_killpg_impl(PyObject *module, pid_t pgid, int signal); |
5700 | | |
5701 | | static PyObject * |
5702 | | os_killpg(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
5703 | 0 | { |
5704 | 0 | PyObject *return_value = NULL; |
5705 | 0 | pid_t pgid; |
5706 | 0 | int signal; |
5707 | |
|
5708 | 0 | if (!_PyArg_CheckPositional("killpg", nargs, 2, 2)) { |
5709 | 0 | goto exit; |
5710 | 0 | } |
5711 | 0 | pgid = PyLong_AsPid(args[0]); |
5712 | 0 | if (pgid == (pid_t)(-1) && PyErr_Occurred()) { |
5713 | 0 | goto exit; |
5714 | 0 | } |
5715 | 0 | signal = PyLong_AsInt(args[1]); |
5716 | 0 | if (signal == -1 && PyErr_Occurred()) { |
5717 | 0 | goto exit; |
5718 | 0 | } |
5719 | 0 | return_value = os_killpg_impl(module, pgid, signal); |
5720 | |
|
5721 | 0 | exit: |
5722 | 0 | return return_value; |
5723 | 0 | } |
5724 | | |
5725 | | #endif /* defined(HAVE_KILLPG) */ |
5726 | | |
5727 | | #if defined(HAVE_PLOCK) |
5728 | | |
5729 | | PyDoc_STRVAR(os_plock__doc__, |
5730 | | "plock($module, op, /)\n" |
5731 | | "--\n" |
5732 | | "\n" |
5733 | | "Lock program segments into memory.\");"); |
5734 | | |
5735 | | #define OS_PLOCK_METHODDEF \ |
5736 | | {"plock", (PyCFunction)os_plock, METH_O, os_plock__doc__}, |
5737 | | |
5738 | | static PyObject * |
5739 | | os_plock_impl(PyObject *module, int op); |
5740 | | |
5741 | | static PyObject * |
5742 | | os_plock(PyObject *module, PyObject *arg) |
5743 | | { |
5744 | | PyObject *return_value = NULL; |
5745 | | int op; |
5746 | | |
5747 | | op = PyLong_AsInt(arg); |
5748 | | if (op == -1 && PyErr_Occurred()) { |
5749 | | goto exit; |
5750 | | } |
5751 | | return_value = os_plock_impl(module, op); |
5752 | | |
5753 | | exit: |
5754 | | return return_value; |
5755 | | } |
5756 | | |
5757 | | #endif /* defined(HAVE_PLOCK) */ |
5758 | | |
5759 | | #if defined(HAVE_SETUID) |
5760 | | |
5761 | | PyDoc_STRVAR(os_setuid__doc__, |
5762 | | "setuid($module, uid, /)\n" |
5763 | | "--\n" |
5764 | | "\n" |
5765 | | "Set the current process\'s user id."); |
5766 | | |
5767 | | #define OS_SETUID_METHODDEF \ |
5768 | | {"setuid", (PyCFunction)os_setuid, METH_O, os_setuid__doc__}, |
5769 | | |
5770 | | static PyObject * |
5771 | | os_setuid_impl(PyObject *module, uid_t uid); |
5772 | | |
5773 | | static PyObject * |
5774 | | os_setuid(PyObject *module, PyObject *arg) |
5775 | 0 | { |
5776 | 0 | PyObject *return_value = NULL; |
5777 | 0 | uid_t uid; |
5778 | |
|
5779 | 0 | if (!_Py_Uid_Converter(arg, &uid)) { |
5780 | 0 | goto exit; |
5781 | 0 | } |
5782 | 0 | return_value = os_setuid_impl(module, uid); |
5783 | |
|
5784 | 0 | exit: |
5785 | 0 | return return_value; |
5786 | 0 | } |
5787 | | |
5788 | | #endif /* defined(HAVE_SETUID) */ |
5789 | | |
5790 | | #if defined(HAVE_SETEUID) |
5791 | | |
5792 | | PyDoc_STRVAR(os_seteuid__doc__, |
5793 | | "seteuid($module, euid, /)\n" |
5794 | | "--\n" |
5795 | | "\n" |
5796 | | "Set the current process\'s effective user id."); |
5797 | | |
5798 | | #define OS_SETEUID_METHODDEF \ |
5799 | | {"seteuid", (PyCFunction)os_seteuid, METH_O, os_seteuid__doc__}, |
5800 | | |
5801 | | static PyObject * |
5802 | | os_seteuid_impl(PyObject *module, uid_t euid); |
5803 | | |
5804 | | static PyObject * |
5805 | | os_seteuid(PyObject *module, PyObject *arg) |
5806 | 0 | { |
5807 | 0 | PyObject *return_value = NULL; |
5808 | 0 | uid_t euid; |
5809 | |
|
5810 | 0 | if (!_Py_Uid_Converter(arg, &euid)) { |
5811 | 0 | goto exit; |
5812 | 0 | } |
5813 | 0 | return_value = os_seteuid_impl(module, euid); |
5814 | |
|
5815 | 0 | exit: |
5816 | 0 | return return_value; |
5817 | 0 | } |
5818 | | |
5819 | | #endif /* defined(HAVE_SETEUID) */ |
5820 | | |
5821 | | #if defined(HAVE_SETEGID) |
5822 | | |
5823 | | PyDoc_STRVAR(os_setegid__doc__, |
5824 | | "setegid($module, egid, /)\n" |
5825 | | "--\n" |
5826 | | "\n" |
5827 | | "Set the current process\'s effective group id."); |
5828 | | |
5829 | | #define OS_SETEGID_METHODDEF \ |
5830 | | {"setegid", (PyCFunction)os_setegid, METH_O, os_setegid__doc__}, |
5831 | | |
5832 | | static PyObject * |
5833 | | os_setegid_impl(PyObject *module, gid_t egid); |
5834 | | |
5835 | | static PyObject * |
5836 | | os_setegid(PyObject *module, PyObject *arg) |
5837 | 0 | { |
5838 | 0 | PyObject *return_value = NULL; |
5839 | 0 | gid_t egid; |
5840 | |
|
5841 | 0 | if (!_Py_Gid_Converter(arg, &egid)) { |
5842 | 0 | goto exit; |
5843 | 0 | } |
5844 | 0 | return_value = os_setegid_impl(module, egid); |
5845 | |
|
5846 | 0 | exit: |
5847 | 0 | return return_value; |
5848 | 0 | } |
5849 | | |
5850 | | #endif /* defined(HAVE_SETEGID) */ |
5851 | | |
5852 | | #if defined(HAVE_SETREUID) |
5853 | | |
5854 | | PyDoc_STRVAR(os_setreuid__doc__, |
5855 | | "setreuid($module, ruid, euid, /)\n" |
5856 | | "--\n" |
5857 | | "\n" |
5858 | | "Set the current process\'s real and effective user ids."); |
5859 | | |
5860 | | #define OS_SETREUID_METHODDEF \ |
5861 | | {"setreuid", _PyCFunction_CAST(os_setreuid), METH_FASTCALL, os_setreuid__doc__}, |
5862 | | |
5863 | | static PyObject * |
5864 | | os_setreuid_impl(PyObject *module, uid_t ruid, uid_t euid); |
5865 | | |
5866 | | static PyObject * |
5867 | | os_setreuid(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
5868 | 0 | { |
5869 | 0 | PyObject *return_value = NULL; |
5870 | 0 | uid_t ruid; |
5871 | 0 | uid_t euid; |
5872 | |
|
5873 | 0 | if (!_PyArg_CheckPositional("setreuid", nargs, 2, 2)) { |
5874 | 0 | goto exit; |
5875 | 0 | } |
5876 | 0 | if (!_Py_Uid_Converter(args[0], &ruid)) { |
5877 | 0 | goto exit; |
5878 | 0 | } |
5879 | 0 | if (!_Py_Uid_Converter(args[1], &euid)) { |
5880 | 0 | goto exit; |
5881 | 0 | } |
5882 | 0 | return_value = os_setreuid_impl(module, ruid, euid); |
5883 | |
|
5884 | 0 | exit: |
5885 | 0 | return return_value; |
5886 | 0 | } |
5887 | | |
5888 | | #endif /* defined(HAVE_SETREUID) */ |
5889 | | |
5890 | | #if defined(HAVE_SETREGID) |
5891 | | |
5892 | | PyDoc_STRVAR(os_setregid__doc__, |
5893 | | "setregid($module, rgid, egid, /)\n" |
5894 | | "--\n" |
5895 | | "\n" |
5896 | | "Set the current process\'s real and effective group ids."); |
5897 | | |
5898 | | #define OS_SETREGID_METHODDEF \ |
5899 | | {"setregid", _PyCFunction_CAST(os_setregid), METH_FASTCALL, os_setregid__doc__}, |
5900 | | |
5901 | | static PyObject * |
5902 | | os_setregid_impl(PyObject *module, gid_t rgid, gid_t egid); |
5903 | | |
5904 | | static PyObject * |
5905 | | os_setregid(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
5906 | 0 | { |
5907 | 0 | PyObject *return_value = NULL; |
5908 | 0 | gid_t rgid; |
5909 | 0 | gid_t egid; |
5910 | |
|
5911 | 0 | if (!_PyArg_CheckPositional("setregid", nargs, 2, 2)) { |
5912 | 0 | goto exit; |
5913 | 0 | } |
5914 | 0 | if (!_Py_Gid_Converter(args[0], &rgid)) { |
5915 | 0 | goto exit; |
5916 | 0 | } |
5917 | 0 | if (!_Py_Gid_Converter(args[1], &egid)) { |
5918 | 0 | goto exit; |
5919 | 0 | } |
5920 | 0 | return_value = os_setregid_impl(module, rgid, egid); |
5921 | |
|
5922 | 0 | exit: |
5923 | 0 | return return_value; |
5924 | 0 | } |
5925 | | |
5926 | | #endif /* defined(HAVE_SETREGID) */ |
5927 | | |
5928 | | #if defined(HAVE_SETGID) |
5929 | | |
5930 | | PyDoc_STRVAR(os_setgid__doc__, |
5931 | | "setgid($module, gid, /)\n" |
5932 | | "--\n" |
5933 | | "\n" |
5934 | | "Set the current process\'s group id."); |
5935 | | |
5936 | | #define OS_SETGID_METHODDEF \ |
5937 | | {"setgid", (PyCFunction)os_setgid, METH_O, os_setgid__doc__}, |
5938 | | |
5939 | | static PyObject * |
5940 | | os_setgid_impl(PyObject *module, gid_t gid); |
5941 | | |
5942 | | static PyObject * |
5943 | | os_setgid(PyObject *module, PyObject *arg) |
5944 | 0 | { |
5945 | 0 | PyObject *return_value = NULL; |
5946 | 0 | gid_t gid; |
5947 | |
|
5948 | 0 | if (!_Py_Gid_Converter(arg, &gid)) { |
5949 | 0 | goto exit; |
5950 | 0 | } |
5951 | 0 | return_value = os_setgid_impl(module, gid); |
5952 | |
|
5953 | 0 | exit: |
5954 | 0 | return return_value; |
5955 | 0 | } |
5956 | | |
5957 | | #endif /* defined(HAVE_SETGID) */ |
5958 | | |
5959 | | #if defined(HAVE_SETGROUPS) |
5960 | | |
5961 | | PyDoc_STRVAR(os_setgroups__doc__, |
5962 | | "setgroups($module, groups, /)\n" |
5963 | | "--\n" |
5964 | | "\n" |
5965 | | "Set the groups of the current process to list."); |
5966 | | |
5967 | | #define OS_SETGROUPS_METHODDEF \ |
5968 | | {"setgroups", (PyCFunction)os_setgroups, METH_O, os_setgroups__doc__}, |
5969 | | |
5970 | | #endif /* defined(HAVE_SETGROUPS) */ |
5971 | | |
5972 | | #if defined(HAVE_WAIT3) |
5973 | | |
5974 | | PyDoc_STRVAR(os_wait3__doc__, |
5975 | | "wait3($module, /, options)\n" |
5976 | | "--\n" |
5977 | | "\n" |
5978 | | "Wait for completion of a child process.\n" |
5979 | | "\n" |
5980 | | "Returns a tuple of information about the child process:\n" |
5981 | | " (pid, status, rusage)"); |
5982 | | |
5983 | | #define OS_WAIT3_METHODDEF \ |
5984 | | {"wait3", _PyCFunction_CAST(os_wait3), METH_FASTCALL|METH_KEYWORDS, os_wait3__doc__}, |
5985 | | |
5986 | | static PyObject * |
5987 | | os_wait3_impl(PyObject *module, int options); |
5988 | | |
5989 | | static PyObject * |
5990 | | os_wait3(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
5991 | 0 | { |
5992 | 0 | PyObject *return_value = NULL; |
5993 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
5994 | |
|
5995 | 0 | #define NUM_KEYWORDS 1 |
5996 | 0 | static struct { |
5997 | 0 | PyGC_Head _this_is_not_used; |
5998 | 0 | PyObject_VAR_HEAD |
5999 | 0 | Py_hash_t ob_hash; |
6000 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
6001 | 0 | } _kwtuple = { |
6002 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
6003 | 0 | .ob_hash = -1, |
6004 | 0 | .ob_item = { &_Py_ID(options), }, |
6005 | 0 | }; |
6006 | 0 | #undef NUM_KEYWORDS |
6007 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
6008 | |
|
6009 | | #else // !Py_BUILD_CORE |
6010 | | # define KWTUPLE NULL |
6011 | | #endif // !Py_BUILD_CORE |
6012 | |
|
6013 | 0 | static const char * const _keywords[] = {"options", NULL}; |
6014 | 0 | static _PyArg_Parser _parser = { |
6015 | 0 | .keywords = _keywords, |
6016 | 0 | .fname = "wait3", |
6017 | 0 | .kwtuple = KWTUPLE, |
6018 | 0 | }; |
6019 | 0 | #undef KWTUPLE |
6020 | 0 | PyObject *argsbuf[1]; |
6021 | 0 | int options; |
6022 | |
|
6023 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
6024 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
6025 | 0 | if (!args) { |
6026 | 0 | goto exit; |
6027 | 0 | } |
6028 | 0 | options = PyLong_AsInt(args[0]); |
6029 | 0 | if (options == -1 && PyErr_Occurred()) { |
6030 | 0 | goto exit; |
6031 | 0 | } |
6032 | 0 | return_value = os_wait3_impl(module, options); |
6033 | |
|
6034 | 0 | exit: |
6035 | 0 | return return_value; |
6036 | 0 | } |
6037 | | |
6038 | | #endif /* defined(HAVE_WAIT3) */ |
6039 | | |
6040 | | #if defined(HAVE_WAIT4) |
6041 | | |
6042 | | PyDoc_STRVAR(os_wait4__doc__, |
6043 | | "wait4($module, /, pid, options)\n" |
6044 | | "--\n" |
6045 | | "\n" |
6046 | | "Wait for completion of a specific child process.\n" |
6047 | | "\n" |
6048 | | "Returns a tuple of information about the child process:\n" |
6049 | | " (pid, status, rusage)"); |
6050 | | |
6051 | | #define OS_WAIT4_METHODDEF \ |
6052 | | {"wait4", _PyCFunction_CAST(os_wait4), METH_FASTCALL|METH_KEYWORDS, os_wait4__doc__}, |
6053 | | |
6054 | | static PyObject * |
6055 | | os_wait4_impl(PyObject *module, pid_t pid, int options); |
6056 | | |
6057 | | static PyObject * |
6058 | | os_wait4(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
6059 | 0 | { |
6060 | 0 | PyObject *return_value = NULL; |
6061 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
6062 | |
|
6063 | 0 | #define NUM_KEYWORDS 2 |
6064 | 0 | static struct { |
6065 | 0 | PyGC_Head _this_is_not_used; |
6066 | 0 | PyObject_VAR_HEAD |
6067 | 0 | Py_hash_t ob_hash; |
6068 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
6069 | 0 | } _kwtuple = { |
6070 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
6071 | 0 | .ob_hash = -1, |
6072 | 0 | .ob_item = { &_Py_ID(pid), &_Py_ID(options), }, |
6073 | 0 | }; |
6074 | 0 | #undef NUM_KEYWORDS |
6075 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
6076 | |
|
6077 | | #else // !Py_BUILD_CORE |
6078 | | # define KWTUPLE NULL |
6079 | | #endif // !Py_BUILD_CORE |
6080 | |
|
6081 | 0 | static const char * const _keywords[] = {"pid", "options", NULL}; |
6082 | 0 | static _PyArg_Parser _parser = { |
6083 | 0 | .keywords = _keywords, |
6084 | 0 | .fname = "wait4", |
6085 | 0 | .kwtuple = KWTUPLE, |
6086 | 0 | }; |
6087 | 0 | #undef KWTUPLE |
6088 | 0 | PyObject *argsbuf[2]; |
6089 | 0 | pid_t pid; |
6090 | 0 | int options; |
6091 | |
|
6092 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
6093 | 0 | /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
6094 | 0 | if (!args) { |
6095 | 0 | goto exit; |
6096 | 0 | } |
6097 | 0 | pid = PyLong_AsPid(args[0]); |
6098 | 0 | if (pid == (pid_t)(-1) && PyErr_Occurred()) { |
6099 | 0 | goto exit; |
6100 | 0 | } |
6101 | 0 | options = PyLong_AsInt(args[1]); |
6102 | 0 | if (options == -1 && PyErr_Occurred()) { |
6103 | 0 | goto exit; |
6104 | 0 | } |
6105 | 0 | return_value = os_wait4_impl(module, pid, options); |
6106 | |
|
6107 | 0 | exit: |
6108 | 0 | return return_value; |
6109 | 0 | } |
6110 | | |
6111 | | #endif /* defined(HAVE_WAIT4) */ |
6112 | | |
6113 | | #if defined(HAVE_WAITID) |
6114 | | |
6115 | | PyDoc_STRVAR(os_waitid__doc__, |
6116 | | "waitid($module, idtype, id, options, /)\n" |
6117 | | "--\n" |
6118 | | "\n" |
6119 | | "Returns the result of waiting for a process or processes.\n" |
6120 | | "\n" |
6121 | | " idtype\n" |
6122 | | " Must be one of be P_PID, P_PGID or P_ALL.\n" |
6123 | | " id\n" |
6124 | | " The id to wait on.\n" |
6125 | | " options\n" |
6126 | | " Constructed from the ORing of one or more of WEXITED, WSTOPPED\n" |
6127 | | " or WCONTINUED and additionally may be ORed with WNOHANG or WNOWAIT.\n" |
6128 | | "\n" |
6129 | | "Returns either waitid_result or None if WNOHANG is specified and there are\n" |
6130 | | "no children in a waitable state."); |
6131 | | |
6132 | | #define OS_WAITID_METHODDEF \ |
6133 | | {"waitid", _PyCFunction_CAST(os_waitid), METH_FASTCALL, os_waitid__doc__}, |
6134 | | |
6135 | | static PyObject * |
6136 | | os_waitid_impl(PyObject *module, idtype_t idtype, id_t id, int options); |
6137 | | |
6138 | | static PyObject * |
6139 | | os_waitid(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
6140 | 0 | { |
6141 | 0 | PyObject *return_value = NULL; |
6142 | 0 | idtype_t idtype; |
6143 | 0 | id_t id; |
6144 | 0 | int options; |
6145 | |
|
6146 | 0 | if (!_PyArg_CheckPositional("waitid", nargs, 3, 3)) { |
6147 | 0 | goto exit; |
6148 | 0 | } |
6149 | 0 | if (!idtype_t_converter(args[0], &idtype)) { |
6150 | 0 | goto exit; |
6151 | 0 | } |
6152 | 0 | id = (id_t)PyLong_AsPid(args[1]); |
6153 | 0 | if (id == (id_t)(-1) && PyErr_Occurred()) { |
6154 | 0 | goto exit; |
6155 | 0 | } |
6156 | 0 | options = PyLong_AsInt(args[2]); |
6157 | 0 | if (options == -1 && PyErr_Occurred()) { |
6158 | 0 | goto exit; |
6159 | 0 | } |
6160 | 0 | return_value = os_waitid_impl(module, idtype, id, options); |
6161 | |
|
6162 | 0 | exit: |
6163 | 0 | return return_value; |
6164 | 0 | } |
6165 | | |
6166 | | #endif /* defined(HAVE_WAITID) */ |
6167 | | |
6168 | | #if defined(HAVE_WAITPID) |
6169 | | |
6170 | | PyDoc_STRVAR(os_waitpid__doc__, |
6171 | | "waitpid($module, pid, options, /)\n" |
6172 | | "--\n" |
6173 | | "\n" |
6174 | | "Wait for completion of a given child process.\n" |
6175 | | "\n" |
6176 | | "Returns a tuple of information regarding the child process:\n" |
6177 | | " (pid, status)\n" |
6178 | | "\n" |
6179 | | "The options argument is ignored on Windows."); |
6180 | | |
6181 | | #define OS_WAITPID_METHODDEF \ |
6182 | | {"waitpid", _PyCFunction_CAST(os_waitpid), METH_FASTCALL, os_waitpid__doc__}, |
6183 | | |
6184 | | static PyObject * |
6185 | | os_waitpid_impl(PyObject *module, pid_t pid, int options); |
6186 | | |
6187 | | static PyObject * |
6188 | | os_waitpid(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
6189 | 0 | { |
6190 | 0 | PyObject *return_value = NULL; |
6191 | 0 | pid_t pid; |
6192 | 0 | int options; |
6193 | |
|
6194 | 0 | if (!_PyArg_CheckPositional("waitpid", nargs, 2, 2)) { |
6195 | 0 | goto exit; |
6196 | 0 | } |
6197 | 0 | pid = PyLong_AsPid(args[0]); |
6198 | 0 | if (pid == (pid_t)(-1) && PyErr_Occurred()) { |
6199 | 0 | goto exit; |
6200 | 0 | } |
6201 | 0 | options = PyLong_AsInt(args[1]); |
6202 | 0 | if (options == -1 && PyErr_Occurred()) { |
6203 | 0 | goto exit; |
6204 | 0 | } |
6205 | 0 | return_value = os_waitpid_impl(module, pid, options); |
6206 | |
|
6207 | 0 | exit: |
6208 | 0 | return return_value; |
6209 | 0 | } |
6210 | | |
6211 | | #endif /* defined(HAVE_WAITPID) */ |
6212 | | |
6213 | | #if !defined(HAVE_WAITPID) && defined(HAVE_CWAIT) |
6214 | | |
6215 | | PyDoc_STRVAR(os_waitpid__doc__, |
6216 | | "waitpid($module, pid, options, /)\n" |
6217 | | "--\n" |
6218 | | "\n" |
6219 | | "Wait for completion of a given process.\n" |
6220 | | "\n" |
6221 | | "Returns a tuple of information regarding the process:\n" |
6222 | | " (pid, status << 8)\n" |
6223 | | "\n" |
6224 | | "The options argument is ignored on Windows."); |
6225 | | |
6226 | | #define OS_WAITPID_METHODDEF \ |
6227 | | {"waitpid", _PyCFunction_CAST(os_waitpid), METH_FASTCALL, os_waitpid__doc__}, |
6228 | | |
6229 | | static PyObject * |
6230 | | os_waitpid_impl(PyObject *module, intptr_t pid, int options); |
6231 | | |
6232 | | static PyObject * |
6233 | | os_waitpid(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
6234 | | { |
6235 | | PyObject *return_value = NULL; |
6236 | | intptr_t pid; |
6237 | | int options; |
6238 | | |
6239 | | if (!_PyArg_CheckPositional("waitpid", nargs, 2, 2)) { |
6240 | | goto exit; |
6241 | | } |
6242 | | pid = (intptr_t)PyLong_AsVoidPtr(args[0]); |
6243 | | if (!pid && PyErr_Occurred()) { |
6244 | | goto exit; |
6245 | | } |
6246 | | options = PyLong_AsInt(args[1]); |
6247 | | if (options == -1 && PyErr_Occurred()) { |
6248 | | goto exit; |
6249 | | } |
6250 | | return_value = os_waitpid_impl(module, pid, options); |
6251 | | |
6252 | | exit: |
6253 | | return return_value; |
6254 | | } |
6255 | | |
6256 | | #endif /* !defined(HAVE_WAITPID) && defined(HAVE_CWAIT) */ |
6257 | | |
6258 | | #if defined(HAVE_WAIT) |
6259 | | |
6260 | | PyDoc_STRVAR(os_wait__doc__, |
6261 | | "wait($module, /)\n" |
6262 | | "--\n" |
6263 | | "\n" |
6264 | | "Wait for completion of a child process.\n" |
6265 | | "\n" |
6266 | | "Returns a tuple of information about the child process:\n" |
6267 | | " (pid, status)"); |
6268 | | |
6269 | | #define OS_WAIT_METHODDEF \ |
6270 | | {"wait", (PyCFunction)os_wait, METH_NOARGS, os_wait__doc__}, |
6271 | | |
6272 | | static PyObject * |
6273 | | os_wait_impl(PyObject *module); |
6274 | | |
6275 | | static PyObject * |
6276 | | os_wait(PyObject *module, PyObject *Py_UNUSED(ignored)) |
6277 | 0 | { |
6278 | 0 | return os_wait_impl(module); |
6279 | 0 | } |
6280 | | |
6281 | | #endif /* defined(HAVE_WAIT) */ |
6282 | | |
6283 | | #if (defined(__linux__) && defined(__NR_pidfd_open) && !(defined(__ANDROID__) && __ANDROID_API__ < 31)) |
6284 | | |
6285 | | PyDoc_STRVAR(os_pidfd_open__doc__, |
6286 | | "pidfd_open($module, /, pid, flags=0)\n" |
6287 | | "--\n" |
6288 | | "\n" |
6289 | | "Return a file descriptor referring to the process *pid*.\n" |
6290 | | "\n" |
6291 | | "The descriptor can be used to perform process management without races and\n" |
6292 | | "signals."); |
6293 | | |
6294 | | #define OS_PIDFD_OPEN_METHODDEF \ |
6295 | | {"pidfd_open", _PyCFunction_CAST(os_pidfd_open), METH_FASTCALL|METH_KEYWORDS, os_pidfd_open__doc__}, |
6296 | | |
6297 | | static PyObject * |
6298 | | os_pidfd_open_impl(PyObject *module, pid_t pid, unsigned int flags); |
6299 | | |
6300 | | static PyObject * |
6301 | | os_pidfd_open(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
6302 | 0 | { |
6303 | 0 | PyObject *return_value = NULL; |
6304 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
6305 | |
|
6306 | 0 | #define NUM_KEYWORDS 2 |
6307 | 0 | static struct { |
6308 | 0 | PyGC_Head _this_is_not_used; |
6309 | 0 | PyObject_VAR_HEAD |
6310 | 0 | Py_hash_t ob_hash; |
6311 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
6312 | 0 | } _kwtuple = { |
6313 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
6314 | 0 | .ob_hash = -1, |
6315 | 0 | .ob_item = { &_Py_ID(pid), &_Py_ID(flags), }, |
6316 | 0 | }; |
6317 | 0 | #undef NUM_KEYWORDS |
6318 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
6319 | |
|
6320 | | #else // !Py_BUILD_CORE |
6321 | | # define KWTUPLE NULL |
6322 | | #endif // !Py_BUILD_CORE |
6323 | |
|
6324 | 0 | static const char * const _keywords[] = {"pid", "flags", NULL}; |
6325 | 0 | static _PyArg_Parser _parser = { |
6326 | 0 | .keywords = _keywords, |
6327 | 0 | .fname = "pidfd_open", |
6328 | 0 | .kwtuple = KWTUPLE, |
6329 | 0 | }; |
6330 | 0 | #undef KWTUPLE |
6331 | 0 | PyObject *argsbuf[2]; |
6332 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
6333 | 0 | pid_t pid; |
6334 | 0 | unsigned int flags = 0; |
6335 | |
|
6336 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
6337 | 0 | /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
6338 | 0 | if (!args) { |
6339 | 0 | goto exit; |
6340 | 0 | } |
6341 | 0 | pid = PyLong_AsPid(args[0]); |
6342 | 0 | if (pid == (pid_t)(-1) && PyErr_Occurred()) { |
6343 | 0 | goto exit; |
6344 | 0 | } |
6345 | 0 | if (!noptargs) { |
6346 | 0 | goto skip_optional_pos; |
6347 | 0 | } |
6348 | 0 | if (!_PyLong_UnsignedInt_Converter(args[1], &flags)) { |
6349 | 0 | goto exit; |
6350 | 0 | } |
6351 | 0 | skip_optional_pos: |
6352 | 0 | return_value = os_pidfd_open_impl(module, pid, flags); |
6353 | |
|
6354 | 0 | exit: |
6355 | 0 | return return_value; |
6356 | 0 | } |
6357 | | |
6358 | | #endif /* (defined(__linux__) && defined(__NR_pidfd_open) && !(defined(__ANDROID__) && __ANDROID_API__ < 31)) */ |
6359 | | |
6360 | | #if defined(HAVE_SETNS) |
6361 | | |
6362 | | PyDoc_STRVAR(os_setns__doc__, |
6363 | | "setns($module, /, fd, nstype=0)\n" |
6364 | | "--\n" |
6365 | | "\n" |
6366 | | "Move the calling thread into different namespaces.\n" |
6367 | | "\n" |
6368 | | " fd\n" |
6369 | | " A file descriptor to a namespace.\n" |
6370 | | " nstype\n" |
6371 | | " Type of namespace."); |
6372 | | |
6373 | | #define OS_SETNS_METHODDEF \ |
6374 | | {"setns", _PyCFunction_CAST(os_setns), METH_FASTCALL|METH_KEYWORDS, os_setns__doc__}, |
6375 | | |
6376 | | static PyObject * |
6377 | | os_setns_impl(PyObject *module, int fd, int nstype); |
6378 | | |
6379 | | static PyObject * |
6380 | | os_setns(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
6381 | 0 | { |
6382 | 0 | PyObject *return_value = NULL; |
6383 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
6384 | |
|
6385 | 0 | #define NUM_KEYWORDS 2 |
6386 | 0 | static struct { |
6387 | 0 | PyGC_Head _this_is_not_used; |
6388 | 0 | PyObject_VAR_HEAD |
6389 | 0 | Py_hash_t ob_hash; |
6390 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
6391 | 0 | } _kwtuple = { |
6392 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
6393 | 0 | .ob_hash = -1, |
6394 | 0 | .ob_item = { &_Py_ID(fd), &_Py_ID(nstype), }, |
6395 | 0 | }; |
6396 | 0 | #undef NUM_KEYWORDS |
6397 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
6398 | |
|
6399 | | #else // !Py_BUILD_CORE |
6400 | | # define KWTUPLE NULL |
6401 | | #endif // !Py_BUILD_CORE |
6402 | |
|
6403 | 0 | static const char * const _keywords[] = {"fd", "nstype", NULL}; |
6404 | 0 | static _PyArg_Parser _parser = { |
6405 | 0 | .keywords = _keywords, |
6406 | 0 | .fname = "setns", |
6407 | 0 | .kwtuple = KWTUPLE, |
6408 | 0 | }; |
6409 | 0 | #undef KWTUPLE |
6410 | 0 | PyObject *argsbuf[2]; |
6411 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
6412 | 0 | int fd; |
6413 | 0 | int nstype = 0; |
6414 | |
|
6415 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
6416 | 0 | /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
6417 | 0 | if (!args) { |
6418 | 0 | goto exit; |
6419 | 0 | } |
6420 | 0 | fd = PyObject_AsFileDescriptor(args[0]); |
6421 | 0 | if (fd < 0) { |
6422 | 0 | goto exit; |
6423 | 0 | } |
6424 | 0 | if (!noptargs) { |
6425 | 0 | goto skip_optional_pos; |
6426 | 0 | } |
6427 | 0 | nstype = PyLong_AsInt(args[1]); |
6428 | 0 | if (nstype == -1 && PyErr_Occurred()) { |
6429 | 0 | goto exit; |
6430 | 0 | } |
6431 | 0 | skip_optional_pos: |
6432 | 0 | return_value = os_setns_impl(module, fd, nstype); |
6433 | |
|
6434 | 0 | exit: |
6435 | 0 | return return_value; |
6436 | 0 | } |
6437 | | |
6438 | | #endif /* defined(HAVE_SETNS) */ |
6439 | | |
6440 | | #if defined(HAVE_UNSHARE) |
6441 | | |
6442 | | PyDoc_STRVAR(os_unshare__doc__, |
6443 | | "unshare($module, /, flags)\n" |
6444 | | "--\n" |
6445 | | "\n" |
6446 | | "Disassociate parts of a process (or thread) execution context.\n" |
6447 | | "\n" |
6448 | | " flags\n" |
6449 | | " Namespaces to be unshared."); |
6450 | | |
6451 | | #define OS_UNSHARE_METHODDEF \ |
6452 | | {"unshare", _PyCFunction_CAST(os_unshare), METH_FASTCALL|METH_KEYWORDS, os_unshare__doc__}, |
6453 | | |
6454 | | static PyObject * |
6455 | | os_unshare_impl(PyObject *module, int flags); |
6456 | | |
6457 | | static PyObject * |
6458 | | os_unshare(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
6459 | 0 | { |
6460 | 0 | PyObject *return_value = NULL; |
6461 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
6462 | |
|
6463 | 0 | #define NUM_KEYWORDS 1 |
6464 | 0 | static struct { |
6465 | 0 | PyGC_Head _this_is_not_used; |
6466 | 0 | PyObject_VAR_HEAD |
6467 | 0 | Py_hash_t ob_hash; |
6468 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
6469 | 0 | } _kwtuple = { |
6470 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
6471 | 0 | .ob_hash = -1, |
6472 | 0 | .ob_item = { &_Py_ID(flags), }, |
6473 | 0 | }; |
6474 | 0 | #undef NUM_KEYWORDS |
6475 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
6476 | |
|
6477 | | #else // !Py_BUILD_CORE |
6478 | | # define KWTUPLE NULL |
6479 | | #endif // !Py_BUILD_CORE |
6480 | |
|
6481 | 0 | static const char * const _keywords[] = {"flags", NULL}; |
6482 | 0 | static _PyArg_Parser _parser = { |
6483 | 0 | .keywords = _keywords, |
6484 | 0 | .fname = "unshare", |
6485 | 0 | .kwtuple = KWTUPLE, |
6486 | 0 | }; |
6487 | 0 | #undef KWTUPLE |
6488 | 0 | PyObject *argsbuf[1]; |
6489 | 0 | int flags; |
6490 | |
|
6491 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
6492 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
6493 | 0 | if (!args) { |
6494 | 0 | goto exit; |
6495 | 0 | } |
6496 | 0 | flags = PyLong_AsInt(args[0]); |
6497 | 0 | if (flags == -1 && PyErr_Occurred()) { |
6498 | 0 | goto exit; |
6499 | 0 | } |
6500 | 0 | return_value = os_unshare_impl(module, flags); |
6501 | |
|
6502 | 0 | exit: |
6503 | 0 | return return_value; |
6504 | 0 | } |
6505 | | |
6506 | | #endif /* defined(HAVE_UNSHARE) */ |
6507 | | |
6508 | | #if (defined(HAVE_READLINK) || defined(MS_WINDOWS)) |
6509 | | |
6510 | | PyDoc_STRVAR(os_readlink__doc__, |
6511 | | "readlink($module, /, path, *, dir_fd=None)\n" |
6512 | | "--\n" |
6513 | | "\n" |
6514 | | "Return a string representing the path to which the symbolic link points.\n" |
6515 | | "\n" |
6516 | | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
6517 | | "and path should be relative; path will then be relative to that directory.\n" |
6518 | | "\n" |
6519 | | "dir_fd may not be implemented on your platform. If it is unavailable,\n" |
6520 | | "using it will raise a NotImplementedError."); |
6521 | | |
6522 | | #define OS_READLINK_METHODDEF \ |
6523 | | {"readlink", _PyCFunction_CAST(os_readlink), METH_FASTCALL|METH_KEYWORDS, os_readlink__doc__}, |
6524 | | |
6525 | | static PyObject * |
6526 | | os_readlink_impl(PyObject *module, path_t *path, int dir_fd); |
6527 | | |
6528 | | static PyObject * |
6529 | | os_readlink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
6530 | 0 | { |
6531 | 0 | PyObject *return_value = NULL; |
6532 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
6533 | |
|
6534 | 0 | #define NUM_KEYWORDS 2 |
6535 | 0 | static struct { |
6536 | 0 | PyGC_Head _this_is_not_used; |
6537 | 0 | PyObject_VAR_HEAD |
6538 | 0 | Py_hash_t ob_hash; |
6539 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
6540 | 0 | } _kwtuple = { |
6541 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
6542 | 0 | .ob_hash = -1, |
6543 | 0 | .ob_item = { &_Py_ID(path), &_Py_ID(dir_fd), }, |
6544 | 0 | }; |
6545 | 0 | #undef NUM_KEYWORDS |
6546 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
6547 | |
|
6548 | | #else // !Py_BUILD_CORE |
6549 | | # define KWTUPLE NULL |
6550 | | #endif // !Py_BUILD_CORE |
6551 | |
|
6552 | 0 | static const char * const _keywords[] = {"path", "dir_fd", NULL}; |
6553 | 0 | static _PyArg_Parser _parser = { |
6554 | 0 | .keywords = _keywords, |
6555 | 0 | .fname = "readlink", |
6556 | 0 | .kwtuple = KWTUPLE, |
6557 | 0 | }; |
6558 | 0 | #undef KWTUPLE |
6559 | 0 | PyObject *argsbuf[2]; |
6560 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
6561 | 0 | path_t path = PATH_T_INITIALIZE_P("readlink", "path", 0, 0, 0, 0); |
6562 | 0 | int dir_fd = DEFAULT_DIR_FD; |
6563 | |
|
6564 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
6565 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
6566 | 0 | if (!args) { |
6567 | 0 | goto exit; |
6568 | 0 | } |
6569 | 0 | if (!path_converter(args[0], &path)) { |
6570 | 0 | goto exit; |
6571 | 0 | } |
6572 | 0 | if (!noptargs) { |
6573 | 0 | goto skip_optional_kwonly; |
6574 | 0 | } |
6575 | 0 | if (!READLINKAT_DIR_FD_CONVERTER(args[1], &dir_fd)) { |
6576 | 0 | goto exit; |
6577 | 0 | } |
6578 | 0 | skip_optional_kwonly: |
6579 | 0 | return_value = os_readlink_impl(module, &path, dir_fd); |
6580 | |
|
6581 | 0 | exit: |
6582 | | /* Cleanup for path */ |
6583 | 0 | path_cleanup(&path); |
6584 | |
|
6585 | 0 | return return_value; |
6586 | 0 | } |
6587 | | |
6588 | | #endif /* (defined(HAVE_READLINK) || defined(MS_WINDOWS)) */ |
6589 | | |
6590 | | #if defined(HAVE_SYMLINK) |
6591 | | |
6592 | | PyDoc_STRVAR(os_symlink__doc__, |
6593 | | "symlink($module, /, src, dst, target_is_directory=False, *, dir_fd=None)\n" |
6594 | | "--\n" |
6595 | | "\n" |
6596 | | "Create a symbolic link pointing to src named dst.\n" |
6597 | | "\n" |
6598 | | "target_is_directory is required on Windows if the target is to be\n" |
6599 | | " interpreted as a directory. (On Windows, symlink requires\n" |
6600 | | " Windows 6.0 or greater, and raises a NotImplementedError otherwise.)\n" |
6601 | | " target_is_directory is ignored on non-Windows platforms.\n" |
6602 | | "\n" |
6603 | | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
6604 | | " and path should be relative; path will then be relative to that directory.\n" |
6605 | | "dir_fd may not be implemented on your platform.\n" |
6606 | | " If it is unavailable, using it will raise a NotImplementedError."); |
6607 | | |
6608 | | #define OS_SYMLINK_METHODDEF \ |
6609 | | {"symlink", _PyCFunction_CAST(os_symlink), METH_FASTCALL|METH_KEYWORDS, os_symlink__doc__}, |
6610 | | |
6611 | | static PyObject * |
6612 | | os_symlink_impl(PyObject *module, path_t *src, path_t *dst, |
6613 | | int target_is_directory, int dir_fd); |
6614 | | |
6615 | | static PyObject * |
6616 | | os_symlink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
6617 | 0 | { |
6618 | 0 | PyObject *return_value = NULL; |
6619 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
6620 | |
|
6621 | 0 | #define NUM_KEYWORDS 4 |
6622 | 0 | static struct { |
6623 | 0 | PyGC_Head _this_is_not_used; |
6624 | 0 | PyObject_VAR_HEAD |
6625 | 0 | Py_hash_t ob_hash; |
6626 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
6627 | 0 | } _kwtuple = { |
6628 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
6629 | 0 | .ob_hash = -1, |
6630 | 0 | .ob_item = { &_Py_ID(src), &_Py_ID(dst), &_Py_ID(target_is_directory), &_Py_ID(dir_fd), }, |
6631 | 0 | }; |
6632 | 0 | #undef NUM_KEYWORDS |
6633 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
6634 | |
|
6635 | | #else // !Py_BUILD_CORE |
6636 | | # define KWTUPLE NULL |
6637 | | #endif // !Py_BUILD_CORE |
6638 | |
|
6639 | 0 | static const char * const _keywords[] = {"src", "dst", "target_is_directory", "dir_fd", NULL}; |
6640 | 0 | static _PyArg_Parser _parser = { |
6641 | 0 | .keywords = _keywords, |
6642 | 0 | .fname = "symlink", |
6643 | 0 | .kwtuple = KWTUPLE, |
6644 | 0 | }; |
6645 | 0 | #undef KWTUPLE |
6646 | 0 | PyObject *argsbuf[4]; |
6647 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2; |
6648 | 0 | path_t src = PATH_T_INITIALIZE_P("symlink", "src", 0, 0, 0, 0); |
6649 | 0 | path_t dst = PATH_T_INITIALIZE_P("symlink", "dst", 0, 0, 0, 0); |
6650 | 0 | int target_is_directory = 0; |
6651 | 0 | int dir_fd = DEFAULT_DIR_FD; |
6652 | |
|
6653 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
6654 | 0 | /*minpos*/ 2, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
6655 | 0 | if (!args) { |
6656 | 0 | goto exit; |
6657 | 0 | } |
6658 | 0 | if (!path_converter(args[0], &src)) { |
6659 | 0 | goto exit; |
6660 | 0 | } |
6661 | 0 | if (!path_converter(args[1], &dst)) { |
6662 | 0 | goto exit; |
6663 | 0 | } |
6664 | 0 | if (!noptargs) { |
6665 | 0 | goto skip_optional_pos; |
6666 | 0 | } |
6667 | 0 | if (args[2]) { |
6668 | 0 | target_is_directory = PyObject_IsTrue(args[2]); |
6669 | 0 | if (target_is_directory < 0) { |
6670 | 0 | goto exit; |
6671 | 0 | } |
6672 | 0 | if (!--noptargs) { |
6673 | 0 | goto skip_optional_pos; |
6674 | 0 | } |
6675 | 0 | } |
6676 | 0 | skip_optional_pos: |
6677 | 0 | if (!noptargs) { |
6678 | 0 | goto skip_optional_kwonly; |
6679 | 0 | } |
6680 | 0 | if (!SYMLINKAT_DIR_FD_CONVERTER(args[3], &dir_fd)) { |
6681 | 0 | goto exit; |
6682 | 0 | } |
6683 | 0 | skip_optional_kwonly: |
6684 | 0 | return_value = os_symlink_impl(module, &src, &dst, target_is_directory, dir_fd); |
6685 | |
|
6686 | 0 | exit: |
6687 | | /* Cleanup for src */ |
6688 | 0 | path_cleanup(&src); |
6689 | | /* Cleanup for dst */ |
6690 | 0 | path_cleanup(&dst); |
6691 | |
|
6692 | 0 | return return_value; |
6693 | 0 | } |
6694 | | |
6695 | | #endif /* defined(HAVE_SYMLINK) */ |
6696 | | |
6697 | | PyDoc_STRVAR(os_times__doc__, |
6698 | | "times($module, /)\n" |
6699 | | "--\n" |
6700 | | "\n" |
6701 | | "Return a collection containing process timing information.\n" |
6702 | | "\n" |
6703 | | "The object returned behaves like a named tuple with these fields:\n" |
6704 | | " (utime, stime, cutime, cstime, elapsed_time)\n" |
6705 | | "All fields are floating-point numbers."); |
6706 | | |
6707 | | #define OS_TIMES_METHODDEF \ |
6708 | | {"times", (PyCFunction)os_times, METH_NOARGS, os_times__doc__}, |
6709 | | |
6710 | | static PyObject * |
6711 | | os_times_impl(PyObject *module); |
6712 | | |
6713 | | static PyObject * |
6714 | | os_times(PyObject *module, PyObject *Py_UNUSED(ignored)) |
6715 | 0 | { |
6716 | 0 | return os_times_impl(module); |
6717 | 0 | } |
6718 | | |
6719 | | #if defined(HAVE_TIMERFD_CREATE) |
6720 | | |
6721 | | PyDoc_STRVAR(os_timerfd_create__doc__, |
6722 | | "timerfd_create($module, clockid, /, *, flags=0)\n" |
6723 | | "--\n" |
6724 | | "\n" |
6725 | | "Create and return a timer file descriptor.\n" |
6726 | | "\n" |
6727 | | " clockid\n" |
6728 | | " A valid clock ID constant as timer file descriptor.\n" |
6729 | | "\n" |
6730 | | " time.CLOCK_REALTIME\n" |
6731 | | " time.CLOCK_MONOTONIC\n" |
6732 | | " time.CLOCK_BOOTTIME\n" |
6733 | | " flags\n" |
6734 | | " 0 or a bit mask of os.TFD_NONBLOCK or os.TFD_CLOEXEC.\n" |
6735 | | "\n" |
6736 | | " os.TFD_NONBLOCK\n" |
6737 | | " If *TFD_NONBLOCK* is set as a flag, read doesn\'t blocks.\n" |
6738 | | " If *TFD_NONBLOCK* is not set as a flag, read block until the timer fires.\n" |
6739 | | "\n" |
6740 | | " os.TFD_CLOEXEC\n" |
6741 | | " If *TFD_CLOEXEC* is set as a flag, enable the close-on-exec flag"); |
6742 | | |
6743 | | #define OS_TIMERFD_CREATE_METHODDEF \ |
6744 | | {"timerfd_create", _PyCFunction_CAST(os_timerfd_create), METH_FASTCALL|METH_KEYWORDS, os_timerfd_create__doc__}, |
6745 | | |
6746 | | static PyObject * |
6747 | | os_timerfd_create_impl(PyObject *module, int clockid, int flags); |
6748 | | |
6749 | | static PyObject * |
6750 | | os_timerfd_create(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
6751 | 0 | { |
6752 | 0 | PyObject *return_value = NULL; |
6753 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
6754 | |
|
6755 | 0 | #define NUM_KEYWORDS 1 |
6756 | 0 | static struct { |
6757 | 0 | PyGC_Head _this_is_not_used; |
6758 | 0 | PyObject_VAR_HEAD |
6759 | 0 | Py_hash_t ob_hash; |
6760 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
6761 | 0 | } _kwtuple = { |
6762 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
6763 | 0 | .ob_hash = -1, |
6764 | 0 | .ob_item = { &_Py_ID(flags), }, |
6765 | 0 | }; |
6766 | 0 | #undef NUM_KEYWORDS |
6767 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
6768 | |
|
6769 | | #else // !Py_BUILD_CORE |
6770 | | # define KWTUPLE NULL |
6771 | | #endif // !Py_BUILD_CORE |
6772 | |
|
6773 | 0 | static const char * const _keywords[] = {"", "flags", NULL}; |
6774 | 0 | static _PyArg_Parser _parser = { |
6775 | 0 | .keywords = _keywords, |
6776 | 0 | .fname = "timerfd_create", |
6777 | 0 | .kwtuple = KWTUPLE, |
6778 | 0 | }; |
6779 | 0 | #undef KWTUPLE |
6780 | 0 | PyObject *argsbuf[2]; |
6781 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
6782 | 0 | int clockid; |
6783 | 0 | int flags = 0; |
6784 | |
|
6785 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
6786 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
6787 | 0 | if (!args) { |
6788 | 0 | goto exit; |
6789 | 0 | } |
6790 | 0 | clockid = PyLong_AsInt(args[0]); |
6791 | 0 | if (clockid == -1 && PyErr_Occurred()) { |
6792 | 0 | goto exit; |
6793 | 0 | } |
6794 | 0 | if (!noptargs) { |
6795 | 0 | goto skip_optional_kwonly; |
6796 | 0 | } |
6797 | 0 | flags = PyLong_AsInt(args[1]); |
6798 | 0 | if (flags == -1 && PyErr_Occurred()) { |
6799 | 0 | goto exit; |
6800 | 0 | } |
6801 | 0 | skip_optional_kwonly: |
6802 | 0 | return_value = os_timerfd_create_impl(module, clockid, flags); |
6803 | |
|
6804 | 0 | exit: |
6805 | 0 | return return_value; |
6806 | 0 | } |
6807 | | |
6808 | | #endif /* defined(HAVE_TIMERFD_CREATE) */ |
6809 | | |
6810 | | #if defined(HAVE_TIMERFD_CREATE) |
6811 | | |
6812 | | PyDoc_STRVAR(os_timerfd_settime__doc__, |
6813 | | "timerfd_settime($module, fd, /, *, flags=0, initial=0.0, interval=0.0)\n" |
6814 | | "--\n" |
6815 | | "\n" |
6816 | | "Alter a timer file descriptor\'s internal timer in seconds.\n" |
6817 | | "\n" |
6818 | | " fd\n" |
6819 | | " A timer file descriptor.\n" |
6820 | | " flags\n" |
6821 | | " 0 or a bit mask of TFD_TIMER_ABSTIME or TFD_TIMER_CANCEL_ON_SET.\n" |
6822 | | " initial\n" |
6823 | | " The initial expiration time, in seconds.\n" |
6824 | | " interval\n" |
6825 | | " The timer\'s interval, in seconds."); |
6826 | | |
6827 | | #define OS_TIMERFD_SETTIME_METHODDEF \ |
6828 | | {"timerfd_settime", _PyCFunction_CAST(os_timerfd_settime), METH_FASTCALL|METH_KEYWORDS, os_timerfd_settime__doc__}, |
6829 | | |
6830 | | static PyObject * |
6831 | | os_timerfd_settime_impl(PyObject *module, int fd, int flags, |
6832 | | double initial_double, double interval_double); |
6833 | | |
6834 | | static PyObject * |
6835 | | os_timerfd_settime(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
6836 | 0 | { |
6837 | 0 | PyObject *return_value = NULL; |
6838 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
6839 | |
|
6840 | 0 | #define NUM_KEYWORDS 3 |
6841 | 0 | static struct { |
6842 | 0 | PyGC_Head _this_is_not_used; |
6843 | 0 | PyObject_VAR_HEAD |
6844 | 0 | Py_hash_t ob_hash; |
6845 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
6846 | 0 | } _kwtuple = { |
6847 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
6848 | 0 | .ob_hash = -1, |
6849 | 0 | .ob_item = { &_Py_ID(flags), &_Py_ID(initial), &_Py_ID(interval), }, |
6850 | 0 | }; |
6851 | 0 | #undef NUM_KEYWORDS |
6852 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
6853 | |
|
6854 | | #else // !Py_BUILD_CORE |
6855 | | # define KWTUPLE NULL |
6856 | | #endif // !Py_BUILD_CORE |
6857 | |
|
6858 | 0 | static const char * const _keywords[] = {"", "flags", "initial", "interval", NULL}; |
6859 | 0 | static _PyArg_Parser _parser = { |
6860 | 0 | .keywords = _keywords, |
6861 | 0 | .fname = "timerfd_settime", |
6862 | 0 | .kwtuple = KWTUPLE, |
6863 | 0 | }; |
6864 | 0 | #undef KWTUPLE |
6865 | 0 | PyObject *argsbuf[4]; |
6866 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
6867 | 0 | int fd; |
6868 | 0 | int flags = 0; |
6869 | 0 | double initial_double = 0.0; |
6870 | 0 | double interval_double = 0.0; |
6871 | |
|
6872 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
6873 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
6874 | 0 | if (!args) { |
6875 | 0 | goto exit; |
6876 | 0 | } |
6877 | 0 | fd = PyObject_AsFileDescriptor(args[0]); |
6878 | 0 | if (fd < 0) { |
6879 | 0 | goto exit; |
6880 | 0 | } |
6881 | 0 | if (!noptargs) { |
6882 | 0 | goto skip_optional_kwonly; |
6883 | 0 | } |
6884 | 0 | if (args[1]) { |
6885 | 0 | flags = PyLong_AsInt(args[1]); |
6886 | 0 | if (flags == -1 && PyErr_Occurred()) { |
6887 | 0 | goto exit; |
6888 | 0 | } |
6889 | 0 | if (!--noptargs) { |
6890 | 0 | goto skip_optional_kwonly; |
6891 | 0 | } |
6892 | 0 | } |
6893 | 0 | if (args[2]) { |
6894 | 0 | if (PyFloat_CheckExact(args[2])) { |
6895 | 0 | initial_double = PyFloat_AS_DOUBLE(args[2]); |
6896 | 0 | } |
6897 | 0 | else |
6898 | 0 | { |
6899 | 0 | initial_double = PyFloat_AsDouble(args[2]); |
6900 | 0 | if (initial_double == -1.0 && PyErr_Occurred()) { |
6901 | 0 | goto exit; |
6902 | 0 | } |
6903 | 0 | } |
6904 | 0 | if (!--noptargs) { |
6905 | 0 | goto skip_optional_kwonly; |
6906 | 0 | } |
6907 | 0 | } |
6908 | 0 | if (PyFloat_CheckExact(args[3])) { |
6909 | 0 | interval_double = PyFloat_AS_DOUBLE(args[3]); |
6910 | 0 | } |
6911 | 0 | else |
6912 | 0 | { |
6913 | 0 | interval_double = PyFloat_AsDouble(args[3]); |
6914 | 0 | if (interval_double == -1.0 && PyErr_Occurred()) { |
6915 | 0 | goto exit; |
6916 | 0 | } |
6917 | 0 | } |
6918 | 0 | skip_optional_kwonly: |
6919 | 0 | return_value = os_timerfd_settime_impl(module, fd, flags, initial_double, interval_double); |
6920 | |
|
6921 | 0 | exit: |
6922 | 0 | return return_value; |
6923 | 0 | } |
6924 | | |
6925 | | #endif /* defined(HAVE_TIMERFD_CREATE) */ |
6926 | | |
6927 | | #if defined(HAVE_TIMERFD_CREATE) |
6928 | | |
6929 | | PyDoc_STRVAR(os_timerfd_settime_ns__doc__, |
6930 | | "timerfd_settime_ns($module, fd, /, *, flags=0, initial=0, interval=0)\n" |
6931 | | "--\n" |
6932 | | "\n" |
6933 | | "Alter a timer file descriptor\'s internal timer in nanoseconds.\n" |
6934 | | "\n" |
6935 | | " fd\n" |
6936 | | " A timer file descriptor.\n" |
6937 | | " flags\n" |
6938 | | " 0 or a bit mask of TFD_TIMER_ABSTIME or TFD_TIMER_CANCEL_ON_SET.\n" |
6939 | | " initial\n" |
6940 | | " initial expiration timing in seconds.\n" |
6941 | | " interval\n" |
6942 | | " interval for the timer in seconds."); |
6943 | | |
6944 | | #define OS_TIMERFD_SETTIME_NS_METHODDEF \ |
6945 | | {"timerfd_settime_ns", _PyCFunction_CAST(os_timerfd_settime_ns), METH_FASTCALL|METH_KEYWORDS, os_timerfd_settime_ns__doc__}, |
6946 | | |
6947 | | static PyObject * |
6948 | | os_timerfd_settime_ns_impl(PyObject *module, int fd, int flags, |
6949 | | long long initial, long long interval); |
6950 | | |
6951 | | static PyObject * |
6952 | | os_timerfd_settime_ns(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
6953 | 0 | { |
6954 | 0 | PyObject *return_value = NULL; |
6955 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
6956 | |
|
6957 | 0 | #define NUM_KEYWORDS 3 |
6958 | 0 | static struct { |
6959 | 0 | PyGC_Head _this_is_not_used; |
6960 | 0 | PyObject_VAR_HEAD |
6961 | 0 | Py_hash_t ob_hash; |
6962 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
6963 | 0 | } _kwtuple = { |
6964 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
6965 | 0 | .ob_hash = -1, |
6966 | 0 | .ob_item = { &_Py_ID(flags), &_Py_ID(initial), &_Py_ID(interval), }, |
6967 | 0 | }; |
6968 | 0 | #undef NUM_KEYWORDS |
6969 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
6970 | |
|
6971 | | #else // !Py_BUILD_CORE |
6972 | | # define KWTUPLE NULL |
6973 | | #endif // !Py_BUILD_CORE |
6974 | |
|
6975 | 0 | static const char * const _keywords[] = {"", "flags", "initial", "interval", NULL}; |
6976 | 0 | static _PyArg_Parser _parser = { |
6977 | 0 | .keywords = _keywords, |
6978 | 0 | .fname = "timerfd_settime_ns", |
6979 | 0 | .kwtuple = KWTUPLE, |
6980 | 0 | }; |
6981 | 0 | #undef KWTUPLE |
6982 | 0 | PyObject *argsbuf[4]; |
6983 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
6984 | 0 | int fd; |
6985 | 0 | int flags = 0; |
6986 | 0 | long long initial = 0; |
6987 | 0 | long long interval = 0; |
6988 | |
|
6989 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
6990 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
6991 | 0 | if (!args) { |
6992 | 0 | goto exit; |
6993 | 0 | } |
6994 | 0 | fd = PyObject_AsFileDescriptor(args[0]); |
6995 | 0 | if (fd < 0) { |
6996 | 0 | goto exit; |
6997 | 0 | } |
6998 | 0 | if (!noptargs) { |
6999 | 0 | goto skip_optional_kwonly; |
7000 | 0 | } |
7001 | 0 | if (args[1]) { |
7002 | 0 | flags = PyLong_AsInt(args[1]); |
7003 | 0 | if (flags == -1 && PyErr_Occurred()) { |
7004 | 0 | goto exit; |
7005 | 0 | } |
7006 | 0 | if (!--noptargs) { |
7007 | 0 | goto skip_optional_kwonly; |
7008 | 0 | } |
7009 | 0 | } |
7010 | 0 | if (args[2]) { |
7011 | 0 | initial = PyLong_AsLongLong(args[2]); |
7012 | 0 | if (initial == -1 && PyErr_Occurred()) { |
7013 | 0 | goto exit; |
7014 | 0 | } |
7015 | 0 | if (!--noptargs) { |
7016 | 0 | goto skip_optional_kwonly; |
7017 | 0 | } |
7018 | 0 | } |
7019 | 0 | interval = PyLong_AsLongLong(args[3]); |
7020 | 0 | if (interval == -1 && PyErr_Occurred()) { |
7021 | 0 | goto exit; |
7022 | 0 | } |
7023 | 0 | skip_optional_kwonly: |
7024 | 0 | return_value = os_timerfd_settime_ns_impl(module, fd, flags, initial, interval); |
7025 | |
|
7026 | 0 | exit: |
7027 | 0 | return return_value; |
7028 | 0 | } |
7029 | | |
7030 | | #endif /* defined(HAVE_TIMERFD_CREATE) */ |
7031 | | |
7032 | | #if defined(HAVE_TIMERFD_CREATE) |
7033 | | |
7034 | | PyDoc_STRVAR(os_timerfd_gettime__doc__, |
7035 | | "timerfd_gettime($module, fd, /)\n" |
7036 | | "--\n" |
7037 | | "\n" |
7038 | | "Return a tuple of a timer file descriptor\'s (interval, next expiration) in float seconds.\n" |
7039 | | "\n" |
7040 | | " fd\n" |
7041 | | " A timer file descriptor."); |
7042 | | |
7043 | | #define OS_TIMERFD_GETTIME_METHODDEF \ |
7044 | | {"timerfd_gettime", (PyCFunction)os_timerfd_gettime, METH_O, os_timerfd_gettime__doc__}, |
7045 | | |
7046 | | static PyObject * |
7047 | | os_timerfd_gettime_impl(PyObject *module, int fd); |
7048 | | |
7049 | | static PyObject * |
7050 | | os_timerfd_gettime(PyObject *module, PyObject *arg) |
7051 | 0 | { |
7052 | 0 | PyObject *return_value = NULL; |
7053 | 0 | int fd; |
7054 | |
|
7055 | 0 | fd = PyObject_AsFileDescriptor(arg); |
7056 | 0 | if (fd < 0) { |
7057 | 0 | goto exit; |
7058 | 0 | } |
7059 | 0 | return_value = os_timerfd_gettime_impl(module, fd); |
7060 | |
|
7061 | 0 | exit: |
7062 | 0 | return return_value; |
7063 | 0 | } |
7064 | | |
7065 | | #endif /* defined(HAVE_TIMERFD_CREATE) */ |
7066 | | |
7067 | | #if defined(HAVE_TIMERFD_CREATE) |
7068 | | |
7069 | | PyDoc_STRVAR(os_timerfd_gettime_ns__doc__, |
7070 | | "timerfd_gettime_ns($module, fd, /)\n" |
7071 | | "--\n" |
7072 | | "\n" |
7073 | | "Return a tuple of a timer file descriptor\'s (interval, next expiration) in nanoseconds.\n" |
7074 | | "\n" |
7075 | | " fd\n" |
7076 | | " A timer file descriptor."); |
7077 | | |
7078 | | #define OS_TIMERFD_GETTIME_NS_METHODDEF \ |
7079 | | {"timerfd_gettime_ns", (PyCFunction)os_timerfd_gettime_ns, METH_O, os_timerfd_gettime_ns__doc__}, |
7080 | | |
7081 | | static PyObject * |
7082 | | os_timerfd_gettime_ns_impl(PyObject *module, int fd); |
7083 | | |
7084 | | static PyObject * |
7085 | | os_timerfd_gettime_ns(PyObject *module, PyObject *arg) |
7086 | 0 | { |
7087 | 0 | PyObject *return_value = NULL; |
7088 | 0 | int fd; |
7089 | |
|
7090 | 0 | fd = PyObject_AsFileDescriptor(arg); |
7091 | 0 | if (fd < 0) { |
7092 | 0 | goto exit; |
7093 | 0 | } |
7094 | 0 | return_value = os_timerfd_gettime_ns_impl(module, fd); |
7095 | |
|
7096 | 0 | exit: |
7097 | 0 | return return_value; |
7098 | 0 | } |
7099 | | |
7100 | | #endif /* defined(HAVE_TIMERFD_CREATE) */ |
7101 | | |
7102 | | #if defined(HAVE_GETSID) |
7103 | | |
7104 | | PyDoc_STRVAR(os_getsid__doc__, |
7105 | | "getsid($module, pid, /)\n" |
7106 | | "--\n" |
7107 | | "\n" |
7108 | | "Call the system call getsid(pid) and return the result."); |
7109 | | |
7110 | | #define OS_GETSID_METHODDEF \ |
7111 | | {"getsid", (PyCFunction)os_getsid, METH_O, os_getsid__doc__}, |
7112 | | |
7113 | | static PyObject * |
7114 | | os_getsid_impl(PyObject *module, pid_t pid); |
7115 | | |
7116 | | static PyObject * |
7117 | | os_getsid(PyObject *module, PyObject *arg) |
7118 | 0 | { |
7119 | 0 | PyObject *return_value = NULL; |
7120 | 0 | pid_t pid; |
7121 | |
|
7122 | 0 | pid = PyLong_AsPid(arg); |
7123 | 0 | if (pid == (pid_t)(-1) && PyErr_Occurred()) { |
7124 | 0 | goto exit; |
7125 | 0 | } |
7126 | 0 | return_value = os_getsid_impl(module, pid); |
7127 | |
|
7128 | 0 | exit: |
7129 | 0 | return return_value; |
7130 | 0 | } |
7131 | | |
7132 | | #endif /* defined(HAVE_GETSID) */ |
7133 | | |
7134 | | #if defined(HAVE_SETSID) |
7135 | | |
7136 | | PyDoc_STRVAR(os_setsid__doc__, |
7137 | | "setsid($module, /)\n" |
7138 | | "--\n" |
7139 | | "\n" |
7140 | | "Call the system call setsid()."); |
7141 | | |
7142 | | #define OS_SETSID_METHODDEF \ |
7143 | | {"setsid", (PyCFunction)os_setsid, METH_NOARGS, os_setsid__doc__}, |
7144 | | |
7145 | | static PyObject * |
7146 | | os_setsid_impl(PyObject *module); |
7147 | | |
7148 | | static PyObject * |
7149 | | os_setsid(PyObject *module, PyObject *Py_UNUSED(ignored)) |
7150 | 0 | { |
7151 | 0 | return os_setsid_impl(module); |
7152 | 0 | } |
7153 | | |
7154 | | #endif /* defined(HAVE_SETSID) */ |
7155 | | |
7156 | | #if defined(HAVE_SETPGID) |
7157 | | |
7158 | | PyDoc_STRVAR(os_setpgid__doc__, |
7159 | | "setpgid($module, pid, pgrp, /)\n" |
7160 | | "--\n" |
7161 | | "\n" |
7162 | | "Call the system call setpgid(pid, pgrp)."); |
7163 | | |
7164 | | #define OS_SETPGID_METHODDEF \ |
7165 | | {"setpgid", _PyCFunction_CAST(os_setpgid), METH_FASTCALL, os_setpgid__doc__}, |
7166 | | |
7167 | | static PyObject * |
7168 | | os_setpgid_impl(PyObject *module, pid_t pid, pid_t pgrp); |
7169 | | |
7170 | | static PyObject * |
7171 | | os_setpgid(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
7172 | 0 | { |
7173 | 0 | PyObject *return_value = NULL; |
7174 | 0 | pid_t pid; |
7175 | 0 | pid_t pgrp; |
7176 | |
|
7177 | 0 | if (!_PyArg_CheckPositional("setpgid", nargs, 2, 2)) { |
7178 | 0 | goto exit; |
7179 | 0 | } |
7180 | 0 | pid = PyLong_AsPid(args[0]); |
7181 | 0 | if (pid == (pid_t)(-1) && PyErr_Occurred()) { |
7182 | 0 | goto exit; |
7183 | 0 | } |
7184 | 0 | pgrp = PyLong_AsPid(args[1]); |
7185 | 0 | if (pgrp == (pid_t)(-1) && PyErr_Occurred()) { |
7186 | 0 | goto exit; |
7187 | 0 | } |
7188 | 0 | return_value = os_setpgid_impl(module, pid, pgrp); |
7189 | |
|
7190 | 0 | exit: |
7191 | 0 | return return_value; |
7192 | 0 | } |
7193 | | |
7194 | | #endif /* defined(HAVE_SETPGID) */ |
7195 | | |
7196 | | #if defined(HAVE_TCGETPGRP) |
7197 | | |
7198 | | PyDoc_STRVAR(os_tcgetpgrp__doc__, |
7199 | | "tcgetpgrp($module, fd, /)\n" |
7200 | | "--\n" |
7201 | | "\n" |
7202 | | "Return the process group associated with the terminal specified by fd."); |
7203 | | |
7204 | | #define OS_TCGETPGRP_METHODDEF \ |
7205 | | {"tcgetpgrp", (PyCFunction)os_tcgetpgrp, METH_O, os_tcgetpgrp__doc__}, |
7206 | | |
7207 | | static PyObject * |
7208 | | os_tcgetpgrp_impl(PyObject *module, int fd); |
7209 | | |
7210 | | static PyObject * |
7211 | | os_tcgetpgrp(PyObject *module, PyObject *arg) |
7212 | 0 | { |
7213 | 0 | PyObject *return_value = NULL; |
7214 | 0 | int fd; |
7215 | |
|
7216 | 0 | fd = PyLong_AsInt(arg); |
7217 | 0 | if (fd == -1 && PyErr_Occurred()) { |
7218 | 0 | goto exit; |
7219 | 0 | } |
7220 | 0 | return_value = os_tcgetpgrp_impl(module, fd); |
7221 | |
|
7222 | 0 | exit: |
7223 | 0 | return return_value; |
7224 | 0 | } |
7225 | | |
7226 | | #endif /* defined(HAVE_TCGETPGRP) */ |
7227 | | |
7228 | | #if defined(HAVE_TCSETPGRP) |
7229 | | |
7230 | | PyDoc_STRVAR(os_tcsetpgrp__doc__, |
7231 | | "tcsetpgrp($module, fd, pgid, /)\n" |
7232 | | "--\n" |
7233 | | "\n" |
7234 | | "Set the process group associated with the terminal specified by fd."); |
7235 | | |
7236 | | #define OS_TCSETPGRP_METHODDEF \ |
7237 | | {"tcsetpgrp", _PyCFunction_CAST(os_tcsetpgrp), METH_FASTCALL, os_tcsetpgrp__doc__}, |
7238 | | |
7239 | | static PyObject * |
7240 | | os_tcsetpgrp_impl(PyObject *module, int fd, pid_t pgid); |
7241 | | |
7242 | | static PyObject * |
7243 | | os_tcsetpgrp(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
7244 | 0 | { |
7245 | 0 | PyObject *return_value = NULL; |
7246 | 0 | int fd; |
7247 | 0 | pid_t pgid; |
7248 | |
|
7249 | 0 | if (!_PyArg_CheckPositional("tcsetpgrp", nargs, 2, 2)) { |
7250 | 0 | goto exit; |
7251 | 0 | } |
7252 | 0 | fd = PyLong_AsInt(args[0]); |
7253 | 0 | if (fd == -1 && PyErr_Occurred()) { |
7254 | 0 | goto exit; |
7255 | 0 | } |
7256 | 0 | pgid = PyLong_AsPid(args[1]); |
7257 | 0 | if (pgid == (pid_t)(-1) && PyErr_Occurred()) { |
7258 | 0 | goto exit; |
7259 | 0 | } |
7260 | 0 | return_value = os_tcsetpgrp_impl(module, fd, pgid); |
7261 | |
|
7262 | 0 | exit: |
7263 | 0 | return return_value; |
7264 | 0 | } |
7265 | | |
7266 | | #endif /* defined(HAVE_TCSETPGRP) */ |
7267 | | |
7268 | | PyDoc_STRVAR(os_open__doc__, |
7269 | | "open($module, /, path, flags, mode=511, *, dir_fd=None)\n" |
7270 | | "--\n" |
7271 | | "\n" |
7272 | | "Open a file for low level IO. Returns a file descriptor (integer).\n" |
7273 | | "\n" |
7274 | | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
7275 | | " and path should be relative; path will then be relative to that directory.\n" |
7276 | | "dir_fd may not be implemented on your platform.\n" |
7277 | | " If it is unavailable, using it will raise a NotImplementedError."); |
7278 | | |
7279 | | #define OS_OPEN_METHODDEF \ |
7280 | | {"open", _PyCFunction_CAST(os_open), METH_FASTCALL|METH_KEYWORDS, os_open__doc__}, |
7281 | | |
7282 | | static int |
7283 | | os_open_impl(PyObject *module, path_t *path, int flags, int mode, int dir_fd); |
7284 | | |
7285 | | static PyObject * |
7286 | | os_open(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
7287 | 218 | { |
7288 | 218 | PyObject *return_value = NULL; |
7289 | 218 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
7290 | | |
7291 | 218 | #define NUM_KEYWORDS 4 |
7292 | 218 | static struct { |
7293 | 218 | PyGC_Head _this_is_not_used; |
7294 | 218 | PyObject_VAR_HEAD |
7295 | 218 | Py_hash_t ob_hash; |
7296 | 218 | PyObject *ob_item[NUM_KEYWORDS]; |
7297 | 218 | } _kwtuple = { |
7298 | 218 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
7299 | 218 | .ob_hash = -1, |
7300 | 218 | .ob_item = { &_Py_ID(path), &_Py_ID(flags), &_Py_ID(mode), &_Py_ID(dir_fd), }, |
7301 | 218 | }; |
7302 | 218 | #undef NUM_KEYWORDS |
7303 | 218 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
7304 | | |
7305 | | #else // !Py_BUILD_CORE |
7306 | | # define KWTUPLE NULL |
7307 | | #endif // !Py_BUILD_CORE |
7308 | | |
7309 | 218 | static const char * const _keywords[] = {"path", "flags", "mode", "dir_fd", NULL}; |
7310 | 218 | static _PyArg_Parser _parser = { |
7311 | 218 | .keywords = _keywords, |
7312 | 218 | .fname = "open", |
7313 | 218 | .kwtuple = KWTUPLE, |
7314 | 218 | }; |
7315 | 218 | #undef KWTUPLE |
7316 | 218 | PyObject *argsbuf[4]; |
7317 | 218 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2; |
7318 | 218 | path_t path = PATH_T_INITIALIZE_P("open", "path", 0, 0, 0, 0); |
7319 | 218 | int flags; |
7320 | 218 | int mode = 511; |
7321 | 218 | int dir_fd = DEFAULT_DIR_FD; |
7322 | 218 | int _return_value; |
7323 | | |
7324 | 218 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
7325 | 218 | /*minpos*/ 2, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
7326 | 218 | if (!args) { |
7327 | 0 | goto exit; |
7328 | 0 | } |
7329 | 218 | if (!path_converter(args[0], &path)) { |
7330 | 0 | goto exit; |
7331 | 0 | } |
7332 | 218 | flags = PyLong_AsInt(args[1]); |
7333 | 218 | if (flags == -1 && PyErr_Occurred()) { |
7334 | 0 | goto exit; |
7335 | 0 | } |
7336 | 218 | if (!noptargs) { |
7337 | 0 | goto skip_optional_pos; |
7338 | 0 | } |
7339 | 218 | if (args[2]) { |
7340 | 218 | mode = PyLong_AsInt(args[2]); |
7341 | 218 | if (mode == -1 && PyErr_Occurred()) { |
7342 | 0 | goto exit; |
7343 | 0 | } |
7344 | 218 | if (!--noptargs) { |
7345 | 218 | goto skip_optional_pos; |
7346 | 218 | } |
7347 | 218 | } |
7348 | 218 | skip_optional_pos: |
7349 | 218 | if (!noptargs) { |
7350 | 218 | goto skip_optional_kwonly; |
7351 | 218 | } |
7352 | 0 | if (!OPENAT_DIR_FD_CONVERTER(args[3], &dir_fd)) { |
7353 | 0 | goto exit; |
7354 | 0 | } |
7355 | 218 | skip_optional_kwonly: |
7356 | 218 | _return_value = os_open_impl(module, &path, flags, mode, dir_fd); |
7357 | 218 | if ((_return_value == -1) && PyErr_Occurred()) { |
7358 | 0 | goto exit; |
7359 | 0 | } |
7360 | 218 | return_value = PyLong_FromLong((long)_return_value); |
7361 | | |
7362 | 218 | exit: |
7363 | | /* Cleanup for path */ |
7364 | 218 | path_cleanup(&path); |
7365 | | |
7366 | 218 | return return_value; |
7367 | 218 | } |
7368 | | |
7369 | | PyDoc_STRVAR(os_close__doc__, |
7370 | | "close($module, /, fd)\n" |
7371 | | "--\n" |
7372 | | "\n" |
7373 | | "Close a file descriptor."); |
7374 | | |
7375 | | #define OS_CLOSE_METHODDEF \ |
7376 | | {"close", _PyCFunction_CAST(os_close), METH_FASTCALL|METH_KEYWORDS, os_close__doc__}, |
7377 | | |
7378 | | static PyObject * |
7379 | | os_close_impl(PyObject *module, int fd); |
7380 | | |
7381 | | static PyObject * |
7382 | | os_close(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
7383 | 0 | { |
7384 | 0 | PyObject *return_value = NULL; |
7385 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
7386 | |
|
7387 | 0 | #define NUM_KEYWORDS 1 |
7388 | 0 | static struct { |
7389 | 0 | PyGC_Head _this_is_not_used; |
7390 | 0 | PyObject_VAR_HEAD |
7391 | 0 | Py_hash_t ob_hash; |
7392 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
7393 | 0 | } _kwtuple = { |
7394 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
7395 | 0 | .ob_hash = -1, |
7396 | 0 | .ob_item = { &_Py_ID(fd), }, |
7397 | 0 | }; |
7398 | 0 | #undef NUM_KEYWORDS |
7399 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
7400 | |
|
7401 | | #else // !Py_BUILD_CORE |
7402 | | # define KWTUPLE NULL |
7403 | | #endif // !Py_BUILD_CORE |
7404 | |
|
7405 | 0 | static const char * const _keywords[] = {"fd", NULL}; |
7406 | 0 | static _PyArg_Parser _parser = { |
7407 | 0 | .keywords = _keywords, |
7408 | 0 | .fname = "close", |
7409 | 0 | .kwtuple = KWTUPLE, |
7410 | 0 | }; |
7411 | 0 | #undef KWTUPLE |
7412 | 0 | PyObject *argsbuf[1]; |
7413 | 0 | int fd; |
7414 | |
|
7415 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
7416 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
7417 | 0 | if (!args) { |
7418 | 0 | goto exit; |
7419 | 0 | } |
7420 | 0 | fd = PyLong_AsInt(args[0]); |
7421 | 0 | if (fd == -1 && PyErr_Occurred()) { |
7422 | 0 | goto exit; |
7423 | 0 | } |
7424 | 0 | return_value = os_close_impl(module, fd); |
7425 | |
|
7426 | 0 | exit: |
7427 | 0 | return return_value; |
7428 | 0 | } |
7429 | | |
7430 | | PyDoc_STRVAR(os_closerange__doc__, |
7431 | | "closerange($module, fd_low, fd_high, /)\n" |
7432 | | "--\n" |
7433 | | "\n" |
7434 | | "Closes all file descriptors in [fd_low, fd_high), ignoring errors."); |
7435 | | |
7436 | | #define OS_CLOSERANGE_METHODDEF \ |
7437 | | {"closerange", _PyCFunction_CAST(os_closerange), METH_FASTCALL, os_closerange__doc__}, |
7438 | | |
7439 | | static PyObject * |
7440 | | os_closerange_impl(PyObject *module, int fd_low, int fd_high); |
7441 | | |
7442 | | static PyObject * |
7443 | | os_closerange(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
7444 | 0 | { |
7445 | 0 | PyObject *return_value = NULL; |
7446 | 0 | int fd_low; |
7447 | 0 | int fd_high; |
7448 | |
|
7449 | 0 | if (!_PyArg_CheckPositional("closerange", nargs, 2, 2)) { |
7450 | 0 | goto exit; |
7451 | 0 | } |
7452 | 0 | fd_low = PyLong_AsInt(args[0]); |
7453 | 0 | if (fd_low == -1 && PyErr_Occurred()) { |
7454 | 0 | goto exit; |
7455 | 0 | } |
7456 | 0 | fd_high = PyLong_AsInt(args[1]); |
7457 | 0 | if (fd_high == -1 && PyErr_Occurred()) { |
7458 | 0 | goto exit; |
7459 | 0 | } |
7460 | 0 | return_value = os_closerange_impl(module, fd_low, fd_high); |
7461 | |
|
7462 | 0 | exit: |
7463 | 0 | return return_value; |
7464 | 0 | } |
7465 | | |
7466 | | PyDoc_STRVAR(os_dup__doc__, |
7467 | | "dup($module, fd, /)\n" |
7468 | | "--\n" |
7469 | | "\n" |
7470 | | "Return a duplicate of a file descriptor."); |
7471 | | |
7472 | | #define OS_DUP_METHODDEF \ |
7473 | | {"dup", (PyCFunction)os_dup, METH_O, os_dup__doc__}, |
7474 | | |
7475 | | static int |
7476 | | os_dup_impl(PyObject *module, int fd); |
7477 | | |
7478 | | static PyObject * |
7479 | | os_dup(PyObject *module, PyObject *arg) |
7480 | 0 | { |
7481 | 0 | PyObject *return_value = NULL; |
7482 | 0 | int fd; |
7483 | 0 | int _return_value; |
7484 | |
|
7485 | 0 | fd = PyLong_AsInt(arg); |
7486 | 0 | if (fd == -1 && PyErr_Occurred()) { |
7487 | 0 | goto exit; |
7488 | 0 | } |
7489 | 0 | _return_value = os_dup_impl(module, fd); |
7490 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
7491 | 0 | goto exit; |
7492 | 0 | } |
7493 | 0 | return_value = PyLong_FromLong((long)_return_value); |
7494 | |
|
7495 | 0 | exit: |
7496 | 0 | return return_value; |
7497 | 0 | } |
7498 | | |
7499 | | #if ((defined(HAVE_DUP3) || defined(F_DUPFD) || defined(MS_WINDOWS))) |
7500 | | |
7501 | | PyDoc_STRVAR(os_dup2__doc__, |
7502 | | "dup2($module, /, fd, fd2, inheritable=True)\n" |
7503 | | "--\n" |
7504 | | "\n" |
7505 | | "Duplicate file descriptor."); |
7506 | | |
7507 | | #define OS_DUP2_METHODDEF \ |
7508 | | {"dup2", _PyCFunction_CAST(os_dup2), METH_FASTCALL|METH_KEYWORDS, os_dup2__doc__}, |
7509 | | |
7510 | | static int |
7511 | | os_dup2_impl(PyObject *module, int fd, int fd2, int inheritable); |
7512 | | |
7513 | | static PyObject * |
7514 | | os_dup2(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
7515 | 0 | { |
7516 | 0 | PyObject *return_value = NULL; |
7517 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
7518 | |
|
7519 | 0 | #define NUM_KEYWORDS 3 |
7520 | 0 | static struct { |
7521 | 0 | PyGC_Head _this_is_not_used; |
7522 | 0 | PyObject_VAR_HEAD |
7523 | 0 | Py_hash_t ob_hash; |
7524 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
7525 | 0 | } _kwtuple = { |
7526 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
7527 | 0 | .ob_hash = -1, |
7528 | 0 | .ob_item = { &_Py_ID(fd), &_Py_ID(fd2), &_Py_ID(inheritable), }, |
7529 | 0 | }; |
7530 | 0 | #undef NUM_KEYWORDS |
7531 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
7532 | |
|
7533 | | #else // !Py_BUILD_CORE |
7534 | | # define KWTUPLE NULL |
7535 | | #endif // !Py_BUILD_CORE |
7536 | |
|
7537 | 0 | static const char * const _keywords[] = {"fd", "fd2", "inheritable", NULL}; |
7538 | 0 | static _PyArg_Parser _parser = { |
7539 | 0 | .keywords = _keywords, |
7540 | 0 | .fname = "dup2", |
7541 | 0 | .kwtuple = KWTUPLE, |
7542 | 0 | }; |
7543 | 0 | #undef KWTUPLE |
7544 | 0 | PyObject *argsbuf[3]; |
7545 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2; |
7546 | 0 | int fd; |
7547 | 0 | int fd2; |
7548 | 0 | int inheritable = 1; |
7549 | 0 | int _return_value; |
7550 | |
|
7551 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
7552 | 0 | /*minpos*/ 2, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
7553 | 0 | if (!args) { |
7554 | 0 | goto exit; |
7555 | 0 | } |
7556 | 0 | fd = PyLong_AsInt(args[0]); |
7557 | 0 | if (fd == -1 && PyErr_Occurred()) { |
7558 | 0 | goto exit; |
7559 | 0 | } |
7560 | 0 | fd2 = PyLong_AsInt(args[1]); |
7561 | 0 | if (fd2 == -1 && PyErr_Occurred()) { |
7562 | 0 | goto exit; |
7563 | 0 | } |
7564 | 0 | if (!noptargs) { |
7565 | 0 | goto skip_optional_pos; |
7566 | 0 | } |
7567 | 0 | inheritable = PyObject_IsTrue(args[2]); |
7568 | 0 | if (inheritable < 0) { |
7569 | 0 | goto exit; |
7570 | 0 | } |
7571 | 0 | skip_optional_pos: |
7572 | 0 | _return_value = os_dup2_impl(module, fd, fd2, inheritable); |
7573 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
7574 | 0 | goto exit; |
7575 | 0 | } |
7576 | 0 | return_value = PyLong_FromLong((long)_return_value); |
7577 | |
|
7578 | 0 | exit: |
7579 | 0 | return return_value; |
7580 | 0 | } |
7581 | | |
7582 | | #endif /* ((defined(HAVE_DUP3) || defined(F_DUPFD) || defined(MS_WINDOWS))) */ |
7583 | | |
7584 | | #if defined(HAVE_LOCKF) |
7585 | | |
7586 | | PyDoc_STRVAR(os_lockf__doc__, |
7587 | | "lockf($module, fd, command, length, /)\n" |
7588 | | "--\n" |
7589 | | "\n" |
7590 | | "Apply, test or remove a POSIX lock on an open file descriptor.\n" |
7591 | | "\n" |
7592 | | " fd\n" |
7593 | | " An open file descriptor.\n" |
7594 | | " command\n" |
7595 | | " One of F_LOCK, F_TLOCK, F_ULOCK or F_TEST.\n" |
7596 | | " length\n" |
7597 | | " The number of bytes to lock, starting at the current position."); |
7598 | | |
7599 | | #define OS_LOCKF_METHODDEF \ |
7600 | | {"lockf", _PyCFunction_CAST(os_lockf), METH_FASTCALL, os_lockf__doc__}, |
7601 | | |
7602 | | static PyObject * |
7603 | | os_lockf_impl(PyObject *module, int fd, int command, Py_off_t length); |
7604 | | |
7605 | | static PyObject * |
7606 | | os_lockf(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
7607 | 0 | { |
7608 | 0 | PyObject *return_value = NULL; |
7609 | 0 | int fd; |
7610 | 0 | int command; |
7611 | 0 | Py_off_t length; |
7612 | |
|
7613 | 0 | if (!_PyArg_CheckPositional("lockf", nargs, 3, 3)) { |
7614 | 0 | goto exit; |
7615 | 0 | } |
7616 | 0 | fd = PyLong_AsInt(args[0]); |
7617 | 0 | if (fd == -1 && PyErr_Occurred()) { |
7618 | 0 | goto exit; |
7619 | 0 | } |
7620 | 0 | command = PyLong_AsInt(args[1]); |
7621 | 0 | if (command == -1 && PyErr_Occurred()) { |
7622 | 0 | goto exit; |
7623 | 0 | } |
7624 | 0 | if (!Py_off_t_converter(args[2], &length)) { |
7625 | 0 | goto exit; |
7626 | 0 | } |
7627 | 0 | return_value = os_lockf_impl(module, fd, command, length); |
7628 | |
|
7629 | 0 | exit: |
7630 | 0 | return return_value; |
7631 | 0 | } |
7632 | | |
7633 | | #endif /* defined(HAVE_LOCKF) */ |
7634 | | |
7635 | | PyDoc_STRVAR(os_lseek__doc__, |
7636 | | "lseek($module, fd, position, whence, /)\n" |
7637 | | "--\n" |
7638 | | "\n" |
7639 | | "Set the position of a file descriptor. Return the new position.\n" |
7640 | | "\n" |
7641 | | " fd\n" |
7642 | | " An open file descriptor, as returned by os.open().\n" |
7643 | | " position\n" |
7644 | | " Position, interpreted relative to \'whence\'.\n" |
7645 | | " whence\n" |
7646 | | " The relative position to seek from. Valid values are:\n" |
7647 | | " - SEEK_SET: seek from the start of the file.\n" |
7648 | | " - SEEK_CUR: seek from the current file position.\n" |
7649 | | " - SEEK_END: seek from the end of the file.\n" |
7650 | | "\n" |
7651 | | "The return value is the number of bytes relative to the beginning of the file."); |
7652 | | |
7653 | | #define OS_LSEEK_METHODDEF \ |
7654 | | {"lseek", _PyCFunction_CAST(os_lseek), METH_FASTCALL, os_lseek__doc__}, |
7655 | | |
7656 | | static Py_off_t |
7657 | | os_lseek_impl(PyObject *module, int fd, Py_off_t position, int how); |
7658 | | |
7659 | | static PyObject * |
7660 | | os_lseek(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
7661 | 0 | { |
7662 | 0 | PyObject *return_value = NULL; |
7663 | 0 | int fd; |
7664 | 0 | Py_off_t position; |
7665 | 0 | int how; |
7666 | 0 | Py_off_t _return_value; |
7667 | |
|
7668 | 0 | if (!_PyArg_CheckPositional("lseek", nargs, 3, 3)) { |
7669 | 0 | goto exit; |
7670 | 0 | } |
7671 | 0 | fd = PyLong_AsInt(args[0]); |
7672 | 0 | if (fd == -1 && PyErr_Occurred()) { |
7673 | 0 | goto exit; |
7674 | 0 | } |
7675 | 0 | if (!Py_off_t_converter(args[1], &position)) { |
7676 | 0 | goto exit; |
7677 | 0 | } |
7678 | 0 | how = PyLong_AsInt(args[2]); |
7679 | 0 | if (how == -1 && PyErr_Occurred()) { |
7680 | 0 | goto exit; |
7681 | 0 | } |
7682 | 0 | _return_value = os_lseek_impl(module, fd, position, how); |
7683 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
7684 | 0 | goto exit; |
7685 | 0 | } |
7686 | 0 | return_value = PyLong_FromPy_off_t(_return_value); |
7687 | |
|
7688 | 0 | exit: |
7689 | 0 | return return_value; |
7690 | 0 | } |
7691 | | |
7692 | | PyDoc_STRVAR(os_read__doc__, |
7693 | | "read($module, fd, length, /)\n" |
7694 | | "--\n" |
7695 | | "\n" |
7696 | | "Read from a file descriptor. Returns a bytes object."); |
7697 | | |
7698 | | #define OS_READ_METHODDEF \ |
7699 | | {"read", _PyCFunction_CAST(os_read), METH_FASTCALL, os_read__doc__}, |
7700 | | |
7701 | | static PyObject * |
7702 | | os_read_impl(PyObject *module, int fd, Py_ssize_t length); |
7703 | | |
7704 | | static PyObject * |
7705 | | os_read(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
7706 | 0 | { |
7707 | 0 | PyObject *return_value = NULL; |
7708 | 0 | int fd; |
7709 | 0 | Py_ssize_t length; |
7710 | |
|
7711 | 0 | if (!_PyArg_CheckPositional("read", nargs, 2, 2)) { |
7712 | 0 | goto exit; |
7713 | 0 | } |
7714 | 0 | fd = PyLong_AsInt(args[0]); |
7715 | 0 | if (fd == -1 && PyErr_Occurred()) { |
7716 | 0 | goto exit; |
7717 | 0 | } |
7718 | 0 | { |
7719 | 0 | Py_ssize_t ival = -1; |
7720 | 0 | PyObject *iobj = _PyNumber_Index(args[1]); |
7721 | 0 | if (iobj != NULL) { |
7722 | 0 | ival = PyLong_AsSsize_t(iobj); |
7723 | 0 | Py_DECREF(iobj); |
7724 | 0 | } |
7725 | 0 | if (ival == -1 && PyErr_Occurred()) { |
7726 | 0 | goto exit; |
7727 | 0 | } |
7728 | 0 | length = ival; |
7729 | 0 | } |
7730 | 0 | return_value = os_read_impl(module, fd, length); |
7731 | |
|
7732 | 0 | exit: |
7733 | 0 | return return_value; |
7734 | 0 | } |
7735 | | |
7736 | | PyDoc_STRVAR(os_readinto__doc__, |
7737 | | "readinto($module, fd, buffer, /)\n" |
7738 | | "--\n" |
7739 | | "\n" |
7740 | | "Read into a buffer object from a file descriptor.\n" |
7741 | | "\n" |
7742 | | "The buffer should be mutable and bytes-like. On success, returns the number of\n" |
7743 | | "bytes read. Less bytes may be read than the size of the buffer. The underlying\n" |
7744 | | "system call will be retried when interrupted by a signal, unless the signal\n" |
7745 | | "handler raises an exception. Other errors will not be retried and an error will\n" |
7746 | | "be raised.\n" |
7747 | | "\n" |
7748 | | "Returns 0 if *fd* is at end of file or if the provided *buffer* has length 0\n" |
7749 | | "(which can be used to check for errors without reading data). Never returns\n" |
7750 | | "negative."); |
7751 | | |
7752 | | #define OS_READINTO_METHODDEF \ |
7753 | | {"readinto", _PyCFunction_CAST(os_readinto), METH_FASTCALL, os_readinto__doc__}, |
7754 | | |
7755 | | static Py_ssize_t |
7756 | | os_readinto_impl(PyObject *module, int fd, Py_buffer *buffer); |
7757 | | |
7758 | | static PyObject * |
7759 | | os_readinto(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
7760 | 0 | { |
7761 | 0 | PyObject *return_value = NULL; |
7762 | 0 | int fd; |
7763 | 0 | Py_buffer buffer = {NULL, NULL}; |
7764 | 0 | Py_ssize_t _return_value; |
7765 | |
|
7766 | 0 | if (!_PyArg_CheckPositional("readinto", nargs, 2, 2)) { |
7767 | 0 | goto exit; |
7768 | 0 | } |
7769 | 0 | fd = PyLong_AsInt(args[0]); |
7770 | 0 | if (fd == -1 && PyErr_Occurred()) { |
7771 | 0 | goto exit; |
7772 | 0 | } |
7773 | 0 | if (PyObject_GetBuffer(args[1], &buffer, PyBUF_WRITABLE) < 0) { |
7774 | 0 | _PyArg_BadArgument("readinto", "argument 2", "read-write bytes-like object", args[1]); |
7775 | 0 | goto exit; |
7776 | 0 | } |
7777 | 0 | _return_value = os_readinto_impl(module, fd, &buffer); |
7778 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
7779 | 0 | goto exit; |
7780 | 0 | } |
7781 | 0 | return_value = PyLong_FromSsize_t(_return_value); |
7782 | |
|
7783 | 0 | exit: |
7784 | | /* Cleanup for buffer */ |
7785 | 0 | if (buffer.obj) { |
7786 | 0 | PyBuffer_Release(&buffer); |
7787 | 0 | } |
7788 | |
|
7789 | 0 | return return_value; |
7790 | 0 | } |
7791 | | |
7792 | | #if defined(HAVE_READV) |
7793 | | |
7794 | | PyDoc_STRVAR(os_readv__doc__, |
7795 | | "readv($module, fd, buffers, /)\n" |
7796 | | "--\n" |
7797 | | "\n" |
7798 | | "Read from a file descriptor fd into an iterable of buffers.\n" |
7799 | | "\n" |
7800 | | "The buffers should be mutable buffers accepting bytes.\n" |
7801 | | "readv will transfer data into each buffer until it is full\n" |
7802 | | "and then move on to the next buffer in the sequence to hold\n" |
7803 | | "the rest of the data.\n" |
7804 | | "\n" |
7805 | | "readv returns the total number of bytes read,\n" |
7806 | | "which may be less than the total capacity of all the buffers."); |
7807 | | |
7808 | | #define OS_READV_METHODDEF \ |
7809 | | {"readv", _PyCFunction_CAST(os_readv), METH_FASTCALL, os_readv__doc__}, |
7810 | | |
7811 | | static Py_ssize_t |
7812 | | os_readv_impl(PyObject *module, int fd, PyObject *buffers); |
7813 | | |
7814 | | static PyObject * |
7815 | | os_readv(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
7816 | 0 | { |
7817 | 0 | PyObject *return_value = NULL; |
7818 | 0 | int fd; |
7819 | 0 | PyObject *buffers; |
7820 | 0 | Py_ssize_t _return_value; |
7821 | |
|
7822 | 0 | if (!_PyArg_CheckPositional("readv", nargs, 2, 2)) { |
7823 | 0 | goto exit; |
7824 | 0 | } |
7825 | 0 | fd = PyLong_AsInt(args[0]); |
7826 | 0 | if (fd == -1 && PyErr_Occurred()) { |
7827 | 0 | goto exit; |
7828 | 0 | } |
7829 | 0 | buffers = args[1]; |
7830 | 0 | _return_value = os_readv_impl(module, fd, buffers); |
7831 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
7832 | 0 | goto exit; |
7833 | 0 | } |
7834 | 0 | return_value = PyLong_FromSsize_t(_return_value); |
7835 | |
|
7836 | 0 | exit: |
7837 | 0 | return return_value; |
7838 | 0 | } |
7839 | | |
7840 | | #endif /* defined(HAVE_READV) */ |
7841 | | |
7842 | | #if defined(HAVE_PREAD) |
7843 | | |
7844 | | PyDoc_STRVAR(os_pread__doc__, |
7845 | | "pread($module, fd, length, offset, /)\n" |
7846 | | "--\n" |
7847 | | "\n" |
7848 | | "Read a number of bytes from a file descriptor starting at a particular offset.\n" |
7849 | | "\n" |
7850 | | "Read length bytes from file descriptor fd, starting at offset bytes from\n" |
7851 | | "the beginning of the file. The file offset remains unchanged."); |
7852 | | |
7853 | | #define OS_PREAD_METHODDEF \ |
7854 | | {"pread", _PyCFunction_CAST(os_pread), METH_FASTCALL, os_pread__doc__}, |
7855 | | |
7856 | | static PyObject * |
7857 | | os_pread_impl(PyObject *module, int fd, Py_ssize_t length, Py_off_t offset); |
7858 | | |
7859 | | static PyObject * |
7860 | | os_pread(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
7861 | 0 | { |
7862 | 0 | PyObject *return_value = NULL; |
7863 | 0 | int fd; |
7864 | 0 | Py_ssize_t length; |
7865 | 0 | Py_off_t offset; |
7866 | |
|
7867 | 0 | if (!_PyArg_CheckPositional("pread", nargs, 3, 3)) { |
7868 | 0 | goto exit; |
7869 | 0 | } |
7870 | 0 | fd = PyLong_AsInt(args[0]); |
7871 | 0 | if (fd == -1 && PyErr_Occurred()) { |
7872 | 0 | goto exit; |
7873 | 0 | } |
7874 | 0 | { |
7875 | 0 | Py_ssize_t ival = -1; |
7876 | 0 | PyObject *iobj = _PyNumber_Index(args[1]); |
7877 | 0 | if (iobj != NULL) { |
7878 | 0 | ival = PyLong_AsSsize_t(iobj); |
7879 | 0 | Py_DECREF(iobj); |
7880 | 0 | } |
7881 | 0 | if (ival == -1 && PyErr_Occurred()) { |
7882 | 0 | goto exit; |
7883 | 0 | } |
7884 | 0 | length = ival; |
7885 | 0 | } |
7886 | 0 | if (!Py_off_t_converter(args[2], &offset)) { |
7887 | 0 | goto exit; |
7888 | 0 | } |
7889 | 0 | return_value = os_pread_impl(module, fd, length, offset); |
7890 | |
|
7891 | 0 | exit: |
7892 | 0 | return return_value; |
7893 | 0 | } |
7894 | | |
7895 | | #endif /* defined(HAVE_PREAD) */ |
7896 | | |
7897 | | #if (defined(HAVE_PREADV) || defined (HAVE_PREADV2)) |
7898 | | |
7899 | | PyDoc_STRVAR(os_preadv__doc__, |
7900 | | "preadv($module, fd, buffers, offset, flags=0, /)\n" |
7901 | | "--\n" |
7902 | | "\n" |
7903 | | "Reads from a file descriptor into a number of mutable bytes-like objects.\n" |
7904 | | "\n" |
7905 | | "Combines the functionality of readv() and pread(). As readv(), it will\n" |
7906 | | "transfer data into each buffer until it is full and then move on to the next\n" |
7907 | | "buffer in the sequence to hold the rest of the data. Its fourth argument,\n" |
7908 | | "specifies the file offset at which the input operation is to be performed. It\n" |
7909 | | "will return the total number of bytes read (which can be less than the total\n" |
7910 | | "capacity of all the objects).\n" |
7911 | | "\n" |
7912 | | "The flags argument contains a bitwise OR of zero or more of the following flags:\n" |
7913 | | "\n" |
7914 | | "- RWF_HIPRI\n" |
7915 | | "- RWF_NOWAIT\n" |
7916 | | "\n" |
7917 | | "Using non-zero flags requires Linux 4.6 or newer."); |
7918 | | |
7919 | | #define OS_PREADV_METHODDEF \ |
7920 | | {"preadv", _PyCFunction_CAST(os_preadv), METH_FASTCALL, os_preadv__doc__}, |
7921 | | |
7922 | | static Py_ssize_t |
7923 | | os_preadv_impl(PyObject *module, int fd, PyObject *buffers, Py_off_t offset, |
7924 | | int flags); |
7925 | | |
7926 | | static PyObject * |
7927 | | os_preadv(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
7928 | 0 | { |
7929 | 0 | PyObject *return_value = NULL; |
7930 | 0 | int fd; |
7931 | 0 | PyObject *buffers; |
7932 | 0 | Py_off_t offset; |
7933 | 0 | int flags = 0; |
7934 | 0 | Py_ssize_t _return_value; |
7935 | |
|
7936 | 0 | if (!_PyArg_CheckPositional("preadv", nargs, 3, 4)) { |
7937 | 0 | goto exit; |
7938 | 0 | } |
7939 | 0 | fd = PyLong_AsInt(args[0]); |
7940 | 0 | if (fd == -1 && PyErr_Occurred()) { |
7941 | 0 | goto exit; |
7942 | 0 | } |
7943 | 0 | buffers = args[1]; |
7944 | 0 | if (!Py_off_t_converter(args[2], &offset)) { |
7945 | 0 | goto exit; |
7946 | 0 | } |
7947 | 0 | if (nargs < 4) { |
7948 | 0 | goto skip_optional; |
7949 | 0 | } |
7950 | 0 | flags = PyLong_AsInt(args[3]); |
7951 | 0 | if (flags == -1 && PyErr_Occurred()) { |
7952 | 0 | goto exit; |
7953 | 0 | } |
7954 | 0 | skip_optional: |
7955 | 0 | _return_value = os_preadv_impl(module, fd, buffers, offset, flags); |
7956 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
7957 | 0 | goto exit; |
7958 | 0 | } |
7959 | 0 | return_value = PyLong_FromSsize_t(_return_value); |
7960 | |
|
7961 | 0 | exit: |
7962 | 0 | return return_value; |
7963 | 0 | } |
7964 | | |
7965 | | #endif /* (defined(HAVE_PREADV) || defined (HAVE_PREADV2)) */ |
7966 | | |
7967 | | PyDoc_STRVAR(os_write__doc__, |
7968 | | "write($module, fd, data, /)\n" |
7969 | | "--\n" |
7970 | | "\n" |
7971 | | "Write a bytes object to a file descriptor."); |
7972 | | |
7973 | | #define OS_WRITE_METHODDEF \ |
7974 | | {"write", _PyCFunction_CAST(os_write), METH_FASTCALL, os_write__doc__}, |
7975 | | |
7976 | | static Py_ssize_t |
7977 | | os_write_impl(PyObject *module, int fd, Py_buffer *data); |
7978 | | |
7979 | | static PyObject * |
7980 | | os_write(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
7981 | 0 | { |
7982 | 0 | PyObject *return_value = NULL; |
7983 | 0 | int fd; |
7984 | 0 | Py_buffer data = {NULL, NULL}; |
7985 | 0 | Py_ssize_t _return_value; |
7986 | |
|
7987 | 0 | if (!_PyArg_CheckPositional("write", nargs, 2, 2)) { |
7988 | 0 | goto exit; |
7989 | 0 | } |
7990 | 0 | fd = PyLong_AsInt(args[0]); |
7991 | 0 | if (fd == -1 && PyErr_Occurred()) { |
7992 | 0 | goto exit; |
7993 | 0 | } |
7994 | 0 | if (PyObject_GetBuffer(args[1], &data, PyBUF_SIMPLE) != 0) { |
7995 | 0 | goto exit; |
7996 | 0 | } |
7997 | 0 | _return_value = os_write_impl(module, fd, &data); |
7998 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
7999 | 0 | goto exit; |
8000 | 0 | } |
8001 | 0 | return_value = PyLong_FromSsize_t(_return_value); |
8002 | |
|
8003 | 0 | exit: |
8004 | | /* Cleanup for data */ |
8005 | 0 | if (data.obj) { |
8006 | 0 | PyBuffer_Release(&data); |
8007 | 0 | } |
8008 | |
|
8009 | 0 | return return_value; |
8010 | 0 | } |
8011 | | |
8012 | | #if defined(HAVE_SENDFILE) && defined(__APPLE__) |
8013 | | |
8014 | | PyDoc_STRVAR(os_sendfile__doc__, |
8015 | | "sendfile($module, /, out_fd, in_fd, offset, count, headers=(),\n" |
8016 | | " trailers=(), flags=0)\n" |
8017 | | "--\n" |
8018 | | "\n" |
8019 | | "Copy count bytes from file descriptor in_fd to file descriptor out_fd."); |
8020 | | |
8021 | | #define OS_SENDFILE_METHODDEF \ |
8022 | | {"sendfile", _PyCFunction_CAST(os_sendfile), METH_FASTCALL|METH_KEYWORDS, os_sendfile__doc__}, |
8023 | | |
8024 | | static PyObject * |
8025 | | os_sendfile_impl(PyObject *module, int out_fd, int in_fd, Py_off_t offset, |
8026 | | Py_off_t sbytes, PyObject *headers, PyObject *trailers, |
8027 | | int flags); |
8028 | | |
8029 | | static PyObject * |
8030 | | os_sendfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
8031 | | { |
8032 | | PyObject *return_value = NULL; |
8033 | | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
8034 | | |
8035 | | #define NUM_KEYWORDS 7 |
8036 | | static struct { |
8037 | | PyGC_Head _this_is_not_used; |
8038 | | PyObject_VAR_HEAD |
8039 | | Py_hash_t ob_hash; |
8040 | | PyObject *ob_item[NUM_KEYWORDS]; |
8041 | | } _kwtuple = { |
8042 | | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
8043 | | .ob_hash = -1, |
8044 | | .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), }, |
8045 | | }; |
8046 | | #undef NUM_KEYWORDS |
8047 | | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
8048 | | |
8049 | | #else // !Py_BUILD_CORE |
8050 | | # define KWTUPLE NULL |
8051 | | #endif // !Py_BUILD_CORE |
8052 | | |
8053 | | static const char * const _keywords[] = {"out_fd", "in_fd", "offset", "count", "headers", "trailers", "flags", NULL}; |
8054 | | static _PyArg_Parser _parser = { |
8055 | | .keywords = _keywords, |
8056 | | .fname = "sendfile", |
8057 | | .kwtuple = KWTUPLE, |
8058 | | }; |
8059 | | #undef KWTUPLE |
8060 | | PyObject *argsbuf[7]; |
8061 | | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 4; |
8062 | | int out_fd; |
8063 | | int in_fd; |
8064 | | Py_off_t offset; |
8065 | | Py_off_t sbytes; |
8066 | | PyObject *headers = NULL; |
8067 | | PyObject *trailers = NULL; |
8068 | | int flags = 0; |
8069 | | |
8070 | | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
8071 | | /*minpos*/ 4, /*maxpos*/ 7, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
8072 | | if (!args) { |
8073 | | goto exit; |
8074 | | } |
8075 | | out_fd = PyLong_AsInt(args[0]); |
8076 | | if (out_fd == -1 && PyErr_Occurred()) { |
8077 | | goto exit; |
8078 | | } |
8079 | | in_fd = PyLong_AsInt(args[1]); |
8080 | | if (in_fd == -1 && PyErr_Occurred()) { |
8081 | | goto exit; |
8082 | | } |
8083 | | if (!Py_off_t_converter(args[2], &offset)) { |
8084 | | goto exit; |
8085 | | } |
8086 | | if (!Py_off_t_converter(args[3], &sbytes)) { |
8087 | | goto exit; |
8088 | | } |
8089 | | if (!noptargs) { |
8090 | | goto skip_optional_pos; |
8091 | | } |
8092 | | if (args[4]) { |
8093 | | headers = args[4]; |
8094 | | if (!--noptargs) { |
8095 | | goto skip_optional_pos; |
8096 | | } |
8097 | | } |
8098 | | if (args[5]) { |
8099 | | trailers = args[5]; |
8100 | | if (!--noptargs) { |
8101 | | goto skip_optional_pos; |
8102 | | } |
8103 | | } |
8104 | | flags = PyLong_AsInt(args[6]); |
8105 | | if (flags == -1 && PyErr_Occurred()) { |
8106 | | goto exit; |
8107 | | } |
8108 | | skip_optional_pos: |
8109 | | return_value = os_sendfile_impl(module, out_fd, in_fd, offset, sbytes, headers, trailers, flags); |
8110 | | |
8111 | | exit: |
8112 | | return return_value; |
8113 | | } |
8114 | | |
8115 | | #endif /* defined(HAVE_SENDFILE) && defined(__APPLE__) */ |
8116 | | |
8117 | | #if defined(HAVE_SENDFILE) && !defined(__APPLE__) && (defined(__FreeBSD__) || defined(__DragonFly__)) |
8118 | | |
8119 | | PyDoc_STRVAR(os_sendfile__doc__, |
8120 | | "sendfile($module, /, out_fd, in_fd, offset, count, headers=(),\n" |
8121 | | " trailers=(), flags=0)\n" |
8122 | | "--\n" |
8123 | | "\n" |
8124 | | "Copy count bytes from file descriptor in_fd to file descriptor out_fd."); |
8125 | | |
8126 | | #define OS_SENDFILE_METHODDEF \ |
8127 | | {"sendfile", _PyCFunction_CAST(os_sendfile), METH_FASTCALL|METH_KEYWORDS, os_sendfile__doc__}, |
8128 | | |
8129 | | static PyObject * |
8130 | | os_sendfile_impl(PyObject *module, int out_fd, int in_fd, Py_off_t offset, |
8131 | | Py_ssize_t count, PyObject *headers, PyObject *trailers, |
8132 | | int flags); |
8133 | | |
8134 | | static PyObject * |
8135 | | os_sendfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
8136 | | { |
8137 | | PyObject *return_value = NULL; |
8138 | | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
8139 | | |
8140 | | #define NUM_KEYWORDS 7 |
8141 | | static struct { |
8142 | | PyGC_Head _this_is_not_used; |
8143 | | PyObject_VAR_HEAD |
8144 | | Py_hash_t ob_hash; |
8145 | | PyObject *ob_item[NUM_KEYWORDS]; |
8146 | | } _kwtuple = { |
8147 | | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
8148 | | .ob_hash = -1, |
8149 | | .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), }, |
8150 | | }; |
8151 | | #undef NUM_KEYWORDS |
8152 | | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
8153 | | |
8154 | | #else // !Py_BUILD_CORE |
8155 | | # define KWTUPLE NULL |
8156 | | #endif // !Py_BUILD_CORE |
8157 | | |
8158 | | static const char * const _keywords[] = {"out_fd", "in_fd", "offset", "count", "headers", "trailers", "flags", NULL}; |
8159 | | static _PyArg_Parser _parser = { |
8160 | | .keywords = _keywords, |
8161 | | .fname = "sendfile", |
8162 | | .kwtuple = KWTUPLE, |
8163 | | }; |
8164 | | #undef KWTUPLE |
8165 | | PyObject *argsbuf[7]; |
8166 | | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 4; |
8167 | | int out_fd; |
8168 | | int in_fd; |
8169 | | Py_off_t offset; |
8170 | | Py_ssize_t count; |
8171 | | PyObject *headers = NULL; |
8172 | | PyObject *trailers = NULL; |
8173 | | int flags = 0; |
8174 | | |
8175 | | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
8176 | | /*minpos*/ 4, /*maxpos*/ 7, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
8177 | | if (!args) { |
8178 | | goto exit; |
8179 | | } |
8180 | | out_fd = PyLong_AsInt(args[0]); |
8181 | | if (out_fd == -1 && PyErr_Occurred()) { |
8182 | | goto exit; |
8183 | | } |
8184 | | in_fd = PyLong_AsInt(args[1]); |
8185 | | if (in_fd == -1 && PyErr_Occurred()) { |
8186 | | goto exit; |
8187 | | } |
8188 | | if (!Py_off_t_converter(args[2], &offset)) { |
8189 | | goto exit; |
8190 | | } |
8191 | | { |
8192 | | Py_ssize_t ival = -1; |
8193 | | PyObject *iobj = _PyNumber_Index(args[3]); |
8194 | | if (iobj != NULL) { |
8195 | | ival = PyLong_AsSsize_t(iobj); |
8196 | | Py_DECREF(iobj); |
8197 | | } |
8198 | | if (ival == -1 && PyErr_Occurred()) { |
8199 | | goto exit; |
8200 | | } |
8201 | | count = ival; |
8202 | | } |
8203 | | if (!noptargs) { |
8204 | | goto skip_optional_pos; |
8205 | | } |
8206 | | if (args[4]) { |
8207 | | headers = args[4]; |
8208 | | if (!--noptargs) { |
8209 | | goto skip_optional_pos; |
8210 | | } |
8211 | | } |
8212 | | if (args[5]) { |
8213 | | trailers = args[5]; |
8214 | | if (!--noptargs) { |
8215 | | goto skip_optional_pos; |
8216 | | } |
8217 | | } |
8218 | | flags = PyLong_AsInt(args[6]); |
8219 | | if (flags == -1 && PyErr_Occurred()) { |
8220 | | goto exit; |
8221 | | } |
8222 | | skip_optional_pos: |
8223 | | return_value = os_sendfile_impl(module, out_fd, in_fd, offset, count, headers, trailers, flags); |
8224 | | |
8225 | | exit: |
8226 | | return return_value; |
8227 | | } |
8228 | | |
8229 | | #endif /* defined(HAVE_SENDFILE) && !defined(__APPLE__) && (defined(__FreeBSD__) || defined(__DragonFly__)) */ |
8230 | | |
8231 | | #if defined(HAVE_SENDFILE) && !defined(__APPLE__) && !(defined(__FreeBSD__) || defined(__DragonFly__)) |
8232 | | |
8233 | | PyDoc_STRVAR(os_sendfile__doc__, |
8234 | | "sendfile($module, /, out_fd, in_fd, offset, count)\n" |
8235 | | "--\n" |
8236 | | "\n" |
8237 | | "Copy count bytes from file descriptor in_fd to file descriptor out_fd."); |
8238 | | |
8239 | | #define OS_SENDFILE_METHODDEF \ |
8240 | | {"sendfile", _PyCFunction_CAST(os_sendfile), METH_FASTCALL|METH_KEYWORDS, os_sendfile__doc__}, |
8241 | | |
8242 | | static PyObject * |
8243 | | os_sendfile_impl(PyObject *module, int out_fd, int in_fd, PyObject *offobj, |
8244 | | Py_ssize_t count); |
8245 | | |
8246 | | static PyObject * |
8247 | | os_sendfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
8248 | 0 | { |
8249 | 0 | PyObject *return_value = NULL; |
8250 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
8251 | |
|
8252 | 0 | #define NUM_KEYWORDS 4 |
8253 | 0 | static struct { |
8254 | 0 | PyGC_Head _this_is_not_used; |
8255 | 0 | PyObject_VAR_HEAD |
8256 | 0 | Py_hash_t ob_hash; |
8257 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
8258 | 0 | } _kwtuple = { |
8259 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
8260 | 0 | .ob_hash = -1, |
8261 | 0 | .ob_item = { &_Py_ID(out_fd), &_Py_ID(in_fd), &_Py_ID(offset), &_Py_ID(count), }, |
8262 | 0 | }; |
8263 | 0 | #undef NUM_KEYWORDS |
8264 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
8265 | |
|
8266 | | #else // !Py_BUILD_CORE |
8267 | | # define KWTUPLE NULL |
8268 | | #endif // !Py_BUILD_CORE |
8269 | |
|
8270 | 0 | static const char * const _keywords[] = {"out_fd", "in_fd", "offset", "count", NULL}; |
8271 | 0 | static _PyArg_Parser _parser = { |
8272 | 0 | .keywords = _keywords, |
8273 | 0 | .fname = "sendfile", |
8274 | 0 | .kwtuple = KWTUPLE, |
8275 | 0 | }; |
8276 | 0 | #undef KWTUPLE |
8277 | 0 | PyObject *argsbuf[4]; |
8278 | 0 | int out_fd; |
8279 | 0 | int in_fd; |
8280 | 0 | PyObject *offobj; |
8281 | 0 | Py_ssize_t count; |
8282 | |
|
8283 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
8284 | 0 | /*minpos*/ 4, /*maxpos*/ 4, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
8285 | 0 | if (!args) { |
8286 | 0 | goto exit; |
8287 | 0 | } |
8288 | 0 | out_fd = PyLong_AsInt(args[0]); |
8289 | 0 | if (out_fd == -1 && PyErr_Occurred()) { |
8290 | 0 | goto exit; |
8291 | 0 | } |
8292 | 0 | in_fd = PyLong_AsInt(args[1]); |
8293 | 0 | if (in_fd == -1 && PyErr_Occurred()) { |
8294 | 0 | goto exit; |
8295 | 0 | } |
8296 | 0 | offobj = args[2]; |
8297 | 0 | { |
8298 | 0 | Py_ssize_t ival = -1; |
8299 | 0 | PyObject *iobj = _PyNumber_Index(args[3]); |
8300 | 0 | if (iobj != NULL) { |
8301 | 0 | ival = PyLong_AsSsize_t(iobj); |
8302 | 0 | Py_DECREF(iobj); |
8303 | 0 | } |
8304 | 0 | if (ival == -1 && PyErr_Occurred()) { |
8305 | 0 | goto exit; |
8306 | 0 | } |
8307 | 0 | count = ival; |
8308 | 0 | } |
8309 | 0 | return_value = os_sendfile_impl(module, out_fd, in_fd, offobj, count); |
8310 | |
|
8311 | 0 | exit: |
8312 | 0 | return return_value; |
8313 | 0 | } |
8314 | | |
8315 | | #endif /* defined(HAVE_SENDFILE) && !defined(__APPLE__) && !(defined(__FreeBSD__) || defined(__DragonFly__)) */ |
8316 | | |
8317 | | #if defined(__APPLE__) |
8318 | | |
8319 | | PyDoc_STRVAR(os__fcopyfile__doc__, |
8320 | | "_fcopyfile($module, in_fd, out_fd, flags, /)\n" |
8321 | | "--\n" |
8322 | | "\n" |
8323 | | "Efficiently copy content or metadata of 2 regular file descriptors (macOS)."); |
8324 | | |
8325 | | #define OS__FCOPYFILE_METHODDEF \ |
8326 | | {"_fcopyfile", _PyCFunction_CAST(os__fcopyfile), METH_FASTCALL, os__fcopyfile__doc__}, |
8327 | | |
8328 | | static PyObject * |
8329 | | os__fcopyfile_impl(PyObject *module, int in_fd, int out_fd, int flags); |
8330 | | |
8331 | | static PyObject * |
8332 | | os__fcopyfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
8333 | | { |
8334 | | PyObject *return_value = NULL; |
8335 | | int in_fd; |
8336 | | int out_fd; |
8337 | | int flags; |
8338 | | |
8339 | | if (!_PyArg_CheckPositional("_fcopyfile", nargs, 3, 3)) { |
8340 | | goto exit; |
8341 | | } |
8342 | | in_fd = PyLong_AsInt(args[0]); |
8343 | | if (in_fd == -1 && PyErr_Occurred()) { |
8344 | | goto exit; |
8345 | | } |
8346 | | out_fd = PyLong_AsInt(args[1]); |
8347 | | if (out_fd == -1 && PyErr_Occurred()) { |
8348 | | goto exit; |
8349 | | } |
8350 | | flags = PyLong_AsInt(args[2]); |
8351 | | if (flags == -1 && PyErr_Occurred()) { |
8352 | | goto exit; |
8353 | | } |
8354 | | return_value = os__fcopyfile_impl(module, in_fd, out_fd, flags); |
8355 | | |
8356 | | exit: |
8357 | | return return_value; |
8358 | | } |
8359 | | |
8360 | | #endif /* defined(__APPLE__) */ |
8361 | | |
8362 | | PyDoc_STRVAR(os_fstat__doc__, |
8363 | | "fstat($module, /, fd)\n" |
8364 | | "--\n" |
8365 | | "\n" |
8366 | | "Perform a stat system call on the given file descriptor.\n" |
8367 | | "\n" |
8368 | | "Like stat(), but for an open file descriptor.\n" |
8369 | | "Equivalent to os.stat(fd)."); |
8370 | | |
8371 | | #define OS_FSTAT_METHODDEF \ |
8372 | | {"fstat", _PyCFunction_CAST(os_fstat), METH_FASTCALL|METH_KEYWORDS, os_fstat__doc__}, |
8373 | | |
8374 | | static PyObject * |
8375 | | os_fstat_impl(PyObject *module, int fd); |
8376 | | |
8377 | | static PyObject * |
8378 | | os_fstat(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
8379 | 0 | { |
8380 | 0 | PyObject *return_value = NULL; |
8381 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
8382 | |
|
8383 | 0 | #define NUM_KEYWORDS 1 |
8384 | 0 | static struct { |
8385 | 0 | PyGC_Head _this_is_not_used; |
8386 | 0 | PyObject_VAR_HEAD |
8387 | 0 | Py_hash_t ob_hash; |
8388 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
8389 | 0 | } _kwtuple = { |
8390 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
8391 | 0 | .ob_hash = -1, |
8392 | 0 | .ob_item = { &_Py_ID(fd), }, |
8393 | 0 | }; |
8394 | 0 | #undef NUM_KEYWORDS |
8395 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
8396 | |
|
8397 | | #else // !Py_BUILD_CORE |
8398 | | # define KWTUPLE NULL |
8399 | | #endif // !Py_BUILD_CORE |
8400 | |
|
8401 | 0 | static const char * const _keywords[] = {"fd", NULL}; |
8402 | 0 | static _PyArg_Parser _parser = { |
8403 | 0 | .keywords = _keywords, |
8404 | 0 | .fname = "fstat", |
8405 | 0 | .kwtuple = KWTUPLE, |
8406 | 0 | }; |
8407 | 0 | #undef KWTUPLE |
8408 | 0 | PyObject *argsbuf[1]; |
8409 | 0 | int fd; |
8410 | |
|
8411 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
8412 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
8413 | 0 | if (!args) { |
8414 | 0 | goto exit; |
8415 | 0 | } |
8416 | 0 | fd = PyLong_AsInt(args[0]); |
8417 | 0 | if (fd == -1 && PyErr_Occurred()) { |
8418 | 0 | goto exit; |
8419 | 0 | } |
8420 | 0 | return_value = os_fstat_impl(module, fd); |
8421 | |
|
8422 | 0 | exit: |
8423 | 0 | return return_value; |
8424 | 0 | } |
8425 | | |
8426 | | PyDoc_STRVAR(os_isatty__doc__, |
8427 | | "isatty($module, fd, /)\n" |
8428 | | "--\n" |
8429 | | "\n" |
8430 | | "Return True if the fd is connected to a terminal.\n" |
8431 | | "\n" |
8432 | | "Return True if the file descriptor is an open file descriptor\n" |
8433 | | "connected to the slave end of a terminal."); |
8434 | | |
8435 | | #define OS_ISATTY_METHODDEF \ |
8436 | | {"isatty", (PyCFunction)os_isatty, METH_O, os_isatty__doc__}, |
8437 | | |
8438 | | static int |
8439 | | os_isatty_impl(PyObject *module, int fd); |
8440 | | |
8441 | | static PyObject * |
8442 | | os_isatty(PyObject *module, PyObject *arg) |
8443 | 0 | { |
8444 | 0 | PyObject *return_value = NULL; |
8445 | 0 | int fd; |
8446 | 0 | int _return_value; |
8447 | |
|
8448 | 0 | fd = PyLong_AsInt(arg); |
8449 | 0 | if (fd == -1 && PyErr_Occurred()) { |
8450 | 0 | goto exit; |
8451 | 0 | } |
8452 | 0 | _return_value = os_isatty_impl(module, fd); |
8453 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
8454 | 0 | goto exit; |
8455 | 0 | } |
8456 | 0 | return_value = PyBool_FromLong((long)_return_value); |
8457 | |
|
8458 | 0 | exit: |
8459 | 0 | return return_value; |
8460 | 0 | } |
8461 | | |
8462 | | #if defined(HAVE_PIPE) |
8463 | | |
8464 | | PyDoc_STRVAR(os_pipe__doc__, |
8465 | | "pipe($module, /)\n" |
8466 | | "--\n" |
8467 | | "\n" |
8468 | | "Create a pipe.\n" |
8469 | | "\n" |
8470 | | "Returns a tuple of two file descriptors:\n" |
8471 | | " (read_fd, write_fd)"); |
8472 | | |
8473 | | #define OS_PIPE_METHODDEF \ |
8474 | | {"pipe", (PyCFunction)os_pipe, METH_NOARGS, os_pipe__doc__}, |
8475 | | |
8476 | | static PyObject * |
8477 | | os_pipe_impl(PyObject *module); |
8478 | | |
8479 | | static PyObject * |
8480 | | os_pipe(PyObject *module, PyObject *Py_UNUSED(ignored)) |
8481 | 0 | { |
8482 | 0 | return os_pipe_impl(module); |
8483 | 0 | } |
8484 | | |
8485 | | #endif /* defined(HAVE_PIPE) */ |
8486 | | |
8487 | | #if defined(HAVE_PIPE2) |
8488 | | |
8489 | | PyDoc_STRVAR(os_pipe2__doc__, |
8490 | | "pipe2($module, flags, /)\n" |
8491 | | "--\n" |
8492 | | "\n" |
8493 | | "Create a pipe with flags set atomically.\n" |
8494 | | "\n" |
8495 | | "Returns a tuple of two file descriptors:\n" |
8496 | | " (read_fd, write_fd)\n" |
8497 | | "\n" |
8498 | | "flags can be constructed by ORing together one or more of these values:\n" |
8499 | | "O_NONBLOCK, O_CLOEXEC."); |
8500 | | |
8501 | | #define OS_PIPE2_METHODDEF \ |
8502 | | {"pipe2", (PyCFunction)os_pipe2, METH_O, os_pipe2__doc__}, |
8503 | | |
8504 | | static PyObject * |
8505 | | os_pipe2_impl(PyObject *module, int flags); |
8506 | | |
8507 | | static PyObject * |
8508 | | os_pipe2(PyObject *module, PyObject *arg) |
8509 | 0 | { |
8510 | 0 | PyObject *return_value = NULL; |
8511 | 0 | int flags; |
8512 | |
|
8513 | 0 | flags = PyLong_AsInt(arg); |
8514 | 0 | if (flags == -1 && PyErr_Occurred()) { |
8515 | 0 | goto exit; |
8516 | 0 | } |
8517 | 0 | return_value = os_pipe2_impl(module, flags); |
8518 | |
|
8519 | 0 | exit: |
8520 | 0 | return return_value; |
8521 | 0 | } |
8522 | | |
8523 | | #endif /* defined(HAVE_PIPE2) */ |
8524 | | |
8525 | | #if defined(HAVE_WRITEV) |
8526 | | |
8527 | | PyDoc_STRVAR(os_writev__doc__, |
8528 | | "writev($module, fd, buffers, /)\n" |
8529 | | "--\n" |
8530 | | "\n" |
8531 | | "Iterate over buffers, and write the contents of each to a file descriptor.\n" |
8532 | | "\n" |
8533 | | "Returns the total number of bytes written.\n" |
8534 | | "buffers must be a sequence of bytes-like objects."); |
8535 | | |
8536 | | #define OS_WRITEV_METHODDEF \ |
8537 | | {"writev", _PyCFunction_CAST(os_writev), METH_FASTCALL, os_writev__doc__}, |
8538 | | |
8539 | | static Py_ssize_t |
8540 | | os_writev_impl(PyObject *module, int fd, PyObject *buffers); |
8541 | | |
8542 | | static PyObject * |
8543 | | os_writev(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
8544 | 0 | { |
8545 | 0 | PyObject *return_value = NULL; |
8546 | 0 | int fd; |
8547 | 0 | PyObject *buffers; |
8548 | 0 | Py_ssize_t _return_value; |
8549 | |
|
8550 | 0 | if (!_PyArg_CheckPositional("writev", nargs, 2, 2)) { |
8551 | 0 | goto exit; |
8552 | 0 | } |
8553 | 0 | fd = PyLong_AsInt(args[0]); |
8554 | 0 | if (fd == -1 && PyErr_Occurred()) { |
8555 | 0 | goto exit; |
8556 | 0 | } |
8557 | 0 | buffers = args[1]; |
8558 | 0 | _return_value = os_writev_impl(module, fd, buffers); |
8559 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
8560 | 0 | goto exit; |
8561 | 0 | } |
8562 | 0 | return_value = PyLong_FromSsize_t(_return_value); |
8563 | |
|
8564 | 0 | exit: |
8565 | 0 | return return_value; |
8566 | 0 | } |
8567 | | |
8568 | | #endif /* defined(HAVE_WRITEV) */ |
8569 | | |
8570 | | #if defined(HAVE_PWRITE) |
8571 | | |
8572 | | PyDoc_STRVAR(os_pwrite__doc__, |
8573 | | "pwrite($module, fd, buffer, offset, /)\n" |
8574 | | "--\n" |
8575 | | "\n" |
8576 | | "Write bytes to a file descriptor starting at a particular offset.\n" |
8577 | | "\n" |
8578 | | "Write buffer to fd, starting at offset bytes from the beginning of\n" |
8579 | | "the file. Returns the number of bytes written. Does not change the\n" |
8580 | | "current file offset."); |
8581 | | |
8582 | | #define OS_PWRITE_METHODDEF \ |
8583 | | {"pwrite", _PyCFunction_CAST(os_pwrite), METH_FASTCALL, os_pwrite__doc__}, |
8584 | | |
8585 | | static Py_ssize_t |
8586 | | os_pwrite_impl(PyObject *module, int fd, Py_buffer *buffer, Py_off_t offset); |
8587 | | |
8588 | | static PyObject * |
8589 | | os_pwrite(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
8590 | 0 | { |
8591 | 0 | PyObject *return_value = NULL; |
8592 | 0 | int fd; |
8593 | 0 | Py_buffer buffer = {NULL, NULL}; |
8594 | 0 | Py_off_t offset; |
8595 | 0 | Py_ssize_t _return_value; |
8596 | |
|
8597 | 0 | if (!_PyArg_CheckPositional("pwrite", nargs, 3, 3)) { |
8598 | 0 | goto exit; |
8599 | 0 | } |
8600 | 0 | fd = PyLong_AsInt(args[0]); |
8601 | 0 | if (fd == -1 && PyErr_Occurred()) { |
8602 | 0 | goto exit; |
8603 | 0 | } |
8604 | 0 | if (PyObject_GetBuffer(args[1], &buffer, PyBUF_SIMPLE) != 0) { |
8605 | 0 | goto exit; |
8606 | 0 | } |
8607 | 0 | if (!Py_off_t_converter(args[2], &offset)) { |
8608 | 0 | goto exit; |
8609 | 0 | } |
8610 | 0 | _return_value = os_pwrite_impl(module, fd, &buffer, offset); |
8611 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
8612 | 0 | goto exit; |
8613 | 0 | } |
8614 | 0 | return_value = PyLong_FromSsize_t(_return_value); |
8615 | |
|
8616 | 0 | exit: |
8617 | | /* Cleanup for buffer */ |
8618 | 0 | if (buffer.obj) { |
8619 | 0 | PyBuffer_Release(&buffer); |
8620 | 0 | } |
8621 | |
|
8622 | 0 | return return_value; |
8623 | 0 | } |
8624 | | |
8625 | | #endif /* defined(HAVE_PWRITE) */ |
8626 | | |
8627 | | #if (defined(HAVE_PWRITEV) || defined (HAVE_PWRITEV2)) |
8628 | | |
8629 | | PyDoc_STRVAR(os_pwritev__doc__, |
8630 | | "pwritev($module, fd, buffers, offset, flags=0, /)\n" |
8631 | | "--\n" |
8632 | | "\n" |
8633 | | "Writes the contents of bytes-like objects to a file descriptor at a given offset.\n" |
8634 | | "\n" |
8635 | | "Combines the functionality of writev() and pwrite(). All buffers must be a sequence\n" |
8636 | | "of bytes-like objects. Buffers are processed in array order. Entire contents of first\n" |
8637 | | "buffer is written before proceeding to second, and so on. The operating system may\n" |
8638 | | "set a limit (sysconf() value SC_IOV_MAX) on the number of buffers that can be used.\n" |
8639 | | "This function writes the contents of each object to the file descriptor and returns\n" |
8640 | | "the total number of bytes written.\n" |
8641 | | "\n" |
8642 | | "The flags argument contains a bitwise OR of zero or more of the following flags:\n" |
8643 | | "\n" |
8644 | | "- RWF_DSYNC\n" |
8645 | | "- RWF_SYNC\n" |
8646 | | "- RWF_APPEND\n" |
8647 | | "\n" |
8648 | | "Using non-zero flags requires Linux 4.7 or newer."); |
8649 | | |
8650 | | #define OS_PWRITEV_METHODDEF \ |
8651 | | {"pwritev", _PyCFunction_CAST(os_pwritev), METH_FASTCALL, os_pwritev__doc__}, |
8652 | | |
8653 | | static Py_ssize_t |
8654 | | os_pwritev_impl(PyObject *module, int fd, PyObject *buffers, Py_off_t offset, |
8655 | | int flags); |
8656 | | |
8657 | | static PyObject * |
8658 | | os_pwritev(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
8659 | 0 | { |
8660 | 0 | PyObject *return_value = NULL; |
8661 | 0 | int fd; |
8662 | 0 | PyObject *buffers; |
8663 | 0 | Py_off_t offset; |
8664 | 0 | int flags = 0; |
8665 | 0 | Py_ssize_t _return_value; |
8666 | |
|
8667 | 0 | if (!_PyArg_CheckPositional("pwritev", nargs, 3, 4)) { |
8668 | 0 | goto exit; |
8669 | 0 | } |
8670 | 0 | fd = PyLong_AsInt(args[0]); |
8671 | 0 | if (fd == -1 && PyErr_Occurred()) { |
8672 | 0 | goto exit; |
8673 | 0 | } |
8674 | 0 | buffers = args[1]; |
8675 | 0 | if (!Py_off_t_converter(args[2], &offset)) { |
8676 | 0 | goto exit; |
8677 | 0 | } |
8678 | 0 | if (nargs < 4) { |
8679 | 0 | goto skip_optional; |
8680 | 0 | } |
8681 | 0 | flags = PyLong_AsInt(args[3]); |
8682 | 0 | if (flags == -1 && PyErr_Occurred()) { |
8683 | 0 | goto exit; |
8684 | 0 | } |
8685 | 0 | skip_optional: |
8686 | 0 | _return_value = os_pwritev_impl(module, fd, buffers, offset, flags); |
8687 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
8688 | 0 | goto exit; |
8689 | 0 | } |
8690 | 0 | return_value = PyLong_FromSsize_t(_return_value); |
8691 | |
|
8692 | 0 | exit: |
8693 | 0 | return return_value; |
8694 | 0 | } |
8695 | | |
8696 | | #endif /* (defined(HAVE_PWRITEV) || defined (HAVE_PWRITEV2)) */ |
8697 | | |
8698 | | #if defined(HAVE_COPY_FILE_RANGE) |
8699 | | |
8700 | | PyDoc_STRVAR(os_copy_file_range__doc__, |
8701 | | "copy_file_range($module, /, src, dst, count, offset_src=None,\n" |
8702 | | " offset_dst=None)\n" |
8703 | | "--\n" |
8704 | | "\n" |
8705 | | "Copy count bytes from one file descriptor to another.\n" |
8706 | | "\n" |
8707 | | " src\n" |
8708 | | " Source file descriptor.\n" |
8709 | | " dst\n" |
8710 | | " Destination file descriptor.\n" |
8711 | | " count\n" |
8712 | | " Number of bytes to copy.\n" |
8713 | | " offset_src\n" |
8714 | | " Starting offset in src.\n" |
8715 | | " offset_dst\n" |
8716 | | " Starting offset in dst.\n" |
8717 | | "\n" |
8718 | | "If offset_src is None, then src is read from the current position;\n" |
8719 | | "respectively for offset_dst."); |
8720 | | |
8721 | | #define OS_COPY_FILE_RANGE_METHODDEF \ |
8722 | | {"copy_file_range", _PyCFunction_CAST(os_copy_file_range), METH_FASTCALL|METH_KEYWORDS, os_copy_file_range__doc__}, |
8723 | | |
8724 | | static PyObject * |
8725 | | os_copy_file_range_impl(PyObject *module, int src, int dst, Py_ssize_t count, |
8726 | | PyObject *offset_src, PyObject *offset_dst); |
8727 | | |
8728 | | static PyObject * |
8729 | | os_copy_file_range(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
8730 | 0 | { |
8731 | 0 | PyObject *return_value = NULL; |
8732 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
8733 | |
|
8734 | 0 | #define NUM_KEYWORDS 5 |
8735 | 0 | static struct { |
8736 | 0 | PyGC_Head _this_is_not_used; |
8737 | 0 | PyObject_VAR_HEAD |
8738 | 0 | Py_hash_t ob_hash; |
8739 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
8740 | 0 | } _kwtuple = { |
8741 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
8742 | 0 | .ob_hash = -1, |
8743 | 0 | .ob_item = { &_Py_ID(src), &_Py_ID(dst), &_Py_ID(count), &_Py_ID(offset_src), &_Py_ID(offset_dst), }, |
8744 | 0 | }; |
8745 | 0 | #undef NUM_KEYWORDS |
8746 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
8747 | |
|
8748 | | #else // !Py_BUILD_CORE |
8749 | | # define KWTUPLE NULL |
8750 | | #endif // !Py_BUILD_CORE |
8751 | |
|
8752 | 0 | static const char * const _keywords[] = {"src", "dst", "count", "offset_src", "offset_dst", NULL}; |
8753 | 0 | static _PyArg_Parser _parser = { |
8754 | 0 | .keywords = _keywords, |
8755 | 0 | .fname = "copy_file_range", |
8756 | 0 | .kwtuple = KWTUPLE, |
8757 | 0 | }; |
8758 | 0 | #undef KWTUPLE |
8759 | 0 | PyObject *argsbuf[5]; |
8760 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3; |
8761 | 0 | int src; |
8762 | 0 | int dst; |
8763 | 0 | Py_ssize_t count; |
8764 | 0 | PyObject *offset_src = Py_None; |
8765 | 0 | PyObject *offset_dst = Py_None; |
8766 | |
|
8767 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
8768 | 0 | /*minpos*/ 3, /*maxpos*/ 5, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
8769 | 0 | if (!args) { |
8770 | 0 | goto exit; |
8771 | 0 | } |
8772 | 0 | src = PyLong_AsInt(args[0]); |
8773 | 0 | if (src == -1 && PyErr_Occurred()) { |
8774 | 0 | goto exit; |
8775 | 0 | } |
8776 | 0 | dst = PyLong_AsInt(args[1]); |
8777 | 0 | if (dst == -1 && PyErr_Occurred()) { |
8778 | 0 | goto exit; |
8779 | 0 | } |
8780 | 0 | { |
8781 | 0 | Py_ssize_t ival = -1; |
8782 | 0 | PyObject *iobj = _PyNumber_Index(args[2]); |
8783 | 0 | if (iobj != NULL) { |
8784 | 0 | ival = PyLong_AsSsize_t(iobj); |
8785 | 0 | Py_DECREF(iobj); |
8786 | 0 | } |
8787 | 0 | if (ival == -1 && PyErr_Occurred()) { |
8788 | 0 | goto exit; |
8789 | 0 | } |
8790 | 0 | count = ival; |
8791 | 0 | } |
8792 | 0 | if (!noptargs) { |
8793 | 0 | goto skip_optional_pos; |
8794 | 0 | } |
8795 | 0 | if (args[3]) { |
8796 | 0 | offset_src = args[3]; |
8797 | 0 | if (!--noptargs) { |
8798 | 0 | goto skip_optional_pos; |
8799 | 0 | } |
8800 | 0 | } |
8801 | 0 | offset_dst = args[4]; |
8802 | 0 | skip_optional_pos: |
8803 | 0 | return_value = os_copy_file_range_impl(module, src, dst, count, offset_src, offset_dst); |
8804 | |
|
8805 | 0 | exit: |
8806 | 0 | return return_value; |
8807 | 0 | } |
8808 | | |
8809 | | #endif /* defined(HAVE_COPY_FILE_RANGE) */ |
8810 | | |
8811 | | #if ((defined(HAVE_SPLICE) && !defined(_AIX))) |
8812 | | |
8813 | | PyDoc_STRVAR(os_splice__doc__, |
8814 | | "splice($module, /, src, dst, count, offset_src=None, offset_dst=None,\n" |
8815 | | " flags=0)\n" |
8816 | | "--\n" |
8817 | | "\n" |
8818 | | "Transfer count bytes from one pipe to a descriptor or vice versa.\n" |
8819 | | "\n" |
8820 | | " src\n" |
8821 | | " Source file descriptor.\n" |
8822 | | " dst\n" |
8823 | | " Destination file descriptor.\n" |
8824 | | " count\n" |
8825 | | " Number of bytes to copy.\n" |
8826 | | " offset_src\n" |
8827 | | " Starting offset in src.\n" |
8828 | | " offset_dst\n" |
8829 | | " Starting offset in dst.\n" |
8830 | | " flags\n" |
8831 | | " Flags to modify the semantics of the call.\n" |
8832 | | "\n" |
8833 | | "If offset_src is None, then src is read from the current position;\n" |
8834 | | "respectively for offset_dst. The offset associated to the file\n" |
8835 | | "descriptor that refers to a pipe must be None."); |
8836 | | |
8837 | | #define OS_SPLICE_METHODDEF \ |
8838 | | {"splice", _PyCFunction_CAST(os_splice), METH_FASTCALL|METH_KEYWORDS, os_splice__doc__}, |
8839 | | |
8840 | | static PyObject * |
8841 | | os_splice_impl(PyObject *module, int src, int dst, Py_ssize_t count, |
8842 | | PyObject *offset_src, PyObject *offset_dst, |
8843 | | unsigned int flags); |
8844 | | |
8845 | | static PyObject * |
8846 | | os_splice(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
8847 | 0 | { |
8848 | 0 | PyObject *return_value = NULL; |
8849 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
8850 | |
|
8851 | 0 | #define NUM_KEYWORDS 6 |
8852 | 0 | static struct { |
8853 | 0 | PyGC_Head _this_is_not_used; |
8854 | 0 | PyObject_VAR_HEAD |
8855 | 0 | Py_hash_t ob_hash; |
8856 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
8857 | 0 | } _kwtuple = { |
8858 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
8859 | 0 | .ob_hash = -1, |
8860 | 0 | .ob_item = { &_Py_ID(src), &_Py_ID(dst), &_Py_ID(count), &_Py_ID(offset_src), &_Py_ID(offset_dst), &_Py_ID(flags), }, |
8861 | 0 | }; |
8862 | 0 | #undef NUM_KEYWORDS |
8863 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
8864 | |
|
8865 | | #else // !Py_BUILD_CORE |
8866 | | # define KWTUPLE NULL |
8867 | | #endif // !Py_BUILD_CORE |
8868 | |
|
8869 | 0 | static const char * const _keywords[] = {"src", "dst", "count", "offset_src", "offset_dst", "flags", NULL}; |
8870 | 0 | static _PyArg_Parser _parser = { |
8871 | 0 | .keywords = _keywords, |
8872 | 0 | .fname = "splice", |
8873 | 0 | .kwtuple = KWTUPLE, |
8874 | 0 | }; |
8875 | 0 | #undef KWTUPLE |
8876 | 0 | PyObject *argsbuf[6]; |
8877 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3; |
8878 | 0 | int src; |
8879 | 0 | int dst; |
8880 | 0 | Py_ssize_t count; |
8881 | 0 | PyObject *offset_src = Py_None; |
8882 | 0 | PyObject *offset_dst = Py_None; |
8883 | 0 | unsigned int flags = 0; |
8884 | |
|
8885 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
8886 | 0 | /*minpos*/ 3, /*maxpos*/ 6, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
8887 | 0 | if (!args) { |
8888 | 0 | goto exit; |
8889 | 0 | } |
8890 | 0 | src = PyLong_AsInt(args[0]); |
8891 | 0 | if (src == -1 && PyErr_Occurred()) { |
8892 | 0 | goto exit; |
8893 | 0 | } |
8894 | 0 | dst = PyLong_AsInt(args[1]); |
8895 | 0 | if (dst == -1 && PyErr_Occurred()) { |
8896 | 0 | goto exit; |
8897 | 0 | } |
8898 | 0 | { |
8899 | 0 | Py_ssize_t ival = -1; |
8900 | 0 | PyObject *iobj = _PyNumber_Index(args[2]); |
8901 | 0 | if (iobj != NULL) { |
8902 | 0 | ival = PyLong_AsSsize_t(iobj); |
8903 | 0 | Py_DECREF(iobj); |
8904 | 0 | } |
8905 | 0 | if (ival == -1 && PyErr_Occurred()) { |
8906 | 0 | goto exit; |
8907 | 0 | } |
8908 | 0 | count = ival; |
8909 | 0 | } |
8910 | 0 | if (!noptargs) { |
8911 | 0 | goto skip_optional_pos; |
8912 | 0 | } |
8913 | 0 | if (args[3]) { |
8914 | 0 | offset_src = args[3]; |
8915 | 0 | if (!--noptargs) { |
8916 | 0 | goto skip_optional_pos; |
8917 | 0 | } |
8918 | 0 | } |
8919 | 0 | if (args[4]) { |
8920 | 0 | offset_dst = args[4]; |
8921 | 0 | if (!--noptargs) { |
8922 | 0 | goto skip_optional_pos; |
8923 | 0 | } |
8924 | 0 | } |
8925 | 0 | if (!_PyLong_UnsignedInt_Converter(args[5], &flags)) { |
8926 | 0 | goto exit; |
8927 | 0 | } |
8928 | 0 | skip_optional_pos: |
8929 | 0 | return_value = os_splice_impl(module, src, dst, count, offset_src, offset_dst, flags); |
8930 | |
|
8931 | 0 | exit: |
8932 | 0 | return return_value; |
8933 | 0 | } |
8934 | | |
8935 | | #endif /* ((defined(HAVE_SPLICE) && !defined(_AIX))) */ |
8936 | | |
8937 | | #if defined(HAVE_MKFIFO) |
8938 | | |
8939 | | PyDoc_STRVAR(os_mkfifo__doc__, |
8940 | | "mkfifo($module, /, path, mode=438, *, dir_fd=None)\n" |
8941 | | "--\n" |
8942 | | "\n" |
8943 | | "Create a \"fifo\" (a POSIX named pipe).\n" |
8944 | | "\n" |
8945 | | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
8946 | | " and path should be relative; path will then be relative to that directory.\n" |
8947 | | "dir_fd may not be implemented on your platform.\n" |
8948 | | " If it is unavailable, using it will raise a NotImplementedError."); |
8949 | | |
8950 | | #define OS_MKFIFO_METHODDEF \ |
8951 | | {"mkfifo", _PyCFunction_CAST(os_mkfifo), METH_FASTCALL|METH_KEYWORDS, os_mkfifo__doc__}, |
8952 | | |
8953 | | static PyObject * |
8954 | | os_mkfifo_impl(PyObject *module, path_t *path, int mode, int dir_fd); |
8955 | | |
8956 | | static PyObject * |
8957 | | os_mkfifo(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
8958 | 0 | { |
8959 | 0 | PyObject *return_value = NULL; |
8960 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
8961 | |
|
8962 | 0 | #define NUM_KEYWORDS 3 |
8963 | 0 | static struct { |
8964 | 0 | PyGC_Head _this_is_not_used; |
8965 | 0 | PyObject_VAR_HEAD |
8966 | 0 | Py_hash_t ob_hash; |
8967 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
8968 | 0 | } _kwtuple = { |
8969 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
8970 | 0 | .ob_hash = -1, |
8971 | 0 | .ob_item = { &_Py_ID(path), &_Py_ID(mode), &_Py_ID(dir_fd), }, |
8972 | 0 | }; |
8973 | 0 | #undef NUM_KEYWORDS |
8974 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
8975 | |
|
8976 | | #else // !Py_BUILD_CORE |
8977 | | # define KWTUPLE NULL |
8978 | | #endif // !Py_BUILD_CORE |
8979 | |
|
8980 | 0 | static const char * const _keywords[] = {"path", "mode", "dir_fd", NULL}; |
8981 | 0 | static _PyArg_Parser _parser = { |
8982 | 0 | .keywords = _keywords, |
8983 | 0 | .fname = "mkfifo", |
8984 | 0 | .kwtuple = KWTUPLE, |
8985 | 0 | }; |
8986 | 0 | #undef KWTUPLE |
8987 | 0 | PyObject *argsbuf[3]; |
8988 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
8989 | 0 | path_t path = PATH_T_INITIALIZE_P("mkfifo", "path", 0, 0, 0, 0); |
8990 | 0 | int mode = 438; |
8991 | 0 | int dir_fd = DEFAULT_DIR_FD; |
8992 | |
|
8993 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
8994 | 0 | /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
8995 | 0 | if (!args) { |
8996 | 0 | goto exit; |
8997 | 0 | } |
8998 | 0 | if (!path_converter(args[0], &path)) { |
8999 | 0 | goto exit; |
9000 | 0 | } |
9001 | 0 | if (!noptargs) { |
9002 | 0 | goto skip_optional_pos; |
9003 | 0 | } |
9004 | 0 | if (args[1]) { |
9005 | 0 | mode = PyLong_AsInt(args[1]); |
9006 | 0 | if (mode == -1 && PyErr_Occurred()) { |
9007 | 0 | goto exit; |
9008 | 0 | } |
9009 | 0 | if (!--noptargs) { |
9010 | 0 | goto skip_optional_pos; |
9011 | 0 | } |
9012 | 0 | } |
9013 | 0 | skip_optional_pos: |
9014 | 0 | if (!noptargs) { |
9015 | 0 | goto skip_optional_kwonly; |
9016 | 0 | } |
9017 | 0 | if (!MKFIFOAT_DIR_FD_CONVERTER(args[2], &dir_fd)) { |
9018 | 0 | goto exit; |
9019 | 0 | } |
9020 | 0 | skip_optional_kwonly: |
9021 | 0 | return_value = os_mkfifo_impl(module, &path, mode, dir_fd); |
9022 | |
|
9023 | 0 | exit: |
9024 | | /* Cleanup for path */ |
9025 | 0 | path_cleanup(&path); |
9026 | |
|
9027 | 0 | return return_value; |
9028 | 0 | } |
9029 | | |
9030 | | #endif /* defined(HAVE_MKFIFO) */ |
9031 | | |
9032 | | #if (defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV)) |
9033 | | |
9034 | | PyDoc_STRVAR(os_mknod__doc__, |
9035 | | "mknod($module, /, path, mode=384, device=0, *, dir_fd=None)\n" |
9036 | | "--\n" |
9037 | | "\n" |
9038 | | "Create a node in the file system.\n" |
9039 | | "\n" |
9040 | | "Create a node in the file system (file, device special file or named pipe)\n" |
9041 | | "at path. mode specifies both the permissions to use and the\n" |
9042 | | "type of node to be created, being combined (bitwise OR) with one of\n" |
9043 | | "S_IFREG, S_IFCHR, S_IFBLK, and S_IFIFO. If S_IFCHR or S_IFBLK is set on mode,\n" |
9044 | | "device defines the newly created device special file (probably using\n" |
9045 | | "os.makedev()). Otherwise device is ignored.\n" |
9046 | | "\n" |
9047 | | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
9048 | | " and path should be relative; path will then be relative to that directory.\n" |
9049 | | "dir_fd may not be implemented on your platform.\n" |
9050 | | " If it is unavailable, using it will raise a NotImplementedError."); |
9051 | | |
9052 | | #define OS_MKNOD_METHODDEF \ |
9053 | | {"mknod", _PyCFunction_CAST(os_mknod), METH_FASTCALL|METH_KEYWORDS, os_mknod__doc__}, |
9054 | | |
9055 | | static PyObject * |
9056 | | os_mknod_impl(PyObject *module, path_t *path, int mode, dev_t device, |
9057 | | int dir_fd); |
9058 | | |
9059 | | static PyObject * |
9060 | | os_mknod(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
9061 | 0 | { |
9062 | 0 | PyObject *return_value = NULL; |
9063 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
9064 | |
|
9065 | 0 | #define NUM_KEYWORDS 4 |
9066 | 0 | static struct { |
9067 | 0 | PyGC_Head _this_is_not_used; |
9068 | 0 | PyObject_VAR_HEAD |
9069 | 0 | Py_hash_t ob_hash; |
9070 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
9071 | 0 | } _kwtuple = { |
9072 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
9073 | 0 | .ob_hash = -1, |
9074 | 0 | .ob_item = { &_Py_ID(path), &_Py_ID(mode), &_Py_ID(device), &_Py_ID(dir_fd), }, |
9075 | 0 | }; |
9076 | 0 | #undef NUM_KEYWORDS |
9077 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
9078 | |
|
9079 | | #else // !Py_BUILD_CORE |
9080 | | # define KWTUPLE NULL |
9081 | | #endif // !Py_BUILD_CORE |
9082 | |
|
9083 | 0 | static const char * const _keywords[] = {"path", "mode", "device", "dir_fd", NULL}; |
9084 | 0 | static _PyArg_Parser _parser = { |
9085 | 0 | .keywords = _keywords, |
9086 | 0 | .fname = "mknod", |
9087 | 0 | .kwtuple = KWTUPLE, |
9088 | 0 | }; |
9089 | 0 | #undef KWTUPLE |
9090 | 0 | PyObject *argsbuf[4]; |
9091 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
9092 | 0 | path_t path = PATH_T_INITIALIZE_P("mknod", "path", 0, 0, 0, 0); |
9093 | 0 | int mode = 384; |
9094 | 0 | dev_t device = 0; |
9095 | 0 | int dir_fd = DEFAULT_DIR_FD; |
9096 | |
|
9097 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
9098 | 0 | /*minpos*/ 1, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
9099 | 0 | if (!args) { |
9100 | 0 | goto exit; |
9101 | 0 | } |
9102 | 0 | if (!path_converter(args[0], &path)) { |
9103 | 0 | goto exit; |
9104 | 0 | } |
9105 | 0 | if (!noptargs) { |
9106 | 0 | goto skip_optional_pos; |
9107 | 0 | } |
9108 | 0 | if (args[1]) { |
9109 | 0 | mode = PyLong_AsInt(args[1]); |
9110 | 0 | if (mode == -1 && PyErr_Occurred()) { |
9111 | 0 | goto exit; |
9112 | 0 | } |
9113 | 0 | if (!--noptargs) { |
9114 | 0 | goto skip_optional_pos; |
9115 | 0 | } |
9116 | 0 | } |
9117 | 0 | if (args[2]) { |
9118 | 0 | if (!_Py_Dev_Converter(args[2], &device)) { |
9119 | 0 | goto exit; |
9120 | 0 | } |
9121 | 0 | if (!--noptargs) { |
9122 | 0 | goto skip_optional_pos; |
9123 | 0 | } |
9124 | 0 | } |
9125 | 0 | skip_optional_pos: |
9126 | 0 | if (!noptargs) { |
9127 | 0 | goto skip_optional_kwonly; |
9128 | 0 | } |
9129 | 0 | if (!MKNODAT_DIR_FD_CONVERTER(args[3], &dir_fd)) { |
9130 | 0 | goto exit; |
9131 | 0 | } |
9132 | 0 | skip_optional_kwonly: |
9133 | 0 | return_value = os_mknod_impl(module, &path, mode, device, dir_fd); |
9134 | |
|
9135 | 0 | exit: |
9136 | | /* Cleanup for path */ |
9137 | 0 | path_cleanup(&path); |
9138 | |
|
9139 | 0 | return return_value; |
9140 | 0 | } |
9141 | | |
9142 | | #endif /* (defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV)) */ |
9143 | | |
9144 | | #if defined(HAVE_DEVICE_MACROS) |
9145 | | |
9146 | | PyDoc_STRVAR(os_major__doc__, |
9147 | | "major($module, device, /)\n" |
9148 | | "--\n" |
9149 | | "\n" |
9150 | | "Extracts a device major number from a raw device number."); |
9151 | | |
9152 | | #define OS_MAJOR_METHODDEF \ |
9153 | | {"major", (PyCFunction)os_major, METH_O, os_major__doc__}, |
9154 | | |
9155 | | static PyObject * |
9156 | | os_major_impl(PyObject *module, dev_t device); |
9157 | | |
9158 | | static PyObject * |
9159 | | os_major(PyObject *module, PyObject *arg) |
9160 | 0 | { |
9161 | 0 | PyObject *return_value = NULL; |
9162 | 0 | dev_t device; |
9163 | |
|
9164 | 0 | if (!_Py_Dev_Converter(arg, &device)) { |
9165 | 0 | goto exit; |
9166 | 0 | } |
9167 | 0 | return_value = os_major_impl(module, device); |
9168 | |
|
9169 | 0 | exit: |
9170 | 0 | return return_value; |
9171 | 0 | } |
9172 | | |
9173 | | #endif /* defined(HAVE_DEVICE_MACROS) */ |
9174 | | |
9175 | | #if defined(HAVE_DEVICE_MACROS) |
9176 | | |
9177 | | PyDoc_STRVAR(os_minor__doc__, |
9178 | | "minor($module, device, /)\n" |
9179 | | "--\n" |
9180 | | "\n" |
9181 | | "Extracts a device minor number from a raw device number."); |
9182 | | |
9183 | | #define OS_MINOR_METHODDEF \ |
9184 | | {"minor", (PyCFunction)os_minor, METH_O, os_minor__doc__}, |
9185 | | |
9186 | | static PyObject * |
9187 | | os_minor_impl(PyObject *module, dev_t device); |
9188 | | |
9189 | | static PyObject * |
9190 | | os_minor(PyObject *module, PyObject *arg) |
9191 | 0 | { |
9192 | 0 | PyObject *return_value = NULL; |
9193 | 0 | dev_t device; |
9194 | |
|
9195 | 0 | if (!_Py_Dev_Converter(arg, &device)) { |
9196 | 0 | goto exit; |
9197 | 0 | } |
9198 | 0 | return_value = os_minor_impl(module, device); |
9199 | |
|
9200 | 0 | exit: |
9201 | 0 | return return_value; |
9202 | 0 | } |
9203 | | |
9204 | | #endif /* defined(HAVE_DEVICE_MACROS) */ |
9205 | | |
9206 | | #if defined(HAVE_DEVICE_MACROS) |
9207 | | |
9208 | | PyDoc_STRVAR(os_makedev__doc__, |
9209 | | "makedev($module, major, minor, /)\n" |
9210 | | "--\n" |
9211 | | "\n" |
9212 | | "Composes a raw device number from the major and minor device numbers."); |
9213 | | |
9214 | | #define OS_MAKEDEV_METHODDEF \ |
9215 | | {"makedev", _PyCFunction_CAST(os_makedev), METH_FASTCALL, os_makedev__doc__}, |
9216 | | |
9217 | | static dev_t |
9218 | | os_makedev_impl(PyObject *module, dev_t major, dev_t minor); |
9219 | | |
9220 | | static PyObject * |
9221 | | os_makedev(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
9222 | 0 | { |
9223 | 0 | PyObject *return_value = NULL; |
9224 | 0 | dev_t major; |
9225 | 0 | dev_t minor; |
9226 | 0 | dev_t _return_value; |
9227 | |
|
9228 | 0 | if (!_PyArg_CheckPositional("makedev", nargs, 2, 2)) { |
9229 | 0 | goto exit; |
9230 | 0 | } |
9231 | 0 | if (!_Py_Dev_Converter(args[0], &major)) { |
9232 | 0 | goto exit; |
9233 | 0 | } |
9234 | 0 | if (!_Py_Dev_Converter(args[1], &minor)) { |
9235 | 0 | goto exit; |
9236 | 0 | } |
9237 | 0 | _return_value = os_makedev_impl(module, major, minor); |
9238 | 0 | if ((_return_value == (dev_t)-1) && PyErr_Occurred()) { |
9239 | 0 | goto exit; |
9240 | 0 | } |
9241 | 0 | return_value = _PyLong_FromDev(_return_value); |
9242 | |
|
9243 | 0 | exit: |
9244 | 0 | return return_value; |
9245 | 0 | } |
9246 | | |
9247 | | #endif /* defined(HAVE_DEVICE_MACROS) */ |
9248 | | |
9249 | | #if (defined HAVE_FTRUNCATE || defined MS_WINDOWS) |
9250 | | |
9251 | | PyDoc_STRVAR(os_ftruncate__doc__, |
9252 | | "ftruncate($module, fd, length, /)\n" |
9253 | | "--\n" |
9254 | | "\n" |
9255 | | "Truncate a file, specified by file descriptor, to a specific length."); |
9256 | | |
9257 | | #define OS_FTRUNCATE_METHODDEF \ |
9258 | | {"ftruncate", _PyCFunction_CAST(os_ftruncate), METH_FASTCALL, os_ftruncate__doc__}, |
9259 | | |
9260 | | static PyObject * |
9261 | | os_ftruncate_impl(PyObject *module, int fd, Py_off_t length); |
9262 | | |
9263 | | static PyObject * |
9264 | | os_ftruncate(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
9265 | 0 | { |
9266 | 0 | PyObject *return_value = NULL; |
9267 | 0 | int fd; |
9268 | 0 | Py_off_t length; |
9269 | |
|
9270 | 0 | if (!_PyArg_CheckPositional("ftruncate", nargs, 2, 2)) { |
9271 | 0 | goto exit; |
9272 | 0 | } |
9273 | 0 | fd = PyLong_AsInt(args[0]); |
9274 | 0 | if (fd == -1 && PyErr_Occurred()) { |
9275 | 0 | goto exit; |
9276 | 0 | } |
9277 | 0 | if (!Py_off_t_converter(args[1], &length)) { |
9278 | 0 | goto exit; |
9279 | 0 | } |
9280 | 0 | return_value = os_ftruncate_impl(module, fd, length); |
9281 | |
|
9282 | 0 | exit: |
9283 | 0 | return return_value; |
9284 | 0 | } |
9285 | | |
9286 | | #endif /* (defined HAVE_FTRUNCATE || defined MS_WINDOWS) */ |
9287 | | |
9288 | | #if (defined HAVE_TRUNCATE || defined MS_WINDOWS) |
9289 | | |
9290 | | PyDoc_STRVAR(os_truncate__doc__, |
9291 | | "truncate($module, /, path, length)\n" |
9292 | | "--\n" |
9293 | | "\n" |
9294 | | "Truncate a file, specified by path, to a specific length.\n" |
9295 | | "\n" |
9296 | | "On some platforms, path may also be specified as an open file descriptor.\n" |
9297 | | " If this functionality is unavailable, using it raises an exception."); |
9298 | | |
9299 | | #define OS_TRUNCATE_METHODDEF \ |
9300 | | {"truncate", _PyCFunction_CAST(os_truncate), METH_FASTCALL|METH_KEYWORDS, os_truncate__doc__}, |
9301 | | |
9302 | | static PyObject * |
9303 | | os_truncate_impl(PyObject *module, path_t *path, Py_off_t length); |
9304 | | |
9305 | | static PyObject * |
9306 | | os_truncate(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
9307 | 0 | { |
9308 | 0 | PyObject *return_value = NULL; |
9309 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
9310 | |
|
9311 | 0 | #define NUM_KEYWORDS 2 |
9312 | 0 | static struct { |
9313 | 0 | PyGC_Head _this_is_not_used; |
9314 | 0 | PyObject_VAR_HEAD |
9315 | 0 | Py_hash_t ob_hash; |
9316 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
9317 | 0 | } _kwtuple = { |
9318 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
9319 | 0 | .ob_hash = -1, |
9320 | 0 | .ob_item = { &_Py_ID(path), &_Py_ID(length), }, |
9321 | 0 | }; |
9322 | 0 | #undef NUM_KEYWORDS |
9323 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
9324 | |
|
9325 | | #else // !Py_BUILD_CORE |
9326 | | # define KWTUPLE NULL |
9327 | | #endif // !Py_BUILD_CORE |
9328 | |
|
9329 | 0 | static const char * const _keywords[] = {"path", "length", NULL}; |
9330 | 0 | static _PyArg_Parser _parser = { |
9331 | 0 | .keywords = _keywords, |
9332 | 0 | .fname = "truncate", |
9333 | 0 | .kwtuple = KWTUPLE, |
9334 | 0 | }; |
9335 | 0 | #undef KWTUPLE |
9336 | 0 | PyObject *argsbuf[2]; |
9337 | 0 | path_t path = PATH_T_INITIALIZE_P("truncate", "path", 0, 0, 0, PATH_HAVE_FTRUNCATE); |
9338 | 0 | Py_off_t length; |
9339 | |
|
9340 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
9341 | 0 | /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
9342 | 0 | if (!args) { |
9343 | 0 | goto exit; |
9344 | 0 | } |
9345 | 0 | if (!path_converter(args[0], &path)) { |
9346 | 0 | goto exit; |
9347 | 0 | } |
9348 | 0 | if (!Py_off_t_converter(args[1], &length)) { |
9349 | 0 | goto exit; |
9350 | 0 | } |
9351 | 0 | return_value = os_truncate_impl(module, &path, length); |
9352 | |
|
9353 | 0 | exit: |
9354 | | /* Cleanup for path */ |
9355 | 0 | path_cleanup(&path); |
9356 | |
|
9357 | 0 | return return_value; |
9358 | 0 | } |
9359 | | |
9360 | | #endif /* (defined HAVE_TRUNCATE || defined MS_WINDOWS) */ |
9361 | | |
9362 | | #if (defined(HAVE_POSIX_FALLOCATE) && !defined(POSIX_FADVISE_AIX_BUG) && !defined(__wasi__)) |
9363 | | |
9364 | | PyDoc_STRVAR(os_posix_fallocate__doc__, |
9365 | | "posix_fallocate($module, fd, offset, length, /)\n" |
9366 | | "--\n" |
9367 | | "\n" |
9368 | | "Ensure a file has allocated at least a particular number of bytes on disk.\n" |
9369 | | "\n" |
9370 | | "Ensure that the file specified by fd encompasses a range of bytes\n" |
9371 | | "starting at offset bytes from the beginning and continuing for length bytes."); |
9372 | | |
9373 | | #define OS_POSIX_FALLOCATE_METHODDEF \ |
9374 | | {"posix_fallocate", _PyCFunction_CAST(os_posix_fallocate), METH_FASTCALL, os_posix_fallocate__doc__}, |
9375 | | |
9376 | | static PyObject * |
9377 | | os_posix_fallocate_impl(PyObject *module, int fd, Py_off_t offset, |
9378 | | Py_off_t length); |
9379 | | |
9380 | | static PyObject * |
9381 | | os_posix_fallocate(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
9382 | 0 | { |
9383 | 0 | PyObject *return_value = NULL; |
9384 | 0 | int fd; |
9385 | 0 | Py_off_t offset; |
9386 | 0 | Py_off_t length; |
9387 | |
|
9388 | 0 | if (!_PyArg_CheckPositional("posix_fallocate", nargs, 3, 3)) { |
9389 | 0 | goto exit; |
9390 | 0 | } |
9391 | 0 | fd = PyLong_AsInt(args[0]); |
9392 | 0 | if (fd == -1 && PyErr_Occurred()) { |
9393 | 0 | goto exit; |
9394 | 0 | } |
9395 | 0 | if (!Py_off_t_converter(args[1], &offset)) { |
9396 | 0 | goto exit; |
9397 | 0 | } |
9398 | 0 | if (!Py_off_t_converter(args[2], &length)) { |
9399 | 0 | goto exit; |
9400 | 0 | } |
9401 | 0 | return_value = os_posix_fallocate_impl(module, fd, offset, length); |
9402 | |
|
9403 | 0 | exit: |
9404 | 0 | return return_value; |
9405 | 0 | } |
9406 | | |
9407 | | #endif /* (defined(HAVE_POSIX_FALLOCATE) && !defined(POSIX_FADVISE_AIX_BUG) && !defined(__wasi__)) */ |
9408 | | |
9409 | | #if (defined(HAVE_POSIX_FADVISE) && !defined(POSIX_FADVISE_AIX_BUG)) |
9410 | | |
9411 | | PyDoc_STRVAR(os_posix_fadvise__doc__, |
9412 | | "posix_fadvise($module, fd, offset, length, advice, /)\n" |
9413 | | "--\n" |
9414 | | "\n" |
9415 | | "Announce an intention to access data in a specific pattern.\n" |
9416 | | "\n" |
9417 | | "Announce an intention to access data in a specific pattern, thus allowing\n" |
9418 | | "the kernel to make optimizations.\n" |
9419 | | "The advice applies to the region of the file specified by fd starting at\n" |
9420 | | "offset and continuing for length bytes.\n" |
9421 | | "advice is one of POSIX_FADV_NORMAL, POSIX_FADV_SEQUENTIAL,\n" |
9422 | | "POSIX_FADV_RANDOM, POSIX_FADV_NOREUSE, POSIX_FADV_WILLNEED, or\n" |
9423 | | "POSIX_FADV_DONTNEED."); |
9424 | | |
9425 | | #define OS_POSIX_FADVISE_METHODDEF \ |
9426 | | {"posix_fadvise", _PyCFunction_CAST(os_posix_fadvise), METH_FASTCALL, os_posix_fadvise__doc__}, |
9427 | | |
9428 | | static PyObject * |
9429 | | os_posix_fadvise_impl(PyObject *module, int fd, Py_off_t offset, |
9430 | | Py_off_t length, int advice); |
9431 | | |
9432 | | static PyObject * |
9433 | | os_posix_fadvise(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
9434 | 0 | { |
9435 | 0 | PyObject *return_value = NULL; |
9436 | 0 | int fd; |
9437 | 0 | Py_off_t offset; |
9438 | 0 | Py_off_t length; |
9439 | 0 | int advice; |
9440 | |
|
9441 | 0 | if (!_PyArg_CheckPositional("posix_fadvise", nargs, 4, 4)) { |
9442 | 0 | goto exit; |
9443 | 0 | } |
9444 | 0 | fd = PyLong_AsInt(args[0]); |
9445 | 0 | if (fd == -1 && PyErr_Occurred()) { |
9446 | 0 | goto exit; |
9447 | 0 | } |
9448 | 0 | if (!Py_off_t_converter(args[1], &offset)) { |
9449 | 0 | goto exit; |
9450 | 0 | } |
9451 | 0 | if (!Py_off_t_converter(args[2], &length)) { |
9452 | 0 | goto exit; |
9453 | 0 | } |
9454 | 0 | advice = PyLong_AsInt(args[3]); |
9455 | 0 | if (advice == -1 && PyErr_Occurred()) { |
9456 | 0 | goto exit; |
9457 | 0 | } |
9458 | 0 | return_value = os_posix_fadvise_impl(module, fd, offset, length, advice); |
9459 | |
|
9460 | 0 | exit: |
9461 | 0 | return return_value; |
9462 | 0 | } |
9463 | | |
9464 | | #endif /* (defined(HAVE_POSIX_FADVISE) && !defined(POSIX_FADVISE_AIX_BUG)) */ |
9465 | | |
9466 | | #if defined(MS_WINDOWS) |
9467 | | |
9468 | | PyDoc_STRVAR(os_putenv__doc__, |
9469 | | "putenv($module, name, value, /)\n" |
9470 | | "--\n" |
9471 | | "\n" |
9472 | | "Change or add an environment variable."); |
9473 | | |
9474 | | #define OS_PUTENV_METHODDEF \ |
9475 | | {"putenv", _PyCFunction_CAST(os_putenv), METH_FASTCALL, os_putenv__doc__}, |
9476 | | |
9477 | | static PyObject * |
9478 | | os_putenv_impl(PyObject *module, PyObject *name, PyObject *value); |
9479 | | |
9480 | | static PyObject * |
9481 | | os_putenv(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
9482 | | { |
9483 | | PyObject *return_value = NULL; |
9484 | | PyObject *name; |
9485 | | PyObject *value; |
9486 | | |
9487 | | if (!_PyArg_CheckPositional("putenv", nargs, 2, 2)) { |
9488 | | goto exit; |
9489 | | } |
9490 | | if (!PyUnicode_Check(args[0])) { |
9491 | | _PyArg_BadArgument("putenv", "argument 1", "str", args[0]); |
9492 | | goto exit; |
9493 | | } |
9494 | | name = args[0]; |
9495 | | if (!PyUnicode_Check(args[1])) { |
9496 | | _PyArg_BadArgument("putenv", "argument 2", "str", args[1]); |
9497 | | goto exit; |
9498 | | } |
9499 | | value = args[1]; |
9500 | | return_value = os_putenv_impl(module, name, value); |
9501 | | |
9502 | | exit: |
9503 | | return return_value; |
9504 | | } |
9505 | | |
9506 | | #endif /* defined(MS_WINDOWS) */ |
9507 | | |
9508 | | #if !defined(MS_WINDOWS) |
9509 | | |
9510 | | PyDoc_STRVAR(os_putenv__doc__, |
9511 | | "putenv($module, name, value, /)\n" |
9512 | | "--\n" |
9513 | | "\n" |
9514 | | "Change or add an environment variable."); |
9515 | | |
9516 | | #define OS_PUTENV_METHODDEF \ |
9517 | | {"putenv", _PyCFunction_CAST(os_putenv), METH_FASTCALL, os_putenv__doc__}, |
9518 | | |
9519 | | static PyObject * |
9520 | | os_putenv_impl(PyObject *module, PyObject *name, PyObject *value); |
9521 | | |
9522 | | static PyObject * |
9523 | | os_putenv(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
9524 | 0 | { |
9525 | 0 | PyObject *return_value = NULL; |
9526 | 0 | PyObject *name = NULL; |
9527 | 0 | PyObject *value = NULL; |
9528 | |
|
9529 | 0 | if (!_PyArg_CheckPositional("putenv", nargs, 2, 2)) { |
9530 | 0 | goto exit; |
9531 | 0 | } |
9532 | 0 | if (!PyUnicode_FSConverter(args[0], &name)) { |
9533 | 0 | goto exit; |
9534 | 0 | } |
9535 | 0 | if (!PyUnicode_FSConverter(args[1], &value)) { |
9536 | 0 | goto exit; |
9537 | 0 | } |
9538 | 0 | return_value = os_putenv_impl(module, name, value); |
9539 | |
|
9540 | 0 | exit: |
9541 | | /* Cleanup for name */ |
9542 | 0 | Py_XDECREF(name); |
9543 | | /* Cleanup for value */ |
9544 | 0 | Py_XDECREF(value); |
9545 | |
|
9546 | 0 | return return_value; |
9547 | 0 | } |
9548 | | |
9549 | | #endif /* !defined(MS_WINDOWS) */ |
9550 | | |
9551 | | #if defined(MS_WINDOWS) |
9552 | | |
9553 | | PyDoc_STRVAR(os_unsetenv__doc__, |
9554 | | "unsetenv($module, name, /)\n" |
9555 | | "--\n" |
9556 | | "\n" |
9557 | | "Delete an environment variable."); |
9558 | | |
9559 | | #define OS_UNSETENV_METHODDEF \ |
9560 | | {"unsetenv", (PyCFunction)os_unsetenv, METH_O, os_unsetenv__doc__}, |
9561 | | |
9562 | | static PyObject * |
9563 | | os_unsetenv_impl(PyObject *module, PyObject *name); |
9564 | | |
9565 | | static PyObject * |
9566 | | os_unsetenv(PyObject *module, PyObject *arg) |
9567 | | { |
9568 | | PyObject *return_value = NULL; |
9569 | | PyObject *name; |
9570 | | |
9571 | | if (!PyUnicode_Check(arg)) { |
9572 | | _PyArg_BadArgument("unsetenv", "argument", "str", arg); |
9573 | | goto exit; |
9574 | | } |
9575 | | name = arg; |
9576 | | return_value = os_unsetenv_impl(module, name); |
9577 | | |
9578 | | exit: |
9579 | | return return_value; |
9580 | | } |
9581 | | |
9582 | | #endif /* defined(MS_WINDOWS) */ |
9583 | | |
9584 | | #if !defined(MS_WINDOWS) |
9585 | | |
9586 | | PyDoc_STRVAR(os_unsetenv__doc__, |
9587 | | "unsetenv($module, name, /)\n" |
9588 | | "--\n" |
9589 | | "\n" |
9590 | | "Delete an environment variable."); |
9591 | | |
9592 | | #define OS_UNSETENV_METHODDEF \ |
9593 | | {"unsetenv", (PyCFunction)os_unsetenv, METH_O, os_unsetenv__doc__}, |
9594 | | |
9595 | | static PyObject * |
9596 | | os_unsetenv_impl(PyObject *module, PyObject *name); |
9597 | | |
9598 | | static PyObject * |
9599 | | os_unsetenv(PyObject *module, PyObject *arg) |
9600 | 0 | { |
9601 | 0 | PyObject *return_value = NULL; |
9602 | 0 | PyObject *name = NULL; |
9603 | |
|
9604 | 0 | if (!PyUnicode_FSConverter(arg, &name)) { |
9605 | 0 | goto exit; |
9606 | 0 | } |
9607 | 0 | return_value = os_unsetenv_impl(module, name); |
9608 | |
|
9609 | 0 | exit: |
9610 | | /* Cleanup for name */ |
9611 | 0 | Py_XDECREF(name); |
9612 | |
|
9613 | 0 | return return_value; |
9614 | 0 | } |
9615 | | |
9616 | | #endif /* !defined(MS_WINDOWS) */ |
9617 | | |
9618 | | PyDoc_STRVAR(os_strerror__doc__, |
9619 | | "strerror($module, code, /)\n" |
9620 | | "--\n" |
9621 | | "\n" |
9622 | | "Translate an error code to a message string."); |
9623 | | |
9624 | | #define OS_STRERROR_METHODDEF \ |
9625 | | {"strerror", (PyCFunction)os_strerror, METH_O, os_strerror__doc__}, |
9626 | | |
9627 | | static PyObject * |
9628 | | os_strerror_impl(PyObject *module, int code); |
9629 | | |
9630 | | static PyObject * |
9631 | | os_strerror(PyObject *module, PyObject *arg) |
9632 | 0 | { |
9633 | 0 | PyObject *return_value = NULL; |
9634 | 0 | int code; |
9635 | |
|
9636 | 0 | code = PyLong_AsInt(arg); |
9637 | 0 | if (code == -1 && PyErr_Occurred()) { |
9638 | 0 | goto exit; |
9639 | 0 | } |
9640 | 0 | return_value = os_strerror_impl(module, code); |
9641 | |
|
9642 | 0 | exit: |
9643 | 0 | return return_value; |
9644 | 0 | } |
9645 | | |
9646 | | #if defined(HAVE_SYS_WAIT_H) && defined(WCOREDUMP) |
9647 | | |
9648 | | PyDoc_STRVAR(os_WCOREDUMP__doc__, |
9649 | | "WCOREDUMP($module, status, /)\n" |
9650 | | "--\n" |
9651 | | "\n" |
9652 | | "Return True if the process returning status was dumped to a core file."); |
9653 | | |
9654 | | #define OS_WCOREDUMP_METHODDEF \ |
9655 | | {"WCOREDUMP", (PyCFunction)os_WCOREDUMP, METH_O, os_WCOREDUMP__doc__}, |
9656 | | |
9657 | | static int |
9658 | | os_WCOREDUMP_impl(PyObject *module, int status); |
9659 | | |
9660 | | static PyObject * |
9661 | | os_WCOREDUMP(PyObject *module, PyObject *arg) |
9662 | 0 | { |
9663 | 0 | PyObject *return_value = NULL; |
9664 | 0 | int status; |
9665 | 0 | int _return_value; |
9666 | |
|
9667 | 0 | status = PyLong_AsInt(arg); |
9668 | 0 | if (status == -1 && PyErr_Occurred()) { |
9669 | 0 | goto exit; |
9670 | 0 | } |
9671 | 0 | _return_value = os_WCOREDUMP_impl(module, status); |
9672 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
9673 | 0 | goto exit; |
9674 | 0 | } |
9675 | 0 | return_value = PyBool_FromLong((long)_return_value); |
9676 | |
|
9677 | 0 | exit: |
9678 | 0 | return return_value; |
9679 | 0 | } |
9680 | | |
9681 | | #endif /* defined(HAVE_SYS_WAIT_H) && defined(WCOREDUMP) */ |
9682 | | |
9683 | | #if defined(HAVE_SYS_WAIT_H) && defined(WIFCONTINUED) |
9684 | | |
9685 | | PyDoc_STRVAR(os_WIFCONTINUED__doc__, |
9686 | | "WIFCONTINUED($module, /, status)\n" |
9687 | | "--\n" |
9688 | | "\n" |
9689 | | "Return True if a particular process was continued from a job control stop.\n" |
9690 | | "\n" |
9691 | | "Return True if the process returning status was continued from a\n" |
9692 | | "job control stop."); |
9693 | | |
9694 | | #define OS_WIFCONTINUED_METHODDEF \ |
9695 | | {"WIFCONTINUED", _PyCFunction_CAST(os_WIFCONTINUED), METH_FASTCALL|METH_KEYWORDS, os_WIFCONTINUED__doc__}, |
9696 | | |
9697 | | static int |
9698 | | os_WIFCONTINUED_impl(PyObject *module, int status); |
9699 | | |
9700 | | static PyObject * |
9701 | | os_WIFCONTINUED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
9702 | 0 | { |
9703 | 0 | PyObject *return_value = NULL; |
9704 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
9705 | |
|
9706 | 0 | #define NUM_KEYWORDS 1 |
9707 | 0 | static struct { |
9708 | 0 | PyGC_Head _this_is_not_used; |
9709 | 0 | PyObject_VAR_HEAD |
9710 | 0 | Py_hash_t ob_hash; |
9711 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
9712 | 0 | } _kwtuple = { |
9713 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
9714 | 0 | .ob_hash = -1, |
9715 | 0 | .ob_item = { &_Py_ID(status), }, |
9716 | 0 | }; |
9717 | 0 | #undef NUM_KEYWORDS |
9718 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
9719 | |
|
9720 | | #else // !Py_BUILD_CORE |
9721 | | # define KWTUPLE NULL |
9722 | | #endif // !Py_BUILD_CORE |
9723 | |
|
9724 | 0 | static const char * const _keywords[] = {"status", NULL}; |
9725 | 0 | static _PyArg_Parser _parser = { |
9726 | 0 | .keywords = _keywords, |
9727 | 0 | .fname = "WIFCONTINUED", |
9728 | 0 | .kwtuple = KWTUPLE, |
9729 | 0 | }; |
9730 | 0 | #undef KWTUPLE |
9731 | 0 | PyObject *argsbuf[1]; |
9732 | 0 | int status; |
9733 | 0 | int _return_value; |
9734 | |
|
9735 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
9736 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
9737 | 0 | if (!args) { |
9738 | 0 | goto exit; |
9739 | 0 | } |
9740 | 0 | status = PyLong_AsInt(args[0]); |
9741 | 0 | if (status == -1 && PyErr_Occurred()) { |
9742 | 0 | goto exit; |
9743 | 0 | } |
9744 | 0 | _return_value = os_WIFCONTINUED_impl(module, status); |
9745 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
9746 | 0 | goto exit; |
9747 | 0 | } |
9748 | 0 | return_value = PyBool_FromLong((long)_return_value); |
9749 | |
|
9750 | 0 | exit: |
9751 | 0 | return return_value; |
9752 | 0 | } |
9753 | | |
9754 | | #endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFCONTINUED) */ |
9755 | | |
9756 | | #if defined(HAVE_SYS_WAIT_H) && defined(WIFSTOPPED) |
9757 | | |
9758 | | PyDoc_STRVAR(os_WIFSTOPPED__doc__, |
9759 | | "WIFSTOPPED($module, /, status)\n" |
9760 | | "--\n" |
9761 | | "\n" |
9762 | | "Return True if the process returning status was stopped."); |
9763 | | |
9764 | | #define OS_WIFSTOPPED_METHODDEF \ |
9765 | | {"WIFSTOPPED", _PyCFunction_CAST(os_WIFSTOPPED), METH_FASTCALL|METH_KEYWORDS, os_WIFSTOPPED__doc__}, |
9766 | | |
9767 | | static int |
9768 | | os_WIFSTOPPED_impl(PyObject *module, int status); |
9769 | | |
9770 | | static PyObject * |
9771 | | os_WIFSTOPPED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
9772 | 0 | { |
9773 | 0 | PyObject *return_value = NULL; |
9774 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
9775 | |
|
9776 | 0 | #define NUM_KEYWORDS 1 |
9777 | 0 | static struct { |
9778 | 0 | PyGC_Head _this_is_not_used; |
9779 | 0 | PyObject_VAR_HEAD |
9780 | 0 | Py_hash_t ob_hash; |
9781 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
9782 | 0 | } _kwtuple = { |
9783 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
9784 | 0 | .ob_hash = -1, |
9785 | 0 | .ob_item = { &_Py_ID(status), }, |
9786 | 0 | }; |
9787 | 0 | #undef NUM_KEYWORDS |
9788 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
9789 | |
|
9790 | | #else // !Py_BUILD_CORE |
9791 | | # define KWTUPLE NULL |
9792 | | #endif // !Py_BUILD_CORE |
9793 | |
|
9794 | 0 | static const char * const _keywords[] = {"status", NULL}; |
9795 | 0 | static _PyArg_Parser _parser = { |
9796 | 0 | .keywords = _keywords, |
9797 | 0 | .fname = "WIFSTOPPED", |
9798 | 0 | .kwtuple = KWTUPLE, |
9799 | 0 | }; |
9800 | 0 | #undef KWTUPLE |
9801 | 0 | PyObject *argsbuf[1]; |
9802 | 0 | int status; |
9803 | 0 | int _return_value; |
9804 | |
|
9805 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
9806 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
9807 | 0 | if (!args) { |
9808 | 0 | goto exit; |
9809 | 0 | } |
9810 | 0 | status = PyLong_AsInt(args[0]); |
9811 | 0 | if (status == -1 && PyErr_Occurred()) { |
9812 | 0 | goto exit; |
9813 | 0 | } |
9814 | 0 | _return_value = os_WIFSTOPPED_impl(module, status); |
9815 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
9816 | 0 | goto exit; |
9817 | 0 | } |
9818 | 0 | return_value = PyBool_FromLong((long)_return_value); |
9819 | |
|
9820 | 0 | exit: |
9821 | 0 | return return_value; |
9822 | 0 | } |
9823 | | |
9824 | | #endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFSTOPPED) */ |
9825 | | |
9826 | | #if defined(HAVE_SYS_WAIT_H) && defined(WIFSIGNALED) |
9827 | | |
9828 | | PyDoc_STRVAR(os_WIFSIGNALED__doc__, |
9829 | | "WIFSIGNALED($module, /, status)\n" |
9830 | | "--\n" |
9831 | | "\n" |
9832 | | "Return True if the process returning status was terminated by a signal."); |
9833 | | |
9834 | | #define OS_WIFSIGNALED_METHODDEF \ |
9835 | | {"WIFSIGNALED", _PyCFunction_CAST(os_WIFSIGNALED), METH_FASTCALL|METH_KEYWORDS, os_WIFSIGNALED__doc__}, |
9836 | | |
9837 | | static int |
9838 | | os_WIFSIGNALED_impl(PyObject *module, int status); |
9839 | | |
9840 | | static PyObject * |
9841 | | os_WIFSIGNALED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
9842 | 0 | { |
9843 | 0 | PyObject *return_value = NULL; |
9844 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
9845 | |
|
9846 | 0 | #define NUM_KEYWORDS 1 |
9847 | 0 | static struct { |
9848 | 0 | PyGC_Head _this_is_not_used; |
9849 | 0 | PyObject_VAR_HEAD |
9850 | 0 | Py_hash_t ob_hash; |
9851 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
9852 | 0 | } _kwtuple = { |
9853 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
9854 | 0 | .ob_hash = -1, |
9855 | 0 | .ob_item = { &_Py_ID(status), }, |
9856 | 0 | }; |
9857 | 0 | #undef NUM_KEYWORDS |
9858 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
9859 | |
|
9860 | | #else // !Py_BUILD_CORE |
9861 | | # define KWTUPLE NULL |
9862 | | #endif // !Py_BUILD_CORE |
9863 | |
|
9864 | 0 | static const char * const _keywords[] = {"status", NULL}; |
9865 | 0 | static _PyArg_Parser _parser = { |
9866 | 0 | .keywords = _keywords, |
9867 | 0 | .fname = "WIFSIGNALED", |
9868 | 0 | .kwtuple = KWTUPLE, |
9869 | 0 | }; |
9870 | 0 | #undef KWTUPLE |
9871 | 0 | PyObject *argsbuf[1]; |
9872 | 0 | int status; |
9873 | 0 | int _return_value; |
9874 | |
|
9875 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
9876 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
9877 | 0 | if (!args) { |
9878 | 0 | goto exit; |
9879 | 0 | } |
9880 | 0 | status = PyLong_AsInt(args[0]); |
9881 | 0 | if (status == -1 && PyErr_Occurred()) { |
9882 | 0 | goto exit; |
9883 | 0 | } |
9884 | 0 | _return_value = os_WIFSIGNALED_impl(module, status); |
9885 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
9886 | 0 | goto exit; |
9887 | 0 | } |
9888 | 0 | return_value = PyBool_FromLong((long)_return_value); |
9889 | |
|
9890 | 0 | exit: |
9891 | 0 | return return_value; |
9892 | 0 | } |
9893 | | |
9894 | | #endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFSIGNALED) */ |
9895 | | |
9896 | | #if defined(HAVE_SYS_WAIT_H) && defined(WIFEXITED) |
9897 | | |
9898 | | PyDoc_STRVAR(os_WIFEXITED__doc__, |
9899 | | "WIFEXITED($module, /, status)\n" |
9900 | | "--\n" |
9901 | | "\n" |
9902 | | "Return True if the process returning status exited via the exit() system call."); |
9903 | | |
9904 | | #define OS_WIFEXITED_METHODDEF \ |
9905 | | {"WIFEXITED", _PyCFunction_CAST(os_WIFEXITED), METH_FASTCALL|METH_KEYWORDS, os_WIFEXITED__doc__}, |
9906 | | |
9907 | | static int |
9908 | | os_WIFEXITED_impl(PyObject *module, int status); |
9909 | | |
9910 | | static PyObject * |
9911 | | os_WIFEXITED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
9912 | 0 | { |
9913 | 0 | PyObject *return_value = NULL; |
9914 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
9915 | |
|
9916 | 0 | #define NUM_KEYWORDS 1 |
9917 | 0 | static struct { |
9918 | 0 | PyGC_Head _this_is_not_used; |
9919 | 0 | PyObject_VAR_HEAD |
9920 | 0 | Py_hash_t ob_hash; |
9921 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
9922 | 0 | } _kwtuple = { |
9923 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
9924 | 0 | .ob_hash = -1, |
9925 | 0 | .ob_item = { &_Py_ID(status), }, |
9926 | 0 | }; |
9927 | 0 | #undef NUM_KEYWORDS |
9928 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
9929 | |
|
9930 | | #else // !Py_BUILD_CORE |
9931 | | # define KWTUPLE NULL |
9932 | | #endif // !Py_BUILD_CORE |
9933 | |
|
9934 | 0 | static const char * const _keywords[] = {"status", NULL}; |
9935 | 0 | static _PyArg_Parser _parser = { |
9936 | 0 | .keywords = _keywords, |
9937 | 0 | .fname = "WIFEXITED", |
9938 | 0 | .kwtuple = KWTUPLE, |
9939 | 0 | }; |
9940 | 0 | #undef KWTUPLE |
9941 | 0 | PyObject *argsbuf[1]; |
9942 | 0 | int status; |
9943 | 0 | int _return_value; |
9944 | |
|
9945 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
9946 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
9947 | 0 | if (!args) { |
9948 | 0 | goto exit; |
9949 | 0 | } |
9950 | 0 | status = PyLong_AsInt(args[0]); |
9951 | 0 | if (status == -1 && PyErr_Occurred()) { |
9952 | 0 | goto exit; |
9953 | 0 | } |
9954 | 0 | _return_value = os_WIFEXITED_impl(module, status); |
9955 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
9956 | 0 | goto exit; |
9957 | 0 | } |
9958 | 0 | return_value = PyBool_FromLong((long)_return_value); |
9959 | |
|
9960 | 0 | exit: |
9961 | 0 | return return_value; |
9962 | 0 | } |
9963 | | |
9964 | | #endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFEXITED) */ |
9965 | | |
9966 | | #if defined(HAVE_SYS_WAIT_H) && defined(WEXITSTATUS) |
9967 | | |
9968 | | PyDoc_STRVAR(os_WEXITSTATUS__doc__, |
9969 | | "WEXITSTATUS($module, /, status)\n" |
9970 | | "--\n" |
9971 | | "\n" |
9972 | | "Return the process return code from status."); |
9973 | | |
9974 | | #define OS_WEXITSTATUS_METHODDEF \ |
9975 | | {"WEXITSTATUS", _PyCFunction_CAST(os_WEXITSTATUS), METH_FASTCALL|METH_KEYWORDS, os_WEXITSTATUS__doc__}, |
9976 | | |
9977 | | static int |
9978 | | os_WEXITSTATUS_impl(PyObject *module, int status); |
9979 | | |
9980 | | static PyObject * |
9981 | | os_WEXITSTATUS(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
9982 | 0 | { |
9983 | 0 | PyObject *return_value = NULL; |
9984 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
9985 | |
|
9986 | 0 | #define NUM_KEYWORDS 1 |
9987 | 0 | static struct { |
9988 | 0 | PyGC_Head _this_is_not_used; |
9989 | 0 | PyObject_VAR_HEAD |
9990 | 0 | Py_hash_t ob_hash; |
9991 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
9992 | 0 | } _kwtuple = { |
9993 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
9994 | 0 | .ob_hash = -1, |
9995 | 0 | .ob_item = { &_Py_ID(status), }, |
9996 | 0 | }; |
9997 | 0 | #undef NUM_KEYWORDS |
9998 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
9999 | |
|
10000 | | #else // !Py_BUILD_CORE |
10001 | | # define KWTUPLE NULL |
10002 | | #endif // !Py_BUILD_CORE |
10003 | |
|
10004 | 0 | static const char * const _keywords[] = {"status", NULL}; |
10005 | 0 | static _PyArg_Parser _parser = { |
10006 | 0 | .keywords = _keywords, |
10007 | 0 | .fname = "WEXITSTATUS", |
10008 | 0 | .kwtuple = KWTUPLE, |
10009 | 0 | }; |
10010 | 0 | #undef KWTUPLE |
10011 | 0 | PyObject *argsbuf[1]; |
10012 | 0 | int status; |
10013 | 0 | int _return_value; |
10014 | |
|
10015 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
10016 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
10017 | 0 | if (!args) { |
10018 | 0 | goto exit; |
10019 | 0 | } |
10020 | 0 | status = PyLong_AsInt(args[0]); |
10021 | 0 | if (status == -1 && PyErr_Occurred()) { |
10022 | 0 | goto exit; |
10023 | 0 | } |
10024 | 0 | _return_value = os_WEXITSTATUS_impl(module, status); |
10025 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
10026 | 0 | goto exit; |
10027 | 0 | } |
10028 | 0 | return_value = PyLong_FromLong((long)_return_value); |
10029 | |
|
10030 | 0 | exit: |
10031 | 0 | return return_value; |
10032 | 0 | } |
10033 | | |
10034 | | #endif /* defined(HAVE_SYS_WAIT_H) && defined(WEXITSTATUS) */ |
10035 | | |
10036 | | #if defined(HAVE_SYS_WAIT_H) && defined(WTERMSIG) |
10037 | | |
10038 | | PyDoc_STRVAR(os_WTERMSIG__doc__, |
10039 | | "WTERMSIG($module, /, status)\n" |
10040 | | "--\n" |
10041 | | "\n" |
10042 | | "Return the signal that terminated the process that provided the status value."); |
10043 | | |
10044 | | #define OS_WTERMSIG_METHODDEF \ |
10045 | | {"WTERMSIG", _PyCFunction_CAST(os_WTERMSIG), METH_FASTCALL|METH_KEYWORDS, os_WTERMSIG__doc__}, |
10046 | | |
10047 | | static int |
10048 | | os_WTERMSIG_impl(PyObject *module, int status); |
10049 | | |
10050 | | static PyObject * |
10051 | | os_WTERMSIG(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
10052 | 0 | { |
10053 | 0 | PyObject *return_value = NULL; |
10054 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
10055 | |
|
10056 | 0 | #define NUM_KEYWORDS 1 |
10057 | 0 | static struct { |
10058 | 0 | PyGC_Head _this_is_not_used; |
10059 | 0 | PyObject_VAR_HEAD |
10060 | 0 | Py_hash_t ob_hash; |
10061 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
10062 | 0 | } _kwtuple = { |
10063 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
10064 | 0 | .ob_hash = -1, |
10065 | 0 | .ob_item = { &_Py_ID(status), }, |
10066 | 0 | }; |
10067 | 0 | #undef NUM_KEYWORDS |
10068 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
10069 | |
|
10070 | | #else // !Py_BUILD_CORE |
10071 | | # define KWTUPLE NULL |
10072 | | #endif // !Py_BUILD_CORE |
10073 | |
|
10074 | 0 | static const char * const _keywords[] = {"status", NULL}; |
10075 | 0 | static _PyArg_Parser _parser = { |
10076 | 0 | .keywords = _keywords, |
10077 | 0 | .fname = "WTERMSIG", |
10078 | 0 | .kwtuple = KWTUPLE, |
10079 | 0 | }; |
10080 | 0 | #undef KWTUPLE |
10081 | 0 | PyObject *argsbuf[1]; |
10082 | 0 | int status; |
10083 | 0 | int _return_value; |
10084 | |
|
10085 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
10086 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
10087 | 0 | if (!args) { |
10088 | 0 | goto exit; |
10089 | 0 | } |
10090 | 0 | status = PyLong_AsInt(args[0]); |
10091 | 0 | if (status == -1 && PyErr_Occurred()) { |
10092 | 0 | goto exit; |
10093 | 0 | } |
10094 | 0 | _return_value = os_WTERMSIG_impl(module, status); |
10095 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
10096 | 0 | goto exit; |
10097 | 0 | } |
10098 | 0 | return_value = PyLong_FromLong((long)_return_value); |
10099 | |
|
10100 | 0 | exit: |
10101 | 0 | return return_value; |
10102 | 0 | } |
10103 | | |
10104 | | #endif /* defined(HAVE_SYS_WAIT_H) && defined(WTERMSIG) */ |
10105 | | |
10106 | | #if defined(HAVE_SYS_WAIT_H) && defined(WSTOPSIG) |
10107 | | |
10108 | | PyDoc_STRVAR(os_WSTOPSIG__doc__, |
10109 | | "WSTOPSIG($module, /, status)\n" |
10110 | | "--\n" |
10111 | | "\n" |
10112 | | "Return the signal that stopped the process that provided the status value."); |
10113 | | |
10114 | | #define OS_WSTOPSIG_METHODDEF \ |
10115 | | {"WSTOPSIG", _PyCFunction_CAST(os_WSTOPSIG), METH_FASTCALL|METH_KEYWORDS, os_WSTOPSIG__doc__}, |
10116 | | |
10117 | | static int |
10118 | | os_WSTOPSIG_impl(PyObject *module, int status); |
10119 | | |
10120 | | static PyObject * |
10121 | | os_WSTOPSIG(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
10122 | 0 | { |
10123 | 0 | PyObject *return_value = NULL; |
10124 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
10125 | |
|
10126 | 0 | #define NUM_KEYWORDS 1 |
10127 | 0 | static struct { |
10128 | 0 | PyGC_Head _this_is_not_used; |
10129 | 0 | PyObject_VAR_HEAD |
10130 | 0 | Py_hash_t ob_hash; |
10131 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
10132 | 0 | } _kwtuple = { |
10133 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
10134 | 0 | .ob_hash = -1, |
10135 | 0 | .ob_item = { &_Py_ID(status), }, |
10136 | 0 | }; |
10137 | 0 | #undef NUM_KEYWORDS |
10138 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
10139 | |
|
10140 | | #else // !Py_BUILD_CORE |
10141 | | # define KWTUPLE NULL |
10142 | | #endif // !Py_BUILD_CORE |
10143 | |
|
10144 | 0 | static const char * const _keywords[] = {"status", NULL}; |
10145 | 0 | static _PyArg_Parser _parser = { |
10146 | 0 | .keywords = _keywords, |
10147 | 0 | .fname = "WSTOPSIG", |
10148 | 0 | .kwtuple = KWTUPLE, |
10149 | 0 | }; |
10150 | 0 | #undef KWTUPLE |
10151 | 0 | PyObject *argsbuf[1]; |
10152 | 0 | int status; |
10153 | 0 | int _return_value; |
10154 | |
|
10155 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
10156 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
10157 | 0 | if (!args) { |
10158 | 0 | goto exit; |
10159 | 0 | } |
10160 | 0 | status = PyLong_AsInt(args[0]); |
10161 | 0 | if (status == -1 && PyErr_Occurred()) { |
10162 | 0 | goto exit; |
10163 | 0 | } |
10164 | 0 | _return_value = os_WSTOPSIG_impl(module, status); |
10165 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
10166 | 0 | goto exit; |
10167 | 0 | } |
10168 | 0 | return_value = PyLong_FromLong((long)_return_value); |
10169 | |
|
10170 | 0 | exit: |
10171 | 0 | return return_value; |
10172 | 0 | } |
10173 | | |
10174 | | #endif /* defined(HAVE_SYS_WAIT_H) && defined(WSTOPSIG) */ |
10175 | | |
10176 | | #if (defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H)) |
10177 | | |
10178 | | PyDoc_STRVAR(os_fstatvfs__doc__, |
10179 | | "fstatvfs($module, fd, /)\n" |
10180 | | "--\n" |
10181 | | "\n" |
10182 | | "Perform an fstatvfs system call on the given fd.\n" |
10183 | | "\n" |
10184 | | "Equivalent to statvfs(fd)."); |
10185 | | |
10186 | | #define OS_FSTATVFS_METHODDEF \ |
10187 | | {"fstatvfs", (PyCFunction)os_fstatvfs, METH_O, os_fstatvfs__doc__}, |
10188 | | |
10189 | | static PyObject * |
10190 | | os_fstatvfs_impl(PyObject *module, int fd); |
10191 | | |
10192 | | static PyObject * |
10193 | | os_fstatvfs(PyObject *module, PyObject *arg) |
10194 | 0 | { |
10195 | 0 | PyObject *return_value = NULL; |
10196 | 0 | int fd; |
10197 | |
|
10198 | 0 | fd = PyLong_AsInt(arg); |
10199 | 0 | if (fd == -1 && PyErr_Occurred()) { |
10200 | 0 | goto exit; |
10201 | 0 | } |
10202 | 0 | return_value = os_fstatvfs_impl(module, fd); |
10203 | |
|
10204 | 0 | exit: |
10205 | 0 | return return_value; |
10206 | 0 | } |
10207 | | |
10208 | | #endif /* (defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H)) */ |
10209 | | |
10210 | | #if (defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H)) |
10211 | | |
10212 | | PyDoc_STRVAR(os_statvfs__doc__, |
10213 | | "statvfs($module, /, path)\n" |
10214 | | "--\n" |
10215 | | "\n" |
10216 | | "Perform a statvfs system call on the given path.\n" |
10217 | | "\n" |
10218 | | "path may always be specified as a string.\n" |
10219 | | "On some platforms, path may also be specified as an open file descriptor.\n" |
10220 | | " If this functionality is unavailable, using it raises an exception."); |
10221 | | |
10222 | | #define OS_STATVFS_METHODDEF \ |
10223 | | {"statvfs", _PyCFunction_CAST(os_statvfs), METH_FASTCALL|METH_KEYWORDS, os_statvfs__doc__}, |
10224 | | |
10225 | | static PyObject * |
10226 | | os_statvfs_impl(PyObject *module, path_t *path); |
10227 | | |
10228 | | static PyObject * |
10229 | | os_statvfs(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
10230 | 0 | { |
10231 | 0 | PyObject *return_value = NULL; |
10232 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
10233 | |
|
10234 | 0 | #define NUM_KEYWORDS 1 |
10235 | 0 | static struct { |
10236 | 0 | PyGC_Head _this_is_not_used; |
10237 | 0 | PyObject_VAR_HEAD |
10238 | 0 | Py_hash_t ob_hash; |
10239 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
10240 | 0 | } _kwtuple = { |
10241 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
10242 | 0 | .ob_hash = -1, |
10243 | 0 | .ob_item = { &_Py_ID(path), }, |
10244 | 0 | }; |
10245 | 0 | #undef NUM_KEYWORDS |
10246 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
10247 | |
|
10248 | | #else // !Py_BUILD_CORE |
10249 | | # define KWTUPLE NULL |
10250 | | #endif // !Py_BUILD_CORE |
10251 | |
|
10252 | 0 | static const char * const _keywords[] = {"path", NULL}; |
10253 | 0 | static _PyArg_Parser _parser = { |
10254 | 0 | .keywords = _keywords, |
10255 | 0 | .fname = "statvfs", |
10256 | 0 | .kwtuple = KWTUPLE, |
10257 | 0 | }; |
10258 | 0 | #undef KWTUPLE |
10259 | 0 | PyObject *argsbuf[1]; |
10260 | 0 | path_t path = PATH_T_INITIALIZE_P("statvfs", "path", 0, 0, 0, PATH_HAVE_FSTATVFS); |
10261 | |
|
10262 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
10263 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
10264 | 0 | if (!args) { |
10265 | 0 | goto exit; |
10266 | 0 | } |
10267 | 0 | if (!path_converter(args[0], &path)) { |
10268 | 0 | goto exit; |
10269 | 0 | } |
10270 | 0 | return_value = os_statvfs_impl(module, &path); |
10271 | |
|
10272 | 0 | exit: |
10273 | | /* Cleanup for path */ |
10274 | 0 | path_cleanup(&path); |
10275 | |
|
10276 | 0 | return return_value; |
10277 | 0 | } |
10278 | | |
10279 | | #endif /* (defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H)) */ |
10280 | | |
10281 | | #if defined(MS_WINDOWS) |
10282 | | |
10283 | | PyDoc_STRVAR(os__getdiskusage__doc__, |
10284 | | "_getdiskusage($module, /, path)\n" |
10285 | | "--\n" |
10286 | | "\n" |
10287 | | "Return disk usage statistics about the given path as a (total, free) tuple."); |
10288 | | |
10289 | | #define OS__GETDISKUSAGE_METHODDEF \ |
10290 | | {"_getdiskusage", _PyCFunction_CAST(os__getdiskusage), METH_FASTCALL|METH_KEYWORDS, os__getdiskusage__doc__}, |
10291 | | |
10292 | | static PyObject * |
10293 | | os__getdiskusage_impl(PyObject *module, path_t *path); |
10294 | | |
10295 | | static PyObject * |
10296 | | os__getdiskusage(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
10297 | | { |
10298 | | PyObject *return_value = NULL; |
10299 | | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
10300 | | |
10301 | | #define NUM_KEYWORDS 1 |
10302 | | static struct { |
10303 | | PyGC_Head _this_is_not_used; |
10304 | | PyObject_VAR_HEAD |
10305 | | Py_hash_t ob_hash; |
10306 | | PyObject *ob_item[NUM_KEYWORDS]; |
10307 | | } _kwtuple = { |
10308 | | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
10309 | | .ob_hash = -1, |
10310 | | .ob_item = { &_Py_ID(path), }, |
10311 | | }; |
10312 | | #undef NUM_KEYWORDS |
10313 | | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
10314 | | |
10315 | | #else // !Py_BUILD_CORE |
10316 | | # define KWTUPLE NULL |
10317 | | #endif // !Py_BUILD_CORE |
10318 | | |
10319 | | static const char * const _keywords[] = {"path", NULL}; |
10320 | | static _PyArg_Parser _parser = { |
10321 | | .keywords = _keywords, |
10322 | | .fname = "_getdiskusage", |
10323 | | .kwtuple = KWTUPLE, |
10324 | | }; |
10325 | | #undef KWTUPLE |
10326 | | PyObject *argsbuf[1]; |
10327 | | path_t path = PATH_T_INITIALIZE_P("_getdiskusage", "path", 0, 0, 0, 0); |
10328 | | |
10329 | | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
10330 | | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
10331 | | if (!args) { |
10332 | | goto exit; |
10333 | | } |
10334 | | if (!path_converter(args[0], &path)) { |
10335 | | goto exit; |
10336 | | } |
10337 | | return_value = os__getdiskusage_impl(module, &path); |
10338 | | |
10339 | | exit: |
10340 | | /* Cleanup for path */ |
10341 | | path_cleanup(&path); |
10342 | | |
10343 | | return return_value; |
10344 | | } |
10345 | | |
10346 | | #endif /* defined(MS_WINDOWS) */ |
10347 | | |
10348 | | #if defined(HAVE_FPATHCONF) |
10349 | | |
10350 | | PyDoc_STRVAR(os_fpathconf__doc__, |
10351 | | "fpathconf($module, fd, name, /)\n" |
10352 | | "--\n" |
10353 | | "\n" |
10354 | | "Return the configuration limit name for the file descriptor fd.\n" |
10355 | | "\n" |
10356 | | "If there is no limit, return -1."); |
10357 | | |
10358 | | #define OS_FPATHCONF_METHODDEF \ |
10359 | | {"fpathconf", _PyCFunction_CAST(os_fpathconf), METH_FASTCALL, os_fpathconf__doc__}, |
10360 | | |
10361 | | static long |
10362 | | os_fpathconf_impl(PyObject *module, int fd, int name); |
10363 | | |
10364 | | static PyObject * |
10365 | | os_fpathconf(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
10366 | 0 | { |
10367 | 0 | PyObject *return_value = NULL; |
10368 | 0 | int fd; |
10369 | 0 | int name; |
10370 | 0 | long _return_value; |
10371 | |
|
10372 | 0 | if (!_PyArg_CheckPositional("fpathconf", nargs, 2, 2)) { |
10373 | 0 | goto exit; |
10374 | 0 | } |
10375 | 0 | fd = PyObject_AsFileDescriptor(args[0]); |
10376 | 0 | if (fd < 0) { |
10377 | 0 | goto exit; |
10378 | 0 | } |
10379 | 0 | if (!conv_confname(module, args[1], &name, "pathconf_names")) { |
10380 | 0 | goto exit; |
10381 | 0 | } |
10382 | 0 | _return_value = os_fpathconf_impl(module, fd, name); |
10383 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
10384 | 0 | goto exit; |
10385 | 0 | } |
10386 | 0 | return_value = PyLong_FromLong(_return_value); |
10387 | |
|
10388 | 0 | exit: |
10389 | 0 | return return_value; |
10390 | 0 | } |
10391 | | |
10392 | | #endif /* defined(HAVE_FPATHCONF) */ |
10393 | | |
10394 | | #if defined(HAVE_PATHCONF) |
10395 | | |
10396 | | PyDoc_STRVAR(os_pathconf__doc__, |
10397 | | "pathconf($module, /, path, name)\n" |
10398 | | "--\n" |
10399 | | "\n" |
10400 | | "Return the configuration limit name for the file or directory path.\n" |
10401 | | "\n" |
10402 | | "If there is no limit, return -1.\n" |
10403 | | "On some platforms, path may also be specified as an open file descriptor.\n" |
10404 | | " If this functionality is unavailable, using it raises an exception."); |
10405 | | |
10406 | | #define OS_PATHCONF_METHODDEF \ |
10407 | | {"pathconf", _PyCFunction_CAST(os_pathconf), METH_FASTCALL|METH_KEYWORDS, os_pathconf__doc__}, |
10408 | | |
10409 | | static long |
10410 | | os_pathconf_impl(PyObject *module, path_t *path, int name); |
10411 | | |
10412 | | static PyObject * |
10413 | | os_pathconf(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
10414 | 0 | { |
10415 | 0 | PyObject *return_value = NULL; |
10416 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
10417 | |
|
10418 | 0 | #define NUM_KEYWORDS 2 |
10419 | 0 | static struct { |
10420 | 0 | PyGC_Head _this_is_not_used; |
10421 | 0 | PyObject_VAR_HEAD |
10422 | 0 | Py_hash_t ob_hash; |
10423 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
10424 | 0 | } _kwtuple = { |
10425 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
10426 | 0 | .ob_hash = -1, |
10427 | 0 | .ob_item = { &_Py_ID(path), &_Py_ID(name), }, |
10428 | 0 | }; |
10429 | 0 | #undef NUM_KEYWORDS |
10430 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
10431 | |
|
10432 | | #else // !Py_BUILD_CORE |
10433 | | # define KWTUPLE NULL |
10434 | | #endif // !Py_BUILD_CORE |
10435 | |
|
10436 | 0 | static const char * const _keywords[] = {"path", "name", NULL}; |
10437 | 0 | static _PyArg_Parser _parser = { |
10438 | 0 | .keywords = _keywords, |
10439 | 0 | .fname = "pathconf", |
10440 | 0 | .kwtuple = KWTUPLE, |
10441 | 0 | }; |
10442 | 0 | #undef KWTUPLE |
10443 | 0 | PyObject *argsbuf[2]; |
10444 | 0 | path_t path = PATH_T_INITIALIZE_P("pathconf", "path", 0, 0, 0, PATH_HAVE_FPATHCONF); |
10445 | 0 | int name; |
10446 | 0 | long _return_value; |
10447 | |
|
10448 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
10449 | 0 | /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
10450 | 0 | if (!args) { |
10451 | 0 | goto exit; |
10452 | 0 | } |
10453 | 0 | if (!path_converter(args[0], &path)) { |
10454 | 0 | goto exit; |
10455 | 0 | } |
10456 | 0 | if (!conv_confname(module, args[1], &name, "pathconf_names")) { |
10457 | 0 | goto exit; |
10458 | 0 | } |
10459 | 0 | _return_value = os_pathconf_impl(module, &path, name); |
10460 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
10461 | 0 | goto exit; |
10462 | 0 | } |
10463 | 0 | return_value = PyLong_FromLong(_return_value); |
10464 | |
|
10465 | 0 | exit: |
10466 | | /* Cleanup for path */ |
10467 | 0 | path_cleanup(&path); |
10468 | |
|
10469 | 0 | return return_value; |
10470 | 0 | } |
10471 | | |
10472 | | #endif /* defined(HAVE_PATHCONF) */ |
10473 | | |
10474 | | #if defined(HAVE_CONFSTR) |
10475 | | |
10476 | | PyDoc_STRVAR(os_confstr__doc__, |
10477 | | "confstr($module, name, /)\n" |
10478 | | "--\n" |
10479 | | "\n" |
10480 | | "Return a string-valued system configuration variable."); |
10481 | | |
10482 | | #define OS_CONFSTR_METHODDEF \ |
10483 | | {"confstr", (PyCFunction)os_confstr, METH_O, os_confstr__doc__}, |
10484 | | |
10485 | | static PyObject * |
10486 | | os_confstr_impl(PyObject *module, int name); |
10487 | | |
10488 | | static PyObject * |
10489 | | os_confstr(PyObject *module, PyObject *arg) |
10490 | 0 | { |
10491 | 0 | PyObject *return_value = NULL; |
10492 | 0 | int name; |
10493 | |
|
10494 | 0 | if (!conv_confname(module, arg, &name, "confstr_names")) { |
10495 | 0 | goto exit; |
10496 | 0 | } |
10497 | 0 | return_value = os_confstr_impl(module, name); |
10498 | |
|
10499 | 0 | exit: |
10500 | 0 | return return_value; |
10501 | 0 | } |
10502 | | |
10503 | | #endif /* defined(HAVE_CONFSTR) */ |
10504 | | |
10505 | | #if defined(HAVE_SYSCONF) |
10506 | | |
10507 | | PyDoc_STRVAR(os_sysconf__doc__, |
10508 | | "sysconf($module, name, /)\n" |
10509 | | "--\n" |
10510 | | "\n" |
10511 | | "Return an integer-valued system configuration variable."); |
10512 | | |
10513 | | #define OS_SYSCONF_METHODDEF \ |
10514 | | {"sysconf", (PyCFunction)os_sysconf, METH_O, os_sysconf__doc__}, |
10515 | | |
10516 | | static long |
10517 | | os_sysconf_impl(PyObject *module, int name); |
10518 | | |
10519 | | static PyObject * |
10520 | | os_sysconf(PyObject *module, PyObject *arg) |
10521 | 0 | { |
10522 | 0 | PyObject *return_value = NULL; |
10523 | 0 | int name; |
10524 | 0 | long _return_value; |
10525 | |
|
10526 | 0 | if (!conv_confname(module, arg, &name, "sysconf_names")) { |
10527 | 0 | goto exit; |
10528 | 0 | } |
10529 | 0 | _return_value = os_sysconf_impl(module, name); |
10530 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
10531 | 0 | goto exit; |
10532 | 0 | } |
10533 | 0 | return_value = PyLong_FromLong(_return_value); |
10534 | |
|
10535 | 0 | exit: |
10536 | 0 | return return_value; |
10537 | 0 | } |
10538 | | |
10539 | | #endif /* defined(HAVE_SYSCONF) */ |
10540 | | |
10541 | | PyDoc_STRVAR(os_abort__doc__, |
10542 | | "abort($module, /)\n" |
10543 | | "--\n" |
10544 | | "\n" |
10545 | | "Abort the interpreter immediately.\n" |
10546 | | "\n" |
10547 | | "This function \'dumps core\' or otherwise fails in the hardest way possible\n" |
10548 | | "on the hosting operating system. This function never returns."); |
10549 | | |
10550 | | #define OS_ABORT_METHODDEF \ |
10551 | | {"abort", (PyCFunction)os_abort, METH_NOARGS, os_abort__doc__}, |
10552 | | |
10553 | | static PyObject * |
10554 | | os_abort_impl(PyObject *module); |
10555 | | |
10556 | | static PyObject * |
10557 | | os_abort(PyObject *module, PyObject *Py_UNUSED(ignored)) |
10558 | 0 | { |
10559 | 0 | return os_abort_impl(module); |
10560 | 0 | } |
10561 | | |
10562 | | #if defined(MS_WINDOWS) |
10563 | | |
10564 | | PyDoc_STRVAR(os_startfile__doc__, |
10565 | | "startfile($module, /, filepath, operation=<unrepresentable>,\n" |
10566 | | " arguments=<unrepresentable>, cwd=None, show_cmd=1)\n" |
10567 | | "--\n" |
10568 | | "\n" |
10569 | | "Start a file with its associated application.\n" |
10570 | | "\n" |
10571 | | "When \"operation\" is not specified or \"open\", this acts like\n" |
10572 | | "double-clicking the file in Explorer, or giving the file name as an\n" |
10573 | | "argument to the DOS \"start\" command: the file is opened with whatever\n" |
10574 | | "application (if any) its extension is associated.\n" |
10575 | | "When another \"operation\" is given, it specifies what should be done with\n" |
10576 | | "the file. A typical operation is \"print\".\n" |
10577 | | "\n" |
10578 | | "\"arguments\" is passed to the application, but should be omitted if the\n" |
10579 | | "file is a document.\n" |
10580 | | "\n" |
10581 | | "\"cwd\" is the working directory for the operation. If \"filepath\" is\n" |
10582 | | "relative, it will be resolved against this directory. This argument\n" |
10583 | | "should usually be an absolute path.\n" |
10584 | | "\n" |
10585 | | "\"show_cmd\" can be used to override the recommended visibility option.\n" |
10586 | | "See the Windows ShellExecute documentation for values.\n" |
10587 | | "\n" |
10588 | | "startfile returns as soon as the associated application is launched.\n" |
10589 | | "There is no option to wait for the application to close, and no way\n" |
10590 | | "to retrieve the application\'s exit status.\n" |
10591 | | "\n" |
10592 | | "The filepath is relative to the current directory. If you want to use\n" |
10593 | | "an absolute path, make sure the first character is not a slash (\"/\");\n" |
10594 | | "the underlying Win32 ShellExecute function doesn\'t work if it is."); |
10595 | | |
10596 | | #define OS_STARTFILE_METHODDEF \ |
10597 | | {"startfile", _PyCFunction_CAST(os_startfile), METH_FASTCALL|METH_KEYWORDS, os_startfile__doc__}, |
10598 | | |
10599 | | static PyObject * |
10600 | | os_startfile_impl(PyObject *module, path_t *filepath, |
10601 | | const wchar_t *operation, const wchar_t *arguments, |
10602 | | path_t *cwd, int show_cmd); |
10603 | | |
10604 | | static PyObject * |
10605 | | os_startfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
10606 | | { |
10607 | | PyObject *return_value = NULL; |
10608 | | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
10609 | | |
10610 | | #define NUM_KEYWORDS 5 |
10611 | | static struct { |
10612 | | PyGC_Head _this_is_not_used; |
10613 | | PyObject_VAR_HEAD |
10614 | | Py_hash_t ob_hash; |
10615 | | PyObject *ob_item[NUM_KEYWORDS]; |
10616 | | } _kwtuple = { |
10617 | | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
10618 | | .ob_hash = -1, |
10619 | | .ob_item = { &_Py_ID(filepath), &_Py_ID(operation), &_Py_ID(arguments), &_Py_ID(cwd), &_Py_ID(show_cmd), }, |
10620 | | }; |
10621 | | #undef NUM_KEYWORDS |
10622 | | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
10623 | | |
10624 | | #else // !Py_BUILD_CORE |
10625 | | # define KWTUPLE NULL |
10626 | | #endif // !Py_BUILD_CORE |
10627 | | |
10628 | | static const char * const _keywords[] = {"filepath", "operation", "arguments", "cwd", "show_cmd", NULL}; |
10629 | | static _PyArg_Parser _parser = { |
10630 | | .keywords = _keywords, |
10631 | | .fname = "startfile", |
10632 | | .kwtuple = KWTUPLE, |
10633 | | }; |
10634 | | #undef KWTUPLE |
10635 | | PyObject *argsbuf[5]; |
10636 | | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
10637 | | path_t filepath = PATH_T_INITIALIZE_P("startfile", "filepath", 0, 0, 0, 0); |
10638 | | const wchar_t *operation = NULL; |
10639 | | const wchar_t *arguments = NULL; |
10640 | | path_t cwd = PATH_T_INITIALIZE_P("startfile", "cwd", 1, 0, 0, 0); |
10641 | | int show_cmd = 1; |
10642 | | |
10643 | | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
10644 | | /*minpos*/ 1, /*maxpos*/ 5, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
10645 | | if (!args) { |
10646 | | goto exit; |
10647 | | } |
10648 | | if (!path_converter(args[0], &filepath)) { |
10649 | | goto exit; |
10650 | | } |
10651 | | if (!noptargs) { |
10652 | | goto skip_optional_pos; |
10653 | | } |
10654 | | if (args[1]) { |
10655 | | if (!PyUnicode_Check(args[1])) { |
10656 | | _PyArg_BadArgument("startfile", "argument 'operation'", "str", args[1]); |
10657 | | goto exit; |
10658 | | } |
10659 | | operation = PyUnicode_AsWideCharString(args[1], NULL); |
10660 | | if (operation == NULL) { |
10661 | | goto exit; |
10662 | | } |
10663 | | if (!--noptargs) { |
10664 | | goto skip_optional_pos; |
10665 | | } |
10666 | | } |
10667 | | if (args[2]) { |
10668 | | if (!PyUnicode_Check(args[2])) { |
10669 | | _PyArg_BadArgument("startfile", "argument 'arguments'", "str", args[2]); |
10670 | | goto exit; |
10671 | | } |
10672 | | arguments = PyUnicode_AsWideCharString(args[2], NULL); |
10673 | | if (arguments == NULL) { |
10674 | | goto exit; |
10675 | | } |
10676 | | if (!--noptargs) { |
10677 | | goto skip_optional_pos; |
10678 | | } |
10679 | | } |
10680 | | if (args[3]) { |
10681 | | if (!path_converter(args[3], &cwd)) { |
10682 | | goto exit; |
10683 | | } |
10684 | | if (!--noptargs) { |
10685 | | goto skip_optional_pos; |
10686 | | } |
10687 | | } |
10688 | | show_cmd = PyLong_AsInt(args[4]); |
10689 | | if (show_cmd == -1 && PyErr_Occurred()) { |
10690 | | goto exit; |
10691 | | } |
10692 | | skip_optional_pos: |
10693 | | return_value = os_startfile_impl(module, &filepath, operation, arguments, &cwd, show_cmd); |
10694 | | |
10695 | | exit: |
10696 | | /* Cleanup for filepath */ |
10697 | | path_cleanup(&filepath); |
10698 | | /* Cleanup for operation */ |
10699 | | PyMem_Free((void *)operation); |
10700 | | /* Cleanup for arguments */ |
10701 | | PyMem_Free((void *)arguments); |
10702 | | /* Cleanup for cwd */ |
10703 | | path_cleanup(&cwd); |
10704 | | |
10705 | | return return_value; |
10706 | | } |
10707 | | |
10708 | | #endif /* defined(MS_WINDOWS) */ |
10709 | | |
10710 | | #if defined(HAVE_GETLOADAVG) |
10711 | | |
10712 | | PyDoc_STRVAR(os_getloadavg__doc__, |
10713 | | "getloadavg($module, /)\n" |
10714 | | "--\n" |
10715 | | "\n" |
10716 | | "Return average recent system load information.\n" |
10717 | | "\n" |
10718 | | "Return the number of processes in the system run queue averaged over\n" |
10719 | | "the last 1, 5, and 15 minutes as a tuple of three floats.\n" |
10720 | | "Raises OSError if the load average was unobtainable."); |
10721 | | |
10722 | | #define OS_GETLOADAVG_METHODDEF \ |
10723 | | {"getloadavg", (PyCFunction)os_getloadavg, METH_NOARGS, os_getloadavg__doc__}, |
10724 | | |
10725 | | static PyObject * |
10726 | | os_getloadavg_impl(PyObject *module); |
10727 | | |
10728 | | static PyObject * |
10729 | | os_getloadavg(PyObject *module, PyObject *Py_UNUSED(ignored)) |
10730 | 0 | { |
10731 | 0 | return os_getloadavg_impl(module); |
10732 | 0 | } |
10733 | | |
10734 | | #endif /* defined(HAVE_GETLOADAVG) */ |
10735 | | |
10736 | | PyDoc_STRVAR(os_device_encoding__doc__, |
10737 | | "device_encoding($module, /, fd)\n" |
10738 | | "--\n" |
10739 | | "\n" |
10740 | | "Return a string describing the encoding of a terminal\'s file descriptor.\n" |
10741 | | "\n" |
10742 | | "The file descriptor must be attached to a terminal.\n" |
10743 | | "If the device is not a terminal, return None."); |
10744 | | |
10745 | | #define OS_DEVICE_ENCODING_METHODDEF \ |
10746 | | {"device_encoding", _PyCFunction_CAST(os_device_encoding), METH_FASTCALL|METH_KEYWORDS, os_device_encoding__doc__}, |
10747 | | |
10748 | | static PyObject * |
10749 | | os_device_encoding_impl(PyObject *module, int fd); |
10750 | | |
10751 | | static PyObject * |
10752 | | os_device_encoding(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
10753 | 0 | { |
10754 | 0 | PyObject *return_value = NULL; |
10755 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
10756 | |
|
10757 | 0 | #define NUM_KEYWORDS 1 |
10758 | 0 | static struct { |
10759 | 0 | PyGC_Head _this_is_not_used; |
10760 | 0 | PyObject_VAR_HEAD |
10761 | 0 | Py_hash_t ob_hash; |
10762 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
10763 | 0 | } _kwtuple = { |
10764 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
10765 | 0 | .ob_hash = -1, |
10766 | 0 | .ob_item = { &_Py_ID(fd), }, |
10767 | 0 | }; |
10768 | 0 | #undef NUM_KEYWORDS |
10769 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
10770 | |
|
10771 | | #else // !Py_BUILD_CORE |
10772 | | # define KWTUPLE NULL |
10773 | | #endif // !Py_BUILD_CORE |
10774 | |
|
10775 | 0 | static const char * const _keywords[] = {"fd", NULL}; |
10776 | 0 | static _PyArg_Parser _parser = { |
10777 | 0 | .keywords = _keywords, |
10778 | 0 | .fname = "device_encoding", |
10779 | 0 | .kwtuple = KWTUPLE, |
10780 | 0 | }; |
10781 | 0 | #undef KWTUPLE |
10782 | 0 | PyObject *argsbuf[1]; |
10783 | 0 | int fd; |
10784 | |
|
10785 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
10786 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
10787 | 0 | if (!args) { |
10788 | 0 | goto exit; |
10789 | 0 | } |
10790 | 0 | fd = PyLong_AsInt(args[0]); |
10791 | 0 | if (fd == -1 && PyErr_Occurred()) { |
10792 | 0 | goto exit; |
10793 | 0 | } |
10794 | 0 | return_value = os_device_encoding_impl(module, fd); |
10795 | |
|
10796 | 0 | exit: |
10797 | 0 | return return_value; |
10798 | 0 | } |
10799 | | |
10800 | | #if defined(HAVE_SETRESUID) |
10801 | | |
10802 | | PyDoc_STRVAR(os_setresuid__doc__, |
10803 | | "setresuid($module, ruid, euid, suid, /)\n" |
10804 | | "--\n" |
10805 | | "\n" |
10806 | | "Set the current process\'s real, effective, and saved user ids."); |
10807 | | |
10808 | | #define OS_SETRESUID_METHODDEF \ |
10809 | | {"setresuid", _PyCFunction_CAST(os_setresuid), METH_FASTCALL, os_setresuid__doc__}, |
10810 | | |
10811 | | static PyObject * |
10812 | | os_setresuid_impl(PyObject *module, uid_t ruid, uid_t euid, uid_t suid); |
10813 | | |
10814 | | static PyObject * |
10815 | | os_setresuid(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
10816 | 0 | { |
10817 | 0 | PyObject *return_value = NULL; |
10818 | 0 | uid_t ruid; |
10819 | 0 | uid_t euid; |
10820 | 0 | uid_t suid; |
10821 | |
|
10822 | 0 | if (!_PyArg_CheckPositional("setresuid", nargs, 3, 3)) { |
10823 | 0 | goto exit; |
10824 | 0 | } |
10825 | 0 | if (!_Py_Uid_Converter(args[0], &ruid)) { |
10826 | 0 | goto exit; |
10827 | 0 | } |
10828 | 0 | if (!_Py_Uid_Converter(args[1], &euid)) { |
10829 | 0 | goto exit; |
10830 | 0 | } |
10831 | 0 | if (!_Py_Uid_Converter(args[2], &suid)) { |
10832 | 0 | goto exit; |
10833 | 0 | } |
10834 | 0 | return_value = os_setresuid_impl(module, ruid, euid, suid); |
10835 | |
|
10836 | 0 | exit: |
10837 | 0 | return return_value; |
10838 | 0 | } |
10839 | | |
10840 | | #endif /* defined(HAVE_SETRESUID) */ |
10841 | | |
10842 | | #if defined(HAVE_SETRESGID) |
10843 | | |
10844 | | PyDoc_STRVAR(os_setresgid__doc__, |
10845 | | "setresgid($module, rgid, egid, sgid, /)\n" |
10846 | | "--\n" |
10847 | | "\n" |
10848 | | "Set the current process\'s real, effective, and saved group ids."); |
10849 | | |
10850 | | #define OS_SETRESGID_METHODDEF \ |
10851 | | {"setresgid", _PyCFunction_CAST(os_setresgid), METH_FASTCALL, os_setresgid__doc__}, |
10852 | | |
10853 | | static PyObject * |
10854 | | os_setresgid_impl(PyObject *module, gid_t rgid, gid_t egid, gid_t sgid); |
10855 | | |
10856 | | static PyObject * |
10857 | | os_setresgid(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
10858 | 0 | { |
10859 | 0 | PyObject *return_value = NULL; |
10860 | 0 | gid_t rgid; |
10861 | 0 | gid_t egid; |
10862 | 0 | gid_t sgid; |
10863 | |
|
10864 | 0 | if (!_PyArg_CheckPositional("setresgid", nargs, 3, 3)) { |
10865 | 0 | goto exit; |
10866 | 0 | } |
10867 | 0 | if (!_Py_Gid_Converter(args[0], &rgid)) { |
10868 | 0 | goto exit; |
10869 | 0 | } |
10870 | 0 | if (!_Py_Gid_Converter(args[1], &egid)) { |
10871 | 0 | goto exit; |
10872 | 0 | } |
10873 | 0 | if (!_Py_Gid_Converter(args[2], &sgid)) { |
10874 | 0 | goto exit; |
10875 | 0 | } |
10876 | 0 | return_value = os_setresgid_impl(module, rgid, egid, sgid); |
10877 | |
|
10878 | 0 | exit: |
10879 | 0 | return return_value; |
10880 | 0 | } |
10881 | | |
10882 | | #endif /* defined(HAVE_SETRESGID) */ |
10883 | | |
10884 | | #if defined(HAVE_GETRESUID) |
10885 | | |
10886 | | PyDoc_STRVAR(os_getresuid__doc__, |
10887 | | "getresuid($module, /)\n" |
10888 | | "--\n" |
10889 | | "\n" |
10890 | | "Return a tuple of the current process\'s real, effective, and saved user ids."); |
10891 | | |
10892 | | #define OS_GETRESUID_METHODDEF \ |
10893 | | {"getresuid", (PyCFunction)os_getresuid, METH_NOARGS, os_getresuid__doc__}, |
10894 | | |
10895 | | static PyObject * |
10896 | | os_getresuid_impl(PyObject *module); |
10897 | | |
10898 | | static PyObject * |
10899 | | os_getresuid(PyObject *module, PyObject *Py_UNUSED(ignored)) |
10900 | 0 | { |
10901 | 0 | return os_getresuid_impl(module); |
10902 | 0 | } |
10903 | | |
10904 | | #endif /* defined(HAVE_GETRESUID) */ |
10905 | | |
10906 | | #if defined(HAVE_GETRESGID) |
10907 | | |
10908 | | PyDoc_STRVAR(os_getresgid__doc__, |
10909 | | "getresgid($module, /)\n" |
10910 | | "--\n" |
10911 | | "\n" |
10912 | | "Return a tuple of the current process\'s real, effective, and saved group ids."); |
10913 | | |
10914 | | #define OS_GETRESGID_METHODDEF \ |
10915 | | {"getresgid", (PyCFunction)os_getresgid, METH_NOARGS, os_getresgid__doc__}, |
10916 | | |
10917 | | static PyObject * |
10918 | | os_getresgid_impl(PyObject *module); |
10919 | | |
10920 | | static PyObject * |
10921 | | os_getresgid(PyObject *module, PyObject *Py_UNUSED(ignored)) |
10922 | 0 | { |
10923 | 0 | return os_getresgid_impl(module); |
10924 | 0 | } |
10925 | | |
10926 | | #endif /* defined(HAVE_GETRESGID) */ |
10927 | | |
10928 | | #if defined(USE_XATTRS) |
10929 | | |
10930 | | PyDoc_STRVAR(os_getxattr__doc__, |
10931 | | "getxattr($module, /, path, attribute, *, follow_symlinks=True)\n" |
10932 | | "--\n" |
10933 | | "\n" |
10934 | | "Return the value of extended attribute attribute on path.\n" |
10935 | | "\n" |
10936 | | "path may be either a string, a path-like object, or an open file descriptor.\n" |
10937 | | "If follow_symlinks is False, and the last element of the path is a symbolic\n" |
10938 | | " link, getxattr will examine the symbolic link itself instead of the file\n" |
10939 | | " the link points to."); |
10940 | | |
10941 | | #define OS_GETXATTR_METHODDEF \ |
10942 | | {"getxattr", _PyCFunction_CAST(os_getxattr), METH_FASTCALL|METH_KEYWORDS, os_getxattr__doc__}, |
10943 | | |
10944 | | static PyObject * |
10945 | | os_getxattr_impl(PyObject *module, path_t *path, path_t *attribute, |
10946 | | int follow_symlinks); |
10947 | | |
10948 | | static PyObject * |
10949 | | os_getxattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
10950 | 0 | { |
10951 | 0 | PyObject *return_value = NULL; |
10952 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
10953 | |
|
10954 | 0 | #define NUM_KEYWORDS 3 |
10955 | 0 | static struct { |
10956 | 0 | PyGC_Head _this_is_not_used; |
10957 | 0 | PyObject_VAR_HEAD |
10958 | 0 | Py_hash_t ob_hash; |
10959 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
10960 | 0 | } _kwtuple = { |
10961 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
10962 | 0 | .ob_hash = -1, |
10963 | 0 | .ob_item = { &_Py_ID(path), &_Py_ID(attribute), &_Py_ID(follow_symlinks), }, |
10964 | 0 | }; |
10965 | 0 | #undef NUM_KEYWORDS |
10966 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
10967 | |
|
10968 | | #else // !Py_BUILD_CORE |
10969 | | # define KWTUPLE NULL |
10970 | | #endif // !Py_BUILD_CORE |
10971 | |
|
10972 | 0 | static const char * const _keywords[] = {"path", "attribute", "follow_symlinks", NULL}; |
10973 | 0 | static _PyArg_Parser _parser = { |
10974 | 0 | .keywords = _keywords, |
10975 | 0 | .fname = "getxattr", |
10976 | 0 | .kwtuple = KWTUPLE, |
10977 | 0 | }; |
10978 | 0 | #undef KWTUPLE |
10979 | 0 | PyObject *argsbuf[3]; |
10980 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2; |
10981 | 0 | path_t path = PATH_T_INITIALIZE_P("getxattr", "path", 0, 0, 0, 1); |
10982 | 0 | path_t attribute = PATH_T_INITIALIZE_P("getxattr", "attribute", 0, 0, 0, 0); |
10983 | 0 | int follow_symlinks = 1; |
10984 | |
|
10985 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
10986 | 0 | /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
10987 | 0 | if (!args) { |
10988 | 0 | goto exit; |
10989 | 0 | } |
10990 | 0 | if (!path_converter(args[0], &path)) { |
10991 | 0 | goto exit; |
10992 | 0 | } |
10993 | 0 | if (!path_converter(args[1], &attribute)) { |
10994 | 0 | goto exit; |
10995 | 0 | } |
10996 | 0 | if (!noptargs) { |
10997 | 0 | goto skip_optional_kwonly; |
10998 | 0 | } |
10999 | 0 | follow_symlinks = PyObject_IsTrue(args[2]); |
11000 | 0 | if (follow_symlinks < 0) { |
11001 | 0 | goto exit; |
11002 | 0 | } |
11003 | 0 | skip_optional_kwonly: |
11004 | 0 | return_value = os_getxattr_impl(module, &path, &attribute, follow_symlinks); |
11005 | |
|
11006 | 0 | exit: |
11007 | | /* Cleanup for path */ |
11008 | 0 | path_cleanup(&path); |
11009 | | /* Cleanup for attribute */ |
11010 | 0 | path_cleanup(&attribute); |
11011 | |
|
11012 | 0 | return return_value; |
11013 | 0 | } |
11014 | | |
11015 | | #endif /* defined(USE_XATTRS) */ |
11016 | | |
11017 | | #if defined(USE_XATTRS) |
11018 | | |
11019 | | PyDoc_STRVAR(os_setxattr__doc__, |
11020 | | "setxattr($module, /, path, attribute, value, flags=0, *,\n" |
11021 | | " follow_symlinks=True)\n" |
11022 | | "--\n" |
11023 | | "\n" |
11024 | | "Set extended attribute attribute on path to value.\n" |
11025 | | "\n" |
11026 | | "path may be either a string, a path-like object, or an open file descriptor.\n" |
11027 | | "If follow_symlinks is False, and the last element of the path is a symbolic\n" |
11028 | | " link, setxattr will modify the symbolic link itself instead of the file\n" |
11029 | | " the link points to."); |
11030 | | |
11031 | | #define OS_SETXATTR_METHODDEF \ |
11032 | | {"setxattr", _PyCFunction_CAST(os_setxattr), METH_FASTCALL|METH_KEYWORDS, os_setxattr__doc__}, |
11033 | | |
11034 | | static PyObject * |
11035 | | os_setxattr_impl(PyObject *module, path_t *path, path_t *attribute, |
11036 | | Py_buffer *value, int flags, int follow_symlinks); |
11037 | | |
11038 | | static PyObject * |
11039 | | os_setxattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
11040 | 0 | { |
11041 | 0 | PyObject *return_value = NULL; |
11042 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
11043 | |
|
11044 | 0 | #define NUM_KEYWORDS 5 |
11045 | 0 | static struct { |
11046 | 0 | PyGC_Head _this_is_not_used; |
11047 | 0 | PyObject_VAR_HEAD |
11048 | 0 | Py_hash_t ob_hash; |
11049 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
11050 | 0 | } _kwtuple = { |
11051 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
11052 | 0 | .ob_hash = -1, |
11053 | 0 | .ob_item = { &_Py_ID(path), &_Py_ID(attribute), &_Py_ID(value), &_Py_ID(flags), &_Py_ID(follow_symlinks), }, |
11054 | 0 | }; |
11055 | 0 | #undef NUM_KEYWORDS |
11056 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
11057 | |
|
11058 | | #else // !Py_BUILD_CORE |
11059 | | # define KWTUPLE NULL |
11060 | | #endif // !Py_BUILD_CORE |
11061 | |
|
11062 | 0 | static const char * const _keywords[] = {"path", "attribute", "value", "flags", "follow_symlinks", NULL}; |
11063 | 0 | static _PyArg_Parser _parser = { |
11064 | 0 | .keywords = _keywords, |
11065 | 0 | .fname = "setxattr", |
11066 | 0 | .kwtuple = KWTUPLE, |
11067 | 0 | }; |
11068 | 0 | #undef KWTUPLE |
11069 | 0 | PyObject *argsbuf[5]; |
11070 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3; |
11071 | 0 | path_t path = PATH_T_INITIALIZE_P("setxattr", "path", 0, 0, 0, 1); |
11072 | 0 | path_t attribute = PATH_T_INITIALIZE_P("setxattr", "attribute", 0, 0, 0, 0); |
11073 | 0 | Py_buffer value = {NULL, NULL}; |
11074 | 0 | int flags = 0; |
11075 | 0 | int follow_symlinks = 1; |
11076 | |
|
11077 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
11078 | 0 | /*minpos*/ 3, /*maxpos*/ 4, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
11079 | 0 | if (!args) { |
11080 | 0 | goto exit; |
11081 | 0 | } |
11082 | 0 | if (!path_converter(args[0], &path)) { |
11083 | 0 | goto exit; |
11084 | 0 | } |
11085 | 0 | if (!path_converter(args[1], &attribute)) { |
11086 | 0 | goto exit; |
11087 | 0 | } |
11088 | 0 | if (PyObject_GetBuffer(args[2], &value, PyBUF_SIMPLE) != 0) { |
11089 | 0 | goto exit; |
11090 | 0 | } |
11091 | 0 | if (!noptargs) { |
11092 | 0 | goto skip_optional_pos; |
11093 | 0 | } |
11094 | 0 | if (args[3]) { |
11095 | 0 | flags = PyLong_AsInt(args[3]); |
11096 | 0 | if (flags == -1 && PyErr_Occurred()) { |
11097 | 0 | goto exit; |
11098 | 0 | } |
11099 | 0 | if (!--noptargs) { |
11100 | 0 | goto skip_optional_pos; |
11101 | 0 | } |
11102 | 0 | } |
11103 | 0 | skip_optional_pos: |
11104 | 0 | if (!noptargs) { |
11105 | 0 | goto skip_optional_kwonly; |
11106 | 0 | } |
11107 | 0 | follow_symlinks = PyObject_IsTrue(args[4]); |
11108 | 0 | if (follow_symlinks < 0) { |
11109 | 0 | goto exit; |
11110 | 0 | } |
11111 | 0 | skip_optional_kwonly: |
11112 | 0 | return_value = os_setxattr_impl(module, &path, &attribute, &value, flags, follow_symlinks); |
11113 | |
|
11114 | 0 | exit: |
11115 | | /* Cleanup for path */ |
11116 | 0 | path_cleanup(&path); |
11117 | | /* Cleanup for attribute */ |
11118 | 0 | path_cleanup(&attribute); |
11119 | | /* Cleanup for value */ |
11120 | 0 | if (value.obj) { |
11121 | 0 | PyBuffer_Release(&value); |
11122 | 0 | } |
11123 | |
|
11124 | 0 | return return_value; |
11125 | 0 | } |
11126 | | |
11127 | | #endif /* defined(USE_XATTRS) */ |
11128 | | |
11129 | | #if defined(USE_XATTRS) |
11130 | | |
11131 | | PyDoc_STRVAR(os_removexattr__doc__, |
11132 | | "removexattr($module, /, path, attribute, *, follow_symlinks=True)\n" |
11133 | | "--\n" |
11134 | | "\n" |
11135 | | "Remove extended attribute attribute on path.\n" |
11136 | | "\n" |
11137 | | "path may be either a string, a path-like object, or an open file descriptor.\n" |
11138 | | "If follow_symlinks is False, and the last element of the path is a symbolic\n" |
11139 | | " link, removexattr will modify the symbolic link itself instead of the file\n" |
11140 | | " the link points to."); |
11141 | | |
11142 | | #define OS_REMOVEXATTR_METHODDEF \ |
11143 | | {"removexattr", _PyCFunction_CAST(os_removexattr), METH_FASTCALL|METH_KEYWORDS, os_removexattr__doc__}, |
11144 | | |
11145 | | static PyObject * |
11146 | | os_removexattr_impl(PyObject *module, path_t *path, path_t *attribute, |
11147 | | int follow_symlinks); |
11148 | | |
11149 | | static PyObject * |
11150 | | os_removexattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
11151 | 0 | { |
11152 | 0 | PyObject *return_value = NULL; |
11153 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
11154 | |
|
11155 | 0 | #define NUM_KEYWORDS 3 |
11156 | 0 | static struct { |
11157 | 0 | PyGC_Head _this_is_not_used; |
11158 | 0 | PyObject_VAR_HEAD |
11159 | 0 | Py_hash_t ob_hash; |
11160 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
11161 | 0 | } _kwtuple = { |
11162 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
11163 | 0 | .ob_hash = -1, |
11164 | 0 | .ob_item = { &_Py_ID(path), &_Py_ID(attribute), &_Py_ID(follow_symlinks), }, |
11165 | 0 | }; |
11166 | 0 | #undef NUM_KEYWORDS |
11167 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
11168 | |
|
11169 | | #else // !Py_BUILD_CORE |
11170 | | # define KWTUPLE NULL |
11171 | | #endif // !Py_BUILD_CORE |
11172 | |
|
11173 | 0 | static const char * const _keywords[] = {"path", "attribute", "follow_symlinks", NULL}; |
11174 | 0 | static _PyArg_Parser _parser = { |
11175 | 0 | .keywords = _keywords, |
11176 | 0 | .fname = "removexattr", |
11177 | 0 | .kwtuple = KWTUPLE, |
11178 | 0 | }; |
11179 | 0 | #undef KWTUPLE |
11180 | 0 | PyObject *argsbuf[3]; |
11181 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2; |
11182 | 0 | path_t path = PATH_T_INITIALIZE_P("removexattr", "path", 0, 0, 0, 1); |
11183 | 0 | path_t attribute = PATH_T_INITIALIZE_P("removexattr", "attribute", 0, 0, 0, 0); |
11184 | 0 | int follow_symlinks = 1; |
11185 | |
|
11186 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
11187 | 0 | /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
11188 | 0 | if (!args) { |
11189 | 0 | goto exit; |
11190 | 0 | } |
11191 | 0 | if (!path_converter(args[0], &path)) { |
11192 | 0 | goto exit; |
11193 | 0 | } |
11194 | 0 | if (!path_converter(args[1], &attribute)) { |
11195 | 0 | goto exit; |
11196 | 0 | } |
11197 | 0 | if (!noptargs) { |
11198 | 0 | goto skip_optional_kwonly; |
11199 | 0 | } |
11200 | 0 | follow_symlinks = PyObject_IsTrue(args[2]); |
11201 | 0 | if (follow_symlinks < 0) { |
11202 | 0 | goto exit; |
11203 | 0 | } |
11204 | 0 | skip_optional_kwonly: |
11205 | 0 | return_value = os_removexattr_impl(module, &path, &attribute, follow_symlinks); |
11206 | |
|
11207 | 0 | exit: |
11208 | | /* Cleanup for path */ |
11209 | 0 | path_cleanup(&path); |
11210 | | /* Cleanup for attribute */ |
11211 | 0 | path_cleanup(&attribute); |
11212 | |
|
11213 | 0 | return return_value; |
11214 | 0 | } |
11215 | | |
11216 | | #endif /* defined(USE_XATTRS) */ |
11217 | | |
11218 | | #if defined(USE_XATTRS) |
11219 | | |
11220 | | PyDoc_STRVAR(os_listxattr__doc__, |
11221 | | "listxattr($module, /, path=None, *, follow_symlinks=True)\n" |
11222 | | "--\n" |
11223 | | "\n" |
11224 | | "Return a list of extended attributes on path.\n" |
11225 | | "\n" |
11226 | | "path may be either None, a string, a path-like object, or an open file descriptor.\n" |
11227 | | "if path is None, listxattr will examine the current directory.\n" |
11228 | | "If follow_symlinks is False, and the last element of the path is a symbolic\n" |
11229 | | " link, listxattr will examine the symbolic link itself instead of the file\n" |
11230 | | " the link points to."); |
11231 | | |
11232 | | #define OS_LISTXATTR_METHODDEF \ |
11233 | | {"listxattr", _PyCFunction_CAST(os_listxattr), METH_FASTCALL|METH_KEYWORDS, os_listxattr__doc__}, |
11234 | | |
11235 | | static PyObject * |
11236 | | os_listxattr_impl(PyObject *module, path_t *path, int follow_symlinks); |
11237 | | |
11238 | | static PyObject * |
11239 | | os_listxattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
11240 | 0 | { |
11241 | 0 | PyObject *return_value = NULL; |
11242 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
11243 | |
|
11244 | 0 | #define NUM_KEYWORDS 2 |
11245 | 0 | static struct { |
11246 | 0 | PyGC_Head _this_is_not_used; |
11247 | 0 | PyObject_VAR_HEAD |
11248 | 0 | Py_hash_t ob_hash; |
11249 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
11250 | 0 | } _kwtuple = { |
11251 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
11252 | 0 | .ob_hash = -1, |
11253 | 0 | .ob_item = { &_Py_ID(path), &_Py_ID(follow_symlinks), }, |
11254 | 0 | }; |
11255 | 0 | #undef NUM_KEYWORDS |
11256 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
11257 | |
|
11258 | | #else // !Py_BUILD_CORE |
11259 | | # define KWTUPLE NULL |
11260 | | #endif // !Py_BUILD_CORE |
11261 | |
|
11262 | 0 | static const char * const _keywords[] = {"path", "follow_symlinks", NULL}; |
11263 | 0 | static _PyArg_Parser _parser = { |
11264 | 0 | .keywords = _keywords, |
11265 | 0 | .fname = "listxattr", |
11266 | 0 | .kwtuple = KWTUPLE, |
11267 | 0 | }; |
11268 | 0 | #undef KWTUPLE |
11269 | 0 | PyObject *argsbuf[2]; |
11270 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; |
11271 | 0 | path_t path = PATH_T_INITIALIZE_P("listxattr", "path", 1, 0, 0, 1); |
11272 | 0 | int follow_symlinks = 1; |
11273 | |
|
11274 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
11275 | 0 | /*minpos*/ 0, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
11276 | 0 | if (!args) { |
11277 | 0 | goto exit; |
11278 | 0 | } |
11279 | 0 | if (!noptargs) { |
11280 | 0 | goto skip_optional_pos; |
11281 | 0 | } |
11282 | 0 | if (args[0]) { |
11283 | 0 | if (!path_converter(args[0], &path)) { |
11284 | 0 | goto exit; |
11285 | 0 | } |
11286 | 0 | if (!--noptargs) { |
11287 | 0 | goto skip_optional_pos; |
11288 | 0 | } |
11289 | 0 | } |
11290 | 0 | skip_optional_pos: |
11291 | 0 | if (!noptargs) { |
11292 | 0 | goto skip_optional_kwonly; |
11293 | 0 | } |
11294 | 0 | follow_symlinks = PyObject_IsTrue(args[1]); |
11295 | 0 | if (follow_symlinks < 0) { |
11296 | 0 | goto exit; |
11297 | 0 | } |
11298 | 0 | skip_optional_kwonly: |
11299 | 0 | return_value = os_listxattr_impl(module, &path, follow_symlinks); |
11300 | |
|
11301 | 0 | exit: |
11302 | | /* Cleanup for path */ |
11303 | 0 | path_cleanup(&path); |
11304 | |
|
11305 | 0 | return return_value; |
11306 | 0 | } |
11307 | | |
11308 | | #endif /* defined(USE_XATTRS) */ |
11309 | | |
11310 | | PyDoc_STRVAR(os_urandom__doc__, |
11311 | | "urandom($module, size, /)\n" |
11312 | | "--\n" |
11313 | | "\n" |
11314 | | "Return a bytes object containing random bytes suitable for cryptographic use."); |
11315 | | |
11316 | | #define OS_URANDOM_METHODDEF \ |
11317 | | {"urandom", (PyCFunction)os_urandom, METH_O, os_urandom__doc__}, |
11318 | | |
11319 | | static PyObject * |
11320 | | os_urandom_impl(PyObject *module, Py_ssize_t size); |
11321 | | |
11322 | | static PyObject * |
11323 | | os_urandom(PyObject *module, PyObject *arg) |
11324 | 0 | { |
11325 | 0 | PyObject *return_value = NULL; |
11326 | 0 | Py_ssize_t size; |
11327 | |
|
11328 | 0 | { |
11329 | 0 | Py_ssize_t ival = -1; |
11330 | 0 | PyObject *iobj = _PyNumber_Index(arg); |
11331 | 0 | if (iobj != NULL) { |
11332 | 0 | ival = PyLong_AsSsize_t(iobj); |
11333 | 0 | Py_DECREF(iobj); |
11334 | 0 | } |
11335 | 0 | if (ival == -1 && PyErr_Occurred()) { |
11336 | 0 | goto exit; |
11337 | 0 | } |
11338 | 0 | size = ival; |
11339 | 0 | } |
11340 | 0 | return_value = os_urandom_impl(module, size); |
11341 | |
|
11342 | 0 | exit: |
11343 | 0 | return return_value; |
11344 | 0 | } |
11345 | | |
11346 | | #if defined(HAVE_MEMFD_CREATE) |
11347 | | |
11348 | | PyDoc_STRVAR(os_memfd_create__doc__, |
11349 | | "memfd_create($module, /, name, flags=MFD_CLOEXEC)\n" |
11350 | | "--\n" |
11351 | | "\n"); |
11352 | | |
11353 | | #define OS_MEMFD_CREATE_METHODDEF \ |
11354 | | {"memfd_create", _PyCFunction_CAST(os_memfd_create), METH_FASTCALL|METH_KEYWORDS, os_memfd_create__doc__}, |
11355 | | |
11356 | | static PyObject * |
11357 | | os_memfd_create_impl(PyObject *module, PyObject *name, unsigned int flags); |
11358 | | |
11359 | | static PyObject * |
11360 | | os_memfd_create(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
11361 | 0 | { |
11362 | 0 | PyObject *return_value = NULL; |
11363 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
11364 | |
|
11365 | 0 | #define NUM_KEYWORDS 2 |
11366 | 0 | static struct { |
11367 | 0 | PyGC_Head _this_is_not_used; |
11368 | 0 | PyObject_VAR_HEAD |
11369 | 0 | Py_hash_t ob_hash; |
11370 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
11371 | 0 | } _kwtuple = { |
11372 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
11373 | 0 | .ob_hash = -1, |
11374 | 0 | .ob_item = { &_Py_ID(name), &_Py_ID(flags), }, |
11375 | 0 | }; |
11376 | 0 | #undef NUM_KEYWORDS |
11377 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
11378 | |
|
11379 | | #else // !Py_BUILD_CORE |
11380 | | # define KWTUPLE NULL |
11381 | | #endif // !Py_BUILD_CORE |
11382 | |
|
11383 | 0 | static const char * const _keywords[] = {"name", "flags", NULL}; |
11384 | 0 | static _PyArg_Parser _parser = { |
11385 | 0 | .keywords = _keywords, |
11386 | 0 | .fname = "memfd_create", |
11387 | 0 | .kwtuple = KWTUPLE, |
11388 | 0 | }; |
11389 | 0 | #undef KWTUPLE |
11390 | 0 | PyObject *argsbuf[2]; |
11391 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
11392 | 0 | PyObject *name = NULL; |
11393 | 0 | unsigned int flags = MFD_CLOEXEC; |
11394 | |
|
11395 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
11396 | 0 | /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
11397 | 0 | if (!args) { |
11398 | 0 | goto exit; |
11399 | 0 | } |
11400 | 0 | if (!PyUnicode_FSConverter(args[0], &name)) { |
11401 | 0 | goto exit; |
11402 | 0 | } |
11403 | 0 | if (!noptargs) { |
11404 | 0 | goto skip_optional_pos; |
11405 | 0 | } |
11406 | 0 | { |
11407 | 0 | Py_ssize_t _bytes = PyLong_AsNativeBytes(args[1], &flags, sizeof(unsigned int), |
11408 | 0 | Py_ASNATIVEBYTES_NATIVE_ENDIAN | |
11409 | 0 | Py_ASNATIVEBYTES_ALLOW_INDEX | |
11410 | 0 | Py_ASNATIVEBYTES_UNSIGNED_BUFFER); |
11411 | 0 | if (_bytes < 0) { |
11412 | 0 | goto exit; |
11413 | 0 | } |
11414 | 0 | if ((size_t)_bytes > sizeof(unsigned int)) { |
11415 | 0 | if (PyErr_WarnEx(PyExc_DeprecationWarning, |
11416 | 0 | "integer value out of range", 1) < 0) |
11417 | 0 | { |
11418 | 0 | goto exit; |
11419 | 0 | } |
11420 | 0 | } |
11421 | 0 | } |
11422 | 0 | skip_optional_pos: |
11423 | 0 | return_value = os_memfd_create_impl(module, name, flags); |
11424 | |
|
11425 | 0 | exit: |
11426 | | /* Cleanup for name */ |
11427 | 0 | Py_XDECREF(name); |
11428 | |
|
11429 | 0 | return return_value; |
11430 | 0 | } |
11431 | | |
11432 | | #endif /* defined(HAVE_MEMFD_CREATE) */ |
11433 | | |
11434 | | #if (defined(HAVE_EVENTFD) && defined(EFD_CLOEXEC)) |
11435 | | |
11436 | | PyDoc_STRVAR(os_eventfd__doc__, |
11437 | | "eventfd($module, /, initval, flags=EFD_CLOEXEC)\n" |
11438 | | "--\n" |
11439 | | "\n" |
11440 | | "Creates and returns an event notification file descriptor."); |
11441 | | |
11442 | | #define OS_EVENTFD_METHODDEF \ |
11443 | | {"eventfd", _PyCFunction_CAST(os_eventfd), METH_FASTCALL|METH_KEYWORDS, os_eventfd__doc__}, |
11444 | | |
11445 | | static PyObject * |
11446 | | os_eventfd_impl(PyObject *module, unsigned int initval, int flags); |
11447 | | |
11448 | | static PyObject * |
11449 | | os_eventfd(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
11450 | 0 | { |
11451 | 0 | PyObject *return_value = NULL; |
11452 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
11453 | |
|
11454 | 0 | #define NUM_KEYWORDS 2 |
11455 | 0 | static struct { |
11456 | 0 | PyGC_Head _this_is_not_used; |
11457 | 0 | PyObject_VAR_HEAD |
11458 | 0 | Py_hash_t ob_hash; |
11459 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
11460 | 0 | } _kwtuple = { |
11461 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
11462 | 0 | .ob_hash = -1, |
11463 | 0 | .ob_item = { &_Py_ID(initval), &_Py_ID(flags), }, |
11464 | 0 | }; |
11465 | 0 | #undef NUM_KEYWORDS |
11466 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
11467 | |
|
11468 | | #else // !Py_BUILD_CORE |
11469 | | # define KWTUPLE NULL |
11470 | | #endif // !Py_BUILD_CORE |
11471 | |
|
11472 | 0 | static const char * const _keywords[] = {"initval", "flags", NULL}; |
11473 | 0 | static _PyArg_Parser _parser = { |
11474 | 0 | .keywords = _keywords, |
11475 | 0 | .fname = "eventfd", |
11476 | 0 | .kwtuple = KWTUPLE, |
11477 | 0 | }; |
11478 | 0 | #undef KWTUPLE |
11479 | 0 | PyObject *argsbuf[2]; |
11480 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
11481 | 0 | unsigned int initval; |
11482 | 0 | int flags = EFD_CLOEXEC; |
11483 | |
|
11484 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
11485 | 0 | /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
11486 | 0 | if (!args) { |
11487 | 0 | goto exit; |
11488 | 0 | } |
11489 | 0 | if (!_PyLong_UnsignedInt_Converter(args[0], &initval)) { |
11490 | 0 | goto exit; |
11491 | 0 | } |
11492 | 0 | if (!noptargs) { |
11493 | 0 | goto skip_optional_pos; |
11494 | 0 | } |
11495 | 0 | flags = PyLong_AsInt(args[1]); |
11496 | 0 | if (flags == -1 && PyErr_Occurred()) { |
11497 | 0 | goto exit; |
11498 | 0 | } |
11499 | 0 | skip_optional_pos: |
11500 | 0 | return_value = os_eventfd_impl(module, initval, flags); |
11501 | |
|
11502 | 0 | exit: |
11503 | 0 | return return_value; |
11504 | 0 | } |
11505 | | |
11506 | | #endif /* (defined(HAVE_EVENTFD) && defined(EFD_CLOEXEC)) */ |
11507 | | |
11508 | | #if (defined(HAVE_EVENTFD) && defined(EFD_CLOEXEC)) |
11509 | | |
11510 | | PyDoc_STRVAR(os_eventfd_read__doc__, |
11511 | | "eventfd_read($module, /, fd)\n" |
11512 | | "--\n" |
11513 | | "\n" |
11514 | | "Read eventfd value"); |
11515 | | |
11516 | | #define OS_EVENTFD_READ_METHODDEF \ |
11517 | | {"eventfd_read", _PyCFunction_CAST(os_eventfd_read), METH_FASTCALL|METH_KEYWORDS, os_eventfd_read__doc__}, |
11518 | | |
11519 | | static PyObject * |
11520 | | os_eventfd_read_impl(PyObject *module, int fd); |
11521 | | |
11522 | | static PyObject * |
11523 | | os_eventfd_read(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
11524 | 0 | { |
11525 | 0 | PyObject *return_value = NULL; |
11526 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
11527 | |
|
11528 | 0 | #define NUM_KEYWORDS 1 |
11529 | 0 | static struct { |
11530 | 0 | PyGC_Head _this_is_not_used; |
11531 | 0 | PyObject_VAR_HEAD |
11532 | 0 | Py_hash_t ob_hash; |
11533 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
11534 | 0 | } _kwtuple = { |
11535 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
11536 | 0 | .ob_hash = -1, |
11537 | 0 | .ob_item = { &_Py_ID(fd), }, |
11538 | 0 | }; |
11539 | 0 | #undef NUM_KEYWORDS |
11540 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
11541 | |
|
11542 | | #else // !Py_BUILD_CORE |
11543 | | # define KWTUPLE NULL |
11544 | | #endif // !Py_BUILD_CORE |
11545 | |
|
11546 | 0 | static const char * const _keywords[] = {"fd", NULL}; |
11547 | 0 | static _PyArg_Parser _parser = { |
11548 | 0 | .keywords = _keywords, |
11549 | 0 | .fname = "eventfd_read", |
11550 | 0 | .kwtuple = KWTUPLE, |
11551 | 0 | }; |
11552 | 0 | #undef KWTUPLE |
11553 | 0 | PyObject *argsbuf[1]; |
11554 | 0 | int fd; |
11555 | |
|
11556 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
11557 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
11558 | 0 | if (!args) { |
11559 | 0 | goto exit; |
11560 | 0 | } |
11561 | 0 | fd = PyObject_AsFileDescriptor(args[0]); |
11562 | 0 | if (fd < 0) { |
11563 | 0 | goto exit; |
11564 | 0 | } |
11565 | 0 | return_value = os_eventfd_read_impl(module, fd); |
11566 | |
|
11567 | 0 | exit: |
11568 | 0 | return return_value; |
11569 | 0 | } |
11570 | | |
11571 | | #endif /* (defined(HAVE_EVENTFD) && defined(EFD_CLOEXEC)) */ |
11572 | | |
11573 | | #if (defined(HAVE_EVENTFD) && defined(EFD_CLOEXEC)) |
11574 | | |
11575 | | PyDoc_STRVAR(os_eventfd_write__doc__, |
11576 | | "eventfd_write($module, /, fd, value)\n" |
11577 | | "--\n" |
11578 | | "\n" |
11579 | | "Write eventfd value."); |
11580 | | |
11581 | | #define OS_EVENTFD_WRITE_METHODDEF \ |
11582 | | {"eventfd_write", _PyCFunction_CAST(os_eventfd_write), METH_FASTCALL|METH_KEYWORDS, os_eventfd_write__doc__}, |
11583 | | |
11584 | | static PyObject * |
11585 | | os_eventfd_write_impl(PyObject *module, int fd, unsigned long long value); |
11586 | | |
11587 | | static PyObject * |
11588 | | os_eventfd_write(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
11589 | 0 | { |
11590 | 0 | PyObject *return_value = NULL; |
11591 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
11592 | |
|
11593 | 0 | #define NUM_KEYWORDS 2 |
11594 | 0 | static struct { |
11595 | 0 | PyGC_Head _this_is_not_used; |
11596 | 0 | PyObject_VAR_HEAD |
11597 | 0 | Py_hash_t ob_hash; |
11598 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
11599 | 0 | } _kwtuple = { |
11600 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
11601 | 0 | .ob_hash = -1, |
11602 | 0 | .ob_item = { &_Py_ID(fd), &_Py_ID(value), }, |
11603 | 0 | }; |
11604 | 0 | #undef NUM_KEYWORDS |
11605 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
11606 | |
|
11607 | | #else // !Py_BUILD_CORE |
11608 | | # define KWTUPLE NULL |
11609 | | #endif // !Py_BUILD_CORE |
11610 | |
|
11611 | 0 | static const char * const _keywords[] = {"fd", "value", NULL}; |
11612 | 0 | static _PyArg_Parser _parser = { |
11613 | 0 | .keywords = _keywords, |
11614 | 0 | .fname = "eventfd_write", |
11615 | 0 | .kwtuple = KWTUPLE, |
11616 | 0 | }; |
11617 | 0 | #undef KWTUPLE |
11618 | 0 | PyObject *argsbuf[2]; |
11619 | 0 | int fd; |
11620 | 0 | unsigned long long value; |
11621 | |
|
11622 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
11623 | 0 | /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
11624 | 0 | if (!args) { |
11625 | 0 | goto exit; |
11626 | 0 | } |
11627 | 0 | fd = PyObject_AsFileDescriptor(args[0]); |
11628 | 0 | if (fd < 0) { |
11629 | 0 | goto exit; |
11630 | 0 | } |
11631 | 0 | if (!_PyLong_UnsignedLongLong_Converter(args[1], &value)) { |
11632 | 0 | goto exit; |
11633 | 0 | } |
11634 | 0 | return_value = os_eventfd_write_impl(module, fd, value); |
11635 | |
|
11636 | 0 | exit: |
11637 | 0 | return return_value; |
11638 | 0 | } |
11639 | | |
11640 | | #endif /* (defined(HAVE_EVENTFD) && defined(EFD_CLOEXEC)) */ |
11641 | | |
11642 | | #if (defined(TERMSIZE_USE_CONIO) || defined(TERMSIZE_USE_IOCTL)) |
11643 | | |
11644 | | PyDoc_STRVAR(os_get_terminal_size__doc__, |
11645 | | "get_terminal_size($module, fd=<unrepresentable>, /)\n" |
11646 | | "--\n" |
11647 | | "\n" |
11648 | | "Return the size of the terminal window as (columns, lines).\n" |
11649 | | "\n" |
11650 | | "The optional argument fd (default standard output) specifies\n" |
11651 | | "which file descriptor should be queried.\n" |
11652 | | "\n" |
11653 | | "If the file descriptor is not connected to a terminal, an OSError\n" |
11654 | | "is thrown.\n" |
11655 | | "\n" |
11656 | | "This function will only be defined if an implementation is\n" |
11657 | | "available for this system.\n" |
11658 | | "\n" |
11659 | | "shutil.get_terminal_size is the high-level function which should\n" |
11660 | | "normally be used, os.get_terminal_size is the low-level implementation."); |
11661 | | |
11662 | | #define OS_GET_TERMINAL_SIZE_METHODDEF \ |
11663 | | {"get_terminal_size", _PyCFunction_CAST(os_get_terminal_size), METH_FASTCALL, os_get_terminal_size__doc__}, |
11664 | | |
11665 | | static PyObject * |
11666 | | os_get_terminal_size_impl(PyObject *module, int fd); |
11667 | | |
11668 | | static PyObject * |
11669 | | os_get_terminal_size(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
11670 | 0 | { |
11671 | 0 | PyObject *return_value = NULL; |
11672 | 0 | int fd = fileno(stdout); |
11673 | |
|
11674 | 0 | if (!_PyArg_CheckPositional("get_terminal_size", nargs, 0, 1)) { |
11675 | 0 | goto exit; |
11676 | 0 | } |
11677 | 0 | if (nargs < 1) { |
11678 | 0 | goto skip_optional; |
11679 | 0 | } |
11680 | 0 | fd = PyLong_AsInt(args[0]); |
11681 | 0 | if (fd == -1 && PyErr_Occurred()) { |
11682 | 0 | goto exit; |
11683 | 0 | } |
11684 | 0 | skip_optional: |
11685 | 0 | return_value = os_get_terminal_size_impl(module, fd); |
11686 | |
|
11687 | 0 | exit: |
11688 | 0 | return return_value; |
11689 | 0 | } |
11690 | | |
11691 | | #endif /* (defined(TERMSIZE_USE_CONIO) || defined(TERMSIZE_USE_IOCTL)) */ |
11692 | | |
11693 | | PyDoc_STRVAR(os_cpu_count__doc__, |
11694 | | "cpu_count($module, /)\n" |
11695 | | "--\n" |
11696 | | "\n" |
11697 | | "Return the number of logical CPUs in the system.\n" |
11698 | | "\n" |
11699 | | "Return None if indeterminable."); |
11700 | | |
11701 | | #define OS_CPU_COUNT_METHODDEF \ |
11702 | | {"cpu_count", (PyCFunction)os_cpu_count, METH_NOARGS, os_cpu_count__doc__}, |
11703 | | |
11704 | | static PyObject * |
11705 | | os_cpu_count_impl(PyObject *module); |
11706 | | |
11707 | | static PyObject * |
11708 | | os_cpu_count(PyObject *module, PyObject *Py_UNUSED(ignored)) |
11709 | 0 | { |
11710 | 0 | return os_cpu_count_impl(module); |
11711 | 0 | } |
11712 | | |
11713 | | PyDoc_STRVAR(os_get_inheritable__doc__, |
11714 | | "get_inheritable($module, fd, /)\n" |
11715 | | "--\n" |
11716 | | "\n" |
11717 | | "Get the close-on-exe flag of the specified file descriptor."); |
11718 | | |
11719 | | #define OS_GET_INHERITABLE_METHODDEF \ |
11720 | | {"get_inheritable", (PyCFunction)os_get_inheritable, METH_O, os_get_inheritable__doc__}, |
11721 | | |
11722 | | static int |
11723 | | os_get_inheritable_impl(PyObject *module, int fd); |
11724 | | |
11725 | | static PyObject * |
11726 | | os_get_inheritable(PyObject *module, PyObject *arg) |
11727 | 0 | { |
11728 | 0 | PyObject *return_value = NULL; |
11729 | 0 | int fd; |
11730 | 0 | int _return_value; |
11731 | |
|
11732 | 0 | fd = PyLong_AsInt(arg); |
11733 | 0 | if (fd == -1 && PyErr_Occurred()) { |
11734 | 0 | goto exit; |
11735 | 0 | } |
11736 | 0 | _return_value = os_get_inheritable_impl(module, fd); |
11737 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
11738 | 0 | goto exit; |
11739 | 0 | } |
11740 | 0 | return_value = PyBool_FromLong((long)_return_value); |
11741 | |
|
11742 | 0 | exit: |
11743 | 0 | return return_value; |
11744 | 0 | } |
11745 | | |
11746 | | PyDoc_STRVAR(os_set_inheritable__doc__, |
11747 | | "set_inheritable($module, fd, inheritable, /)\n" |
11748 | | "--\n" |
11749 | | "\n" |
11750 | | "Set the inheritable flag of the specified file descriptor."); |
11751 | | |
11752 | | #define OS_SET_INHERITABLE_METHODDEF \ |
11753 | | {"set_inheritable", _PyCFunction_CAST(os_set_inheritable), METH_FASTCALL, os_set_inheritable__doc__}, |
11754 | | |
11755 | | static PyObject * |
11756 | | os_set_inheritable_impl(PyObject *module, int fd, int inheritable); |
11757 | | |
11758 | | static PyObject * |
11759 | | os_set_inheritable(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
11760 | 0 | { |
11761 | 0 | PyObject *return_value = NULL; |
11762 | 0 | int fd; |
11763 | 0 | int inheritable; |
11764 | |
|
11765 | 0 | if (!_PyArg_CheckPositional("set_inheritable", nargs, 2, 2)) { |
11766 | 0 | goto exit; |
11767 | 0 | } |
11768 | 0 | fd = PyLong_AsInt(args[0]); |
11769 | 0 | if (fd == -1 && PyErr_Occurred()) { |
11770 | 0 | goto exit; |
11771 | 0 | } |
11772 | 0 | inheritable = PyLong_AsInt(args[1]); |
11773 | 0 | if (inheritable == -1 && PyErr_Occurred()) { |
11774 | 0 | goto exit; |
11775 | 0 | } |
11776 | 0 | return_value = os_set_inheritable_impl(module, fd, inheritable); |
11777 | |
|
11778 | 0 | exit: |
11779 | 0 | return return_value; |
11780 | 0 | } |
11781 | | |
11782 | | #if defined(MS_WINDOWS) |
11783 | | |
11784 | | PyDoc_STRVAR(os_get_handle_inheritable__doc__, |
11785 | | "get_handle_inheritable($module, handle, /)\n" |
11786 | | "--\n" |
11787 | | "\n" |
11788 | | "Get the close-on-exe flag of the specified file descriptor."); |
11789 | | |
11790 | | #define OS_GET_HANDLE_INHERITABLE_METHODDEF \ |
11791 | | {"get_handle_inheritable", (PyCFunction)os_get_handle_inheritable, METH_O, os_get_handle_inheritable__doc__}, |
11792 | | |
11793 | | static int |
11794 | | os_get_handle_inheritable_impl(PyObject *module, intptr_t handle); |
11795 | | |
11796 | | static PyObject * |
11797 | | os_get_handle_inheritable(PyObject *module, PyObject *arg) |
11798 | | { |
11799 | | PyObject *return_value = NULL; |
11800 | | intptr_t handle; |
11801 | | int _return_value; |
11802 | | |
11803 | | handle = (intptr_t)PyLong_AsVoidPtr(arg); |
11804 | | if (!handle && PyErr_Occurred()) { |
11805 | | goto exit; |
11806 | | } |
11807 | | _return_value = os_get_handle_inheritable_impl(module, handle); |
11808 | | if ((_return_value == -1) && PyErr_Occurred()) { |
11809 | | goto exit; |
11810 | | } |
11811 | | return_value = PyBool_FromLong((long)_return_value); |
11812 | | |
11813 | | exit: |
11814 | | return return_value; |
11815 | | } |
11816 | | |
11817 | | #endif /* defined(MS_WINDOWS) */ |
11818 | | |
11819 | | #if defined(MS_WINDOWS) |
11820 | | |
11821 | | PyDoc_STRVAR(os_set_handle_inheritable__doc__, |
11822 | | "set_handle_inheritable($module, handle, inheritable, /)\n" |
11823 | | "--\n" |
11824 | | "\n" |
11825 | | "Set the inheritable flag of the specified handle."); |
11826 | | |
11827 | | #define OS_SET_HANDLE_INHERITABLE_METHODDEF \ |
11828 | | {"set_handle_inheritable", _PyCFunction_CAST(os_set_handle_inheritable), METH_FASTCALL, os_set_handle_inheritable__doc__}, |
11829 | | |
11830 | | static PyObject * |
11831 | | os_set_handle_inheritable_impl(PyObject *module, intptr_t handle, |
11832 | | int inheritable); |
11833 | | |
11834 | | static PyObject * |
11835 | | os_set_handle_inheritable(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
11836 | | { |
11837 | | PyObject *return_value = NULL; |
11838 | | intptr_t handle; |
11839 | | int inheritable; |
11840 | | |
11841 | | if (!_PyArg_CheckPositional("set_handle_inheritable", nargs, 2, 2)) { |
11842 | | goto exit; |
11843 | | } |
11844 | | handle = (intptr_t)PyLong_AsVoidPtr(args[0]); |
11845 | | if (!handle && PyErr_Occurred()) { |
11846 | | goto exit; |
11847 | | } |
11848 | | inheritable = PyObject_IsTrue(args[1]); |
11849 | | if (inheritable < 0) { |
11850 | | goto exit; |
11851 | | } |
11852 | | return_value = os_set_handle_inheritable_impl(module, handle, inheritable); |
11853 | | |
11854 | | exit: |
11855 | | return return_value; |
11856 | | } |
11857 | | |
11858 | | #endif /* defined(MS_WINDOWS) */ |
11859 | | |
11860 | | PyDoc_STRVAR(os_get_blocking__doc__, |
11861 | | "get_blocking($module, fd, /)\n" |
11862 | | "--\n" |
11863 | | "\n" |
11864 | | "Get the blocking mode of the file descriptor.\n" |
11865 | | "\n" |
11866 | | "Return False if the O_NONBLOCK flag is set, True if the flag is cleared."); |
11867 | | |
11868 | | #define OS_GET_BLOCKING_METHODDEF \ |
11869 | | {"get_blocking", (PyCFunction)os_get_blocking, METH_O, os_get_blocking__doc__}, |
11870 | | |
11871 | | static int |
11872 | | os_get_blocking_impl(PyObject *module, int fd); |
11873 | | |
11874 | | static PyObject * |
11875 | | os_get_blocking(PyObject *module, PyObject *arg) |
11876 | 0 | { |
11877 | 0 | PyObject *return_value = NULL; |
11878 | 0 | int fd; |
11879 | 0 | int _return_value; |
11880 | |
|
11881 | 0 | fd = PyLong_AsInt(arg); |
11882 | 0 | if (fd == -1 && PyErr_Occurred()) { |
11883 | 0 | goto exit; |
11884 | 0 | } |
11885 | 0 | _return_value = os_get_blocking_impl(module, fd); |
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_set_blocking__doc__, |
11896 | | "set_blocking($module, fd, blocking, /)\n" |
11897 | | "--\n" |
11898 | | "\n" |
11899 | | "Set the blocking mode of the specified file descriptor.\n" |
11900 | | "\n" |
11901 | | "Set the O_NONBLOCK flag if blocking is False,\n" |
11902 | | "clear the O_NONBLOCK flag otherwise."); |
11903 | | |
11904 | | #define OS_SET_BLOCKING_METHODDEF \ |
11905 | | {"set_blocking", _PyCFunction_CAST(os_set_blocking), METH_FASTCALL, os_set_blocking__doc__}, |
11906 | | |
11907 | | static PyObject * |
11908 | | os_set_blocking_impl(PyObject *module, int fd, int blocking); |
11909 | | |
11910 | | static PyObject * |
11911 | | os_set_blocking(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
11912 | 0 | { |
11913 | 0 | PyObject *return_value = NULL; |
11914 | 0 | int fd; |
11915 | 0 | int blocking; |
11916 | |
|
11917 | 0 | if (!_PyArg_CheckPositional("set_blocking", nargs, 2, 2)) { |
11918 | 0 | goto exit; |
11919 | 0 | } |
11920 | 0 | fd = PyLong_AsInt(args[0]); |
11921 | 0 | if (fd == -1 && PyErr_Occurred()) { |
11922 | 0 | goto exit; |
11923 | 0 | } |
11924 | 0 | blocking = PyObject_IsTrue(args[1]); |
11925 | 0 | if (blocking < 0) { |
11926 | 0 | goto exit; |
11927 | 0 | } |
11928 | 0 | return_value = os_set_blocking_impl(module, fd, blocking); |
11929 | |
|
11930 | 0 | exit: |
11931 | 0 | return return_value; |
11932 | 0 | } |
11933 | | |
11934 | | PyDoc_STRVAR(os_DirEntry_is_symlink__doc__, |
11935 | | "is_symlink($self, /)\n" |
11936 | | "--\n" |
11937 | | "\n" |
11938 | | "Return True if the entry is a symbolic link; cached per entry."); |
11939 | | |
11940 | | #define OS_DIRENTRY_IS_SYMLINK_METHODDEF \ |
11941 | | {"is_symlink", _PyCFunction_CAST(os_DirEntry_is_symlink), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, os_DirEntry_is_symlink__doc__}, |
11942 | | |
11943 | | static int |
11944 | | os_DirEntry_is_symlink_impl(DirEntry *self, PyTypeObject *defining_class); |
11945 | | |
11946 | | static PyObject * |
11947 | | os_DirEntry_is_symlink(PyObject *self, PyTypeObject *defining_class, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
11948 | 0 | { |
11949 | 0 | PyObject *return_value = NULL; |
11950 | 0 | int _return_value; |
11951 | |
|
11952 | 0 | if (nargs || (kwnames && PyTuple_GET_SIZE(kwnames))) { |
11953 | 0 | PyErr_SetString(PyExc_TypeError, "is_symlink() takes no arguments"); |
11954 | 0 | goto exit; |
11955 | 0 | } |
11956 | 0 | _return_value = os_DirEntry_is_symlink_impl((DirEntry *)self, defining_class); |
11957 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
11958 | 0 | goto exit; |
11959 | 0 | } |
11960 | 0 | return_value = PyBool_FromLong((long)_return_value); |
11961 | |
|
11962 | 0 | exit: |
11963 | 0 | return return_value; |
11964 | 0 | } |
11965 | | |
11966 | | PyDoc_STRVAR(os_DirEntry_is_junction__doc__, |
11967 | | "is_junction($self, /)\n" |
11968 | | "--\n" |
11969 | | "\n" |
11970 | | "Return True if the entry is a junction; cached per entry."); |
11971 | | |
11972 | | #define OS_DIRENTRY_IS_JUNCTION_METHODDEF \ |
11973 | | {"is_junction", (PyCFunction)os_DirEntry_is_junction, METH_NOARGS, os_DirEntry_is_junction__doc__}, |
11974 | | |
11975 | | static int |
11976 | | os_DirEntry_is_junction_impl(DirEntry *self); |
11977 | | |
11978 | | static PyObject * |
11979 | | os_DirEntry_is_junction(PyObject *self, PyObject *Py_UNUSED(ignored)) |
11980 | 0 | { |
11981 | 0 | PyObject *return_value = NULL; |
11982 | 0 | int _return_value; |
11983 | |
|
11984 | 0 | _return_value = os_DirEntry_is_junction_impl((DirEntry *)self); |
11985 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
11986 | 0 | goto exit; |
11987 | 0 | } |
11988 | 0 | return_value = PyBool_FromLong((long)_return_value); |
11989 | |
|
11990 | 0 | exit: |
11991 | 0 | return return_value; |
11992 | 0 | } |
11993 | | |
11994 | | PyDoc_STRVAR(os_DirEntry_stat__doc__, |
11995 | | "stat($self, /, *, follow_symlinks=True)\n" |
11996 | | "--\n" |
11997 | | "\n" |
11998 | | "Return stat_result object for the entry; cached per entry."); |
11999 | | |
12000 | | #define OS_DIRENTRY_STAT_METHODDEF \ |
12001 | | {"stat", _PyCFunction_CAST(os_DirEntry_stat), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, os_DirEntry_stat__doc__}, |
12002 | | |
12003 | | static PyObject * |
12004 | | os_DirEntry_stat_impl(DirEntry *self, PyTypeObject *defining_class, |
12005 | | int follow_symlinks); |
12006 | | |
12007 | | static PyObject * |
12008 | | os_DirEntry_stat(PyObject *self, PyTypeObject *defining_class, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
12009 | 0 | { |
12010 | 0 | PyObject *return_value = NULL; |
12011 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
12012 | |
|
12013 | 0 | #define NUM_KEYWORDS 1 |
12014 | 0 | static struct { |
12015 | 0 | PyGC_Head _this_is_not_used; |
12016 | 0 | PyObject_VAR_HEAD |
12017 | 0 | Py_hash_t ob_hash; |
12018 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
12019 | 0 | } _kwtuple = { |
12020 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
12021 | 0 | .ob_hash = -1, |
12022 | 0 | .ob_item = { &_Py_ID(follow_symlinks), }, |
12023 | 0 | }; |
12024 | 0 | #undef NUM_KEYWORDS |
12025 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
12026 | |
|
12027 | | #else // !Py_BUILD_CORE |
12028 | | # define KWTUPLE NULL |
12029 | | #endif // !Py_BUILD_CORE |
12030 | |
|
12031 | 0 | static const char * const _keywords[] = {"follow_symlinks", NULL}; |
12032 | 0 | static _PyArg_Parser _parser = { |
12033 | 0 | .keywords = _keywords, |
12034 | 0 | .fname = "stat", |
12035 | 0 | .kwtuple = KWTUPLE, |
12036 | 0 | }; |
12037 | 0 | #undef KWTUPLE |
12038 | 0 | PyObject *argsbuf[1]; |
12039 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; |
12040 | 0 | int follow_symlinks = 1; |
12041 | |
|
12042 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
12043 | 0 | /*minpos*/ 0, /*maxpos*/ 0, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
12044 | 0 | if (!args) { |
12045 | 0 | goto exit; |
12046 | 0 | } |
12047 | 0 | if (!noptargs) { |
12048 | 0 | goto skip_optional_kwonly; |
12049 | 0 | } |
12050 | 0 | follow_symlinks = PyObject_IsTrue(args[0]); |
12051 | 0 | if (follow_symlinks < 0) { |
12052 | 0 | goto exit; |
12053 | 0 | } |
12054 | 0 | skip_optional_kwonly: |
12055 | 0 | return_value = os_DirEntry_stat_impl((DirEntry *)self, defining_class, follow_symlinks); |
12056 | |
|
12057 | 0 | exit: |
12058 | 0 | return return_value; |
12059 | 0 | } |
12060 | | |
12061 | | PyDoc_STRVAR(os_DirEntry_is_dir__doc__, |
12062 | | "is_dir($self, /, *, follow_symlinks=True)\n" |
12063 | | "--\n" |
12064 | | "\n" |
12065 | | "Return True if the entry is a directory; cached per entry."); |
12066 | | |
12067 | | #define OS_DIRENTRY_IS_DIR_METHODDEF \ |
12068 | | {"is_dir", _PyCFunction_CAST(os_DirEntry_is_dir), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, os_DirEntry_is_dir__doc__}, |
12069 | | |
12070 | | static int |
12071 | | os_DirEntry_is_dir_impl(DirEntry *self, PyTypeObject *defining_class, |
12072 | | int follow_symlinks); |
12073 | | |
12074 | | static PyObject * |
12075 | | os_DirEntry_is_dir(PyObject *self, PyTypeObject *defining_class, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
12076 | 0 | { |
12077 | 0 | PyObject *return_value = NULL; |
12078 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
12079 | |
|
12080 | 0 | #define NUM_KEYWORDS 1 |
12081 | 0 | static struct { |
12082 | 0 | PyGC_Head _this_is_not_used; |
12083 | 0 | PyObject_VAR_HEAD |
12084 | 0 | Py_hash_t ob_hash; |
12085 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
12086 | 0 | } _kwtuple = { |
12087 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
12088 | 0 | .ob_hash = -1, |
12089 | 0 | .ob_item = { &_Py_ID(follow_symlinks), }, |
12090 | 0 | }; |
12091 | 0 | #undef NUM_KEYWORDS |
12092 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
12093 | |
|
12094 | | #else // !Py_BUILD_CORE |
12095 | | # define KWTUPLE NULL |
12096 | | #endif // !Py_BUILD_CORE |
12097 | |
|
12098 | 0 | static const char * const _keywords[] = {"follow_symlinks", NULL}; |
12099 | 0 | static _PyArg_Parser _parser = { |
12100 | 0 | .keywords = _keywords, |
12101 | 0 | .fname = "is_dir", |
12102 | 0 | .kwtuple = KWTUPLE, |
12103 | 0 | }; |
12104 | 0 | #undef KWTUPLE |
12105 | 0 | PyObject *argsbuf[1]; |
12106 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; |
12107 | 0 | int follow_symlinks = 1; |
12108 | 0 | int _return_value; |
12109 | |
|
12110 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
12111 | 0 | /*minpos*/ 0, /*maxpos*/ 0, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
12112 | 0 | if (!args) { |
12113 | 0 | goto exit; |
12114 | 0 | } |
12115 | 0 | if (!noptargs) { |
12116 | 0 | goto skip_optional_kwonly; |
12117 | 0 | } |
12118 | 0 | follow_symlinks = PyObject_IsTrue(args[0]); |
12119 | 0 | if (follow_symlinks < 0) { |
12120 | 0 | goto exit; |
12121 | 0 | } |
12122 | 0 | skip_optional_kwonly: |
12123 | 0 | _return_value = os_DirEntry_is_dir_impl((DirEntry *)self, defining_class, follow_symlinks); |
12124 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
12125 | 0 | goto exit; |
12126 | 0 | } |
12127 | 0 | return_value = PyBool_FromLong((long)_return_value); |
12128 | |
|
12129 | 0 | exit: |
12130 | 0 | return return_value; |
12131 | 0 | } |
12132 | | |
12133 | | PyDoc_STRVAR(os_DirEntry_is_file__doc__, |
12134 | | "is_file($self, /, *, follow_symlinks=True)\n" |
12135 | | "--\n" |
12136 | | "\n" |
12137 | | "Return True if the entry is a file; cached per entry."); |
12138 | | |
12139 | | #define OS_DIRENTRY_IS_FILE_METHODDEF \ |
12140 | | {"is_file", _PyCFunction_CAST(os_DirEntry_is_file), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, os_DirEntry_is_file__doc__}, |
12141 | | |
12142 | | static int |
12143 | | os_DirEntry_is_file_impl(DirEntry *self, PyTypeObject *defining_class, |
12144 | | int follow_symlinks); |
12145 | | |
12146 | | static PyObject * |
12147 | | os_DirEntry_is_file(PyObject *self, PyTypeObject *defining_class, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
12148 | 0 | { |
12149 | 0 | PyObject *return_value = NULL; |
12150 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
12151 | |
|
12152 | 0 | #define NUM_KEYWORDS 1 |
12153 | 0 | static struct { |
12154 | 0 | PyGC_Head _this_is_not_used; |
12155 | 0 | PyObject_VAR_HEAD |
12156 | 0 | Py_hash_t ob_hash; |
12157 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
12158 | 0 | } _kwtuple = { |
12159 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
12160 | 0 | .ob_hash = -1, |
12161 | 0 | .ob_item = { &_Py_ID(follow_symlinks), }, |
12162 | 0 | }; |
12163 | 0 | #undef NUM_KEYWORDS |
12164 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
12165 | |
|
12166 | | #else // !Py_BUILD_CORE |
12167 | | # define KWTUPLE NULL |
12168 | | #endif // !Py_BUILD_CORE |
12169 | |
|
12170 | 0 | static const char * const _keywords[] = {"follow_symlinks", NULL}; |
12171 | 0 | static _PyArg_Parser _parser = { |
12172 | 0 | .keywords = _keywords, |
12173 | 0 | .fname = "is_file", |
12174 | 0 | .kwtuple = KWTUPLE, |
12175 | 0 | }; |
12176 | 0 | #undef KWTUPLE |
12177 | 0 | PyObject *argsbuf[1]; |
12178 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; |
12179 | 0 | int follow_symlinks = 1; |
12180 | 0 | int _return_value; |
12181 | |
|
12182 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
12183 | 0 | /*minpos*/ 0, /*maxpos*/ 0, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
12184 | 0 | if (!args) { |
12185 | 0 | goto exit; |
12186 | 0 | } |
12187 | 0 | if (!noptargs) { |
12188 | 0 | goto skip_optional_kwonly; |
12189 | 0 | } |
12190 | 0 | follow_symlinks = PyObject_IsTrue(args[0]); |
12191 | 0 | if (follow_symlinks < 0) { |
12192 | 0 | goto exit; |
12193 | 0 | } |
12194 | 0 | skip_optional_kwonly: |
12195 | 0 | _return_value = os_DirEntry_is_file_impl((DirEntry *)self, defining_class, follow_symlinks); |
12196 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
12197 | 0 | goto exit; |
12198 | 0 | } |
12199 | 0 | return_value = PyBool_FromLong((long)_return_value); |
12200 | |
|
12201 | 0 | exit: |
12202 | 0 | return return_value; |
12203 | 0 | } |
12204 | | |
12205 | | PyDoc_STRVAR(os_DirEntry_inode__doc__, |
12206 | | "inode($self, /)\n" |
12207 | | "--\n" |
12208 | | "\n" |
12209 | | "Return inode of the entry; cached per entry."); |
12210 | | |
12211 | | #define OS_DIRENTRY_INODE_METHODDEF \ |
12212 | | {"inode", (PyCFunction)os_DirEntry_inode, METH_NOARGS, os_DirEntry_inode__doc__}, |
12213 | | |
12214 | | static PyObject * |
12215 | | os_DirEntry_inode_impl(DirEntry *self); |
12216 | | |
12217 | | static PyObject * |
12218 | | os_DirEntry_inode(PyObject *self, PyObject *Py_UNUSED(ignored)) |
12219 | 0 | { |
12220 | 0 | return os_DirEntry_inode_impl((DirEntry *)self); |
12221 | 0 | } |
12222 | | |
12223 | | PyDoc_STRVAR(os_DirEntry___fspath____doc__, |
12224 | | "__fspath__($self, /)\n" |
12225 | | "--\n" |
12226 | | "\n" |
12227 | | "Returns the path for the entry."); |
12228 | | |
12229 | | #define OS_DIRENTRY___FSPATH___METHODDEF \ |
12230 | | {"__fspath__", (PyCFunction)os_DirEntry___fspath__, METH_NOARGS, os_DirEntry___fspath____doc__}, |
12231 | | |
12232 | | static PyObject * |
12233 | | os_DirEntry___fspath___impl(DirEntry *self); |
12234 | | |
12235 | | static PyObject * |
12236 | | os_DirEntry___fspath__(PyObject *self, PyObject *Py_UNUSED(ignored)) |
12237 | 0 | { |
12238 | 0 | return os_DirEntry___fspath___impl((DirEntry *)self); |
12239 | 0 | } |
12240 | | |
12241 | | PyDoc_STRVAR(os_scandir__doc__, |
12242 | | "scandir($module, /, path=None)\n" |
12243 | | "--\n" |
12244 | | "\n" |
12245 | | "Return an iterator of DirEntry objects for given path.\n" |
12246 | | "\n" |
12247 | | "path can be specified as either str, bytes, or a path-like object. If path\n" |
12248 | | "is bytes, the names of yielded DirEntry objects will also be bytes; in\n" |
12249 | | "all other circumstances they will be str.\n" |
12250 | | "\n" |
12251 | | "If path is None, uses the path=\'.\'."); |
12252 | | |
12253 | | #define OS_SCANDIR_METHODDEF \ |
12254 | | {"scandir", _PyCFunction_CAST(os_scandir), METH_FASTCALL|METH_KEYWORDS, os_scandir__doc__}, |
12255 | | |
12256 | | static PyObject * |
12257 | | os_scandir_impl(PyObject *module, path_t *path); |
12258 | | |
12259 | | static PyObject * |
12260 | | os_scandir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
12261 | 0 | { |
12262 | 0 | PyObject *return_value = NULL; |
12263 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
12264 | |
|
12265 | 0 | #define NUM_KEYWORDS 1 |
12266 | 0 | static struct { |
12267 | 0 | PyGC_Head _this_is_not_used; |
12268 | 0 | PyObject_VAR_HEAD |
12269 | 0 | Py_hash_t ob_hash; |
12270 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
12271 | 0 | } _kwtuple = { |
12272 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
12273 | 0 | .ob_hash = -1, |
12274 | 0 | .ob_item = { &_Py_ID(path), }, |
12275 | 0 | }; |
12276 | 0 | #undef NUM_KEYWORDS |
12277 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
12278 | |
|
12279 | | #else // !Py_BUILD_CORE |
12280 | | # define KWTUPLE NULL |
12281 | | #endif // !Py_BUILD_CORE |
12282 | |
|
12283 | 0 | static const char * const _keywords[] = {"path", NULL}; |
12284 | 0 | static _PyArg_Parser _parser = { |
12285 | 0 | .keywords = _keywords, |
12286 | 0 | .fname = "scandir", |
12287 | 0 | .kwtuple = KWTUPLE, |
12288 | 0 | }; |
12289 | 0 | #undef KWTUPLE |
12290 | 0 | PyObject *argsbuf[1]; |
12291 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; |
12292 | 0 | path_t path = PATH_T_INITIALIZE_P("scandir", "path", 1, 0, 0, PATH_HAVE_FDOPENDIR); |
12293 | |
|
12294 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
12295 | 0 | /*minpos*/ 0, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
12296 | 0 | if (!args) { |
12297 | 0 | goto exit; |
12298 | 0 | } |
12299 | 0 | if (!noptargs) { |
12300 | 0 | goto skip_optional_pos; |
12301 | 0 | } |
12302 | 0 | if (!path_converter(args[0], &path)) { |
12303 | 0 | goto exit; |
12304 | 0 | } |
12305 | 0 | skip_optional_pos: |
12306 | 0 | return_value = os_scandir_impl(module, &path); |
12307 | |
|
12308 | 0 | exit: |
12309 | | /* Cleanup for path */ |
12310 | 0 | path_cleanup(&path); |
12311 | |
|
12312 | 0 | return return_value; |
12313 | 0 | } |
12314 | | |
12315 | | PyDoc_STRVAR(os_fspath__doc__, |
12316 | | "fspath($module, /, path)\n" |
12317 | | "--\n" |
12318 | | "\n" |
12319 | | "Return the file system path representation of the object.\n" |
12320 | | "\n" |
12321 | | "If the object is str or bytes, then allow it to pass through as-is. If the\n" |
12322 | | "object defines __fspath__(), then return the result of that method. All other\n" |
12323 | | "types raise a TypeError."); |
12324 | | |
12325 | | #define OS_FSPATH_METHODDEF \ |
12326 | | {"fspath", _PyCFunction_CAST(os_fspath), METH_FASTCALL|METH_KEYWORDS, os_fspath__doc__}, |
12327 | | |
12328 | | static PyObject * |
12329 | | os_fspath_impl(PyObject *module, PyObject *path); |
12330 | | |
12331 | | static PyObject * |
12332 | | os_fspath(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
12333 | 2.89k | { |
12334 | 2.89k | PyObject *return_value = NULL; |
12335 | 2.89k | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
12336 | | |
12337 | 2.89k | #define NUM_KEYWORDS 1 |
12338 | 2.89k | static struct { |
12339 | 2.89k | PyGC_Head _this_is_not_used; |
12340 | 2.89k | PyObject_VAR_HEAD |
12341 | 2.89k | Py_hash_t ob_hash; |
12342 | 2.89k | PyObject *ob_item[NUM_KEYWORDS]; |
12343 | 2.89k | } _kwtuple = { |
12344 | 2.89k | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
12345 | 2.89k | .ob_hash = -1, |
12346 | 2.89k | .ob_item = { &_Py_ID(path), }, |
12347 | 2.89k | }; |
12348 | 2.89k | #undef NUM_KEYWORDS |
12349 | 2.89k | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
12350 | | |
12351 | | #else // !Py_BUILD_CORE |
12352 | | # define KWTUPLE NULL |
12353 | | #endif // !Py_BUILD_CORE |
12354 | | |
12355 | 2.89k | static const char * const _keywords[] = {"path", NULL}; |
12356 | 2.89k | static _PyArg_Parser _parser = { |
12357 | 2.89k | .keywords = _keywords, |
12358 | 2.89k | .fname = "fspath", |
12359 | 2.89k | .kwtuple = KWTUPLE, |
12360 | 2.89k | }; |
12361 | 2.89k | #undef KWTUPLE |
12362 | 2.89k | PyObject *argsbuf[1]; |
12363 | 2.89k | PyObject *path; |
12364 | | |
12365 | 2.89k | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
12366 | 2.89k | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
12367 | 2.89k | if (!args) { |
12368 | 0 | goto exit; |
12369 | 0 | } |
12370 | 2.89k | path = args[0]; |
12371 | 2.89k | return_value = os_fspath_impl(module, path); |
12372 | | |
12373 | 2.89k | exit: |
12374 | 2.89k | return return_value; |
12375 | 2.89k | } |
12376 | | |
12377 | | #if defined(HAVE_GETRANDOM_SYSCALL) |
12378 | | |
12379 | | PyDoc_STRVAR(os_getrandom__doc__, |
12380 | | "getrandom($module, /, size, flags=0)\n" |
12381 | | "--\n" |
12382 | | "\n" |
12383 | | "Obtain a series of random bytes."); |
12384 | | |
12385 | | #define OS_GETRANDOM_METHODDEF \ |
12386 | | {"getrandom", _PyCFunction_CAST(os_getrandom), METH_FASTCALL|METH_KEYWORDS, os_getrandom__doc__}, |
12387 | | |
12388 | | static PyObject * |
12389 | | os_getrandom_impl(PyObject *module, Py_ssize_t size, int flags); |
12390 | | |
12391 | | static PyObject * |
12392 | | os_getrandom(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
12393 | 0 | { |
12394 | 0 | PyObject *return_value = NULL; |
12395 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
12396 | |
|
12397 | 0 | #define NUM_KEYWORDS 2 |
12398 | 0 | static struct { |
12399 | 0 | PyGC_Head _this_is_not_used; |
12400 | 0 | PyObject_VAR_HEAD |
12401 | 0 | Py_hash_t ob_hash; |
12402 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
12403 | 0 | } _kwtuple = { |
12404 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
12405 | 0 | .ob_hash = -1, |
12406 | 0 | .ob_item = { &_Py_ID(size), &_Py_ID(flags), }, |
12407 | 0 | }; |
12408 | 0 | #undef NUM_KEYWORDS |
12409 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
12410 | |
|
12411 | | #else // !Py_BUILD_CORE |
12412 | | # define KWTUPLE NULL |
12413 | | #endif // !Py_BUILD_CORE |
12414 | |
|
12415 | 0 | static const char * const _keywords[] = {"size", "flags", NULL}; |
12416 | 0 | static _PyArg_Parser _parser = { |
12417 | 0 | .keywords = _keywords, |
12418 | 0 | .fname = "getrandom", |
12419 | 0 | .kwtuple = KWTUPLE, |
12420 | 0 | }; |
12421 | 0 | #undef KWTUPLE |
12422 | 0 | PyObject *argsbuf[2]; |
12423 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
12424 | 0 | Py_ssize_t size; |
12425 | 0 | int flags = 0; |
12426 | |
|
12427 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
12428 | 0 | /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
12429 | 0 | if (!args) { |
12430 | 0 | goto exit; |
12431 | 0 | } |
12432 | 0 | { |
12433 | 0 | Py_ssize_t ival = -1; |
12434 | 0 | PyObject *iobj = _PyNumber_Index(args[0]); |
12435 | 0 | if (iobj != NULL) { |
12436 | 0 | ival = PyLong_AsSsize_t(iobj); |
12437 | 0 | Py_DECREF(iobj); |
12438 | 0 | } |
12439 | 0 | if (ival == -1 && PyErr_Occurred()) { |
12440 | 0 | goto exit; |
12441 | 0 | } |
12442 | 0 | size = ival; |
12443 | 0 | } |
12444 | 0 | if (!noptargs) { |
12445 | 0 | goto skip_optional_pos; |
12446 | 0 | } |
12447 | 0 | flags = PyLong_AsInt(args[1]); |
12448 | 0 | if (flags == -1 && PyErr_Occurred()) { |
12449 | 0 | goto exit; |
12450 | 0 | } |
12451 | 0 | skip_optional_pos: |
12452 | 0 | return_value = os_getrandom_impl(module, size, flags); |
12453 | |
|
12454 | 0 | exit: |
12455 | 0 | return return_value; |
12456 | 0 | } |
12457 | | |
12458 | | #endif /* defined(HAVE_GETRANDOM_SYSCALL) */ |
12459 | | |
12460 | | #if (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM)) |
12461 | | |
12462 | | PyDoc_STRVAR(os__add_dll_directory__doc__, |
12463 | | "_add_dll_directory($module, /, path)\n" |
12464 | | "--\n" |
12465 | | "\n" |
12466 | | "Add a path to the DLL search path.\n" |
12467 | | "\n" |
12468 | | "This search path is used when resolving dependencies for imported\n" |
12469 | | "extension modules (the module itself is resolved through sys.path),\n" |
12470 | | "and also by ctypes.\n" |
12471 | | "\n" |
12472 | | "Returns an opaque value that may be passed to os.remove_dll_directory\n" |
12473 | | "to remove this directory from the search path."); |
12474 | | |
12475 | | #define OS__ADD_DLL_DIRECTORY_METHODDEF \ |
12476 | | {"_add_dll_directory", _PyCFunction_CAST(os__add_dll_directory), METH_FASTCALL|METH_KEYWORDS, os__add_dll_directory__doc__}, |
12477 | | |
12478 | | static PyObject * |
12479 | | os__add_dll_directory_impl(PyObject *module, path_t *path); |
12480 | | |
12481 | | static PyObject * |
12482 | | os__add_dll_directory(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
12483 | | { |
12484 | | PyObject *return_value = NULL; |
12485 | | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
12486 | | |
12487 | | #define NUM_KEYWORDS 1 |
12488 | | static struct { |
12489 | | PyGC_Head _this_is_not_used; |
12490 | | PyObject_VAR_HEAD |
12491 | | Py_hash_t ob_hash; |
12492 | | PyObject *ob_item[NUM_KEYWORDS]; |
12493 | | } _kwtuple = { |
12494 | | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
12495 | | .ob_hash = -1, |
12496 | | .ob_item = { &_Py_ID(path), }, |
12497 | | }; |
12498 | | #undef NUM_KEYWORDS |
12499 | | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
12500 | | |
12501 | | #else // !Py_BUILD_CORE |
12502 | | # define KWTUPLE NULL |
12503 | | #endif // !Py_BUILD_CORE |
12504 | | |
12505 | | static const char * const _keywords[] = {"path", NULL}; |
12506 | | static _PyArg_Parser _parser = { |
12507 | | .keywords = _keywords, |
12508 | | .fname = "_add_dll_directory", |
12509 | | .kwtuple = KWTUPLE, |
12510 | | }; |
12511 | | #undef KWTUPLE |
12512 | | PyObject *argsbuf[1]; |
12513 | | path_t path = PATH_T_INITIALIZE_P("_add_dll_directory", "path", 0, 0, 0, 0); |
12514 | | |
12515 | | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
12516 | | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
12517 | | if (!args) { |
12518 | | goto exit; |
12519 | | } |
12520 | | if (!path_converter(args[0], &path)) { |
12521 | | goto exit; |
12522 | | } |
12523 | | return_value = os__add_dll_directory_impl(module, &path); |
12524 | | |
12525 | | exit: |
12526 | | /* Cleanup for path */ |
12527 | | path_cleanup(&path); |
12528 | | |
12529 | | return return_value; |
12530 | | } |
12531 | | |
12532 | | #endif /* (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM)) */ |
12533 | | |
12534 | | #if (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM)) |
12535 | | |
12536 | | PyDoc_STRVAR(os__remove_dll_directory__doc__, |
12537 | | "_remove_dll_directory($module, /, cookie)\n" |
12538 | | "--\n" |
12539 | | "\n" |
12540 | | "Removes a path from the DLL search path.\n" |
12541 | | "\n" |
12542 | | "The parameter is an opaque value that was returned from\n" |
12543 | | "os.add_dll_directory. You can only remove directories that you added\n" |
12544 | | "yourself."); |
12545 | | |
12546 | | #define OS__REMOVE_DLL_DIRECTORY_METHODDEF \ |
12547 | | {"_remove_dll_directory", _PyCFunction_CAST(os__remove_dll_directory), METH_FASTCALL|METH_KEYWORDS, os__remove_dll_directory__doc__}, |
12548 | | |
12549 | | static PyObject * |
12550 | | os__remove_dll_directory_impl(PyObject *module, PyObject *cookie); |
12551 | | |
12552 | | static PyObject * |
12553 | | os__remove_dll_directory(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
12554 | | { |
12555 | | PyObject *return_value = NULL; |
12556 | | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
12557 | | |
12558 | | #define NUM_KEYWORDS 1 |
12559 | | static struct { |
12560 | | PyGC_Head _this_is_not_used; |
12561 | | PyObject_VAR_HEAD |
12562 | | Py_hash_t ob_hash; |
12563 | | PyObject *ob_item[NUM_KEYWORDS]; |
12564 | | } _kwtuple = { |
12565 | | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
12566 | | .ob_hash = -1, |
12567 | | .ob_item = { &_Py_ID(cookie), }, |
12568 | | }; |
12569 | | #undef NUM_KEYWORDS |
12570 | | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
12571 | | |
12572 | | #else // !Py_BUILD_CORE |
12573 | | # define KWTUPLE NULL |
12574 | | #endif // !Py_BUILD_CORE |
12575 | | |
12576 | | static const char * const _keywords[] = {"cookie", NULL}; |
12577 | | static _PyArg_Parser _parser = { |
12578 | | .keywords = _keywords, |
12579 | | .fname = "_remove_dll_directory", |
12580 | | .kwtuple = KWTUPLE, |
12581 | | }; |
12582 | | #undef KWTUPLE |
12583 | | PyObject *argsbuf[1]; |
12584 | | PyObject *cookie; |
12585 | | |
12586 | | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
12587 | | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
12588 | | if (!args) { |
12589 | | goto exit; |
12590 | | } |
12591 | | cookie = args[0]; |
12592 | | return_value = os__remove_dll_directory_impl(module, cookie); |
12593 | | |
12594 | | exit: |
12595 | | return return_value; |
12596 | | } |
12597 | | |
12598 | | #endif /* (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM)) */ |
12599 | | |
12600 | | #if (defined(WIFEXITED) || defined(MS_WINDOWS)) |
12601 | | |
12602 | | PyDoc_STRVAR(os_waitstatus_to_exitcode__doc__, |
12603 | | "waitstatus_to_exitcode($module, /, status)\n" |
12604 | | "--\n" |
12605 | | "\n" |
12606 | | "Convert a wait status to an exit code.\n" |
12607 | | "\n" |
12608 | | "On Unix:\n" |
12609 | | "\n" |
12610 | | "* If WIFEXITED(status) is true, return WEXITSTATUS(status).\n" |
12611 | | "* If WIFSIGNALED(status) is true, return -WTERMSIG(status).\n" |
12612 | | "* Otherwise, raise a ValueError.\n" |
12613 | | "\n" |
12614 | | "On Windows, return status shifted right by 8 bits.\n" |
12615 | | "\n" |
12616 | | "On Unix, if the process is being traced or if waitpid() was called with\n" |
12617 | | "WUNTRACED option, the caller must first check if WIFSTOPPED(status) is true.\n" |
12618 | | "This function must not be called if WIFSTOPPED(status) is true."); |
12619 | | |
12620 | | #define OS_WAITSTATUS_TO_EXITCODE_METHODDEF \ |
12621 | | {"waitstatus_to_exitcode", _PyCFunction_CAST(os_waitstatus_to_exitcode), METH_FASTCALL|METH_KEYWORDS, os_waitstatus_to_exitcode__doc__}, |
12622 | | |
12623 | | static PyObject * |
12624 | | os_waitstatus_to_exitcode_impl(PyObject *module, PyObject *status_obj); |
12625 | | |
12626 | | static PyObject * |
12627 | | os_waitstatus_to_exitcode(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
12628 | 0 | { |
12629 | 0 | PyObject *return_value = NULL; |
12630 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
12631 | |
|
12632 | 0 | #define NUM_KEYWORDS 1 |
12633 | 0 | static struct { |
12634 | 0 | PyGC_Head _this_is_not_used; |
12635 | 0 | PyObject_VAR_HEAD |
12636 | 0 | Py_hash_t ob_hash; |
12637 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
12638 | 0 | } _kwtuple = { |
12639 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
12640 | 0 | .ob_hash = -1, |
12641 | 0 | .ob_item = { &_Py_ID(status), }, |
12642 | 0 | }; |
12643 | 0 | #undef NUM_KEYWORDS |
12644 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
12645 | |
|
12646 | | #else // !Py_BUILD_CORE |
12647 | | # define KWTUPLE NULL |
12648 | | #endif // !Py_BUILD_CORE |
12649 | |
|
12650 | 0 | static const char * const _keywords[] = {"status", NULL}; |
12651 | 0 | static _PyArg_Parser _parser = { |
12652 | 0 | .keywords = _keywords, |
12653 | 0 | .fname = "waitstatus_to_exitcode", |
12654 | 0 | .kwtuple = KWTUPLE, |
12655 | 0 | }; |
12656 | 0 | #undef KWTUPLE |
12657 | 0 | PyObject *argsbuf[1]; |
12658 | 0 | PyObject *status_obj; |
12659 | |
|
12660 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
12661 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
12662 | 0 | if (!args) { |
12663 | 0 | goto exit; |
12664 | 0 | } |
12665 | 0 | status_obj = args[0]; |
12666 | 0 | return_value = os_waitstatus_to_exitcode_impl(module, status_obj); |
12667 | |
|
12668 | 0 | exit: |
12669 | 0 | return return_value; |
12670 | 0 | } |
12671 | | |
12672 | | #endif /* (defined(WIFEXITED) || defined(MS_WINDOWS)) */ |
12673 | | |
12674 | | #if defined(MS_WINDOWS) |
12675 | | |
12676 | | PyDoc_STRVAR(os__supports_virtual_terminal__doc__, |
12677 | | "_supports_virtual_terminal($module, /)\n" |
12678 | | "--\n" |
12679 | | "\n" |
12680 | | "Checks if virtual terminal is supported in windows"); |
12681 | | |
12682 | | #define OS__SUPPORTS_VIRTUAL_TERMINAL_METHODDEF \ |
12683 | | {"_supports_virtual_terminal", (PyCFunction)os__supports_virtual_terminal, METH_NOARGS, os__supports_virtual_terminal__doc__}, |
12684 | | |
12685 | | static PyObject * |
12686 | | os__supports_virtual_terminal_impl(PyObject *module); |
12687 | | |
12688 | | static PyObject * |
12689 | | os__supports_virtual_terminal(PyObject *module, PyObject *Py_UNUSED(ignored)) |
12690 | | { |
12691 | | return os__supports_virtual_terminal_impl(module); |
12692 | | } |
12693 | | |
12694 | | #endif /* defined(MS_WINDOWS) */ |
12695 | | |
12696 | | PyDoc_STRVAR(os__inputhook__doc__, |
12697 | | "_inputhook($module, /)\n" |
12698 | | "--\n" |
12699 | | "\n" |
12700 | | "Calls PyOS_CallInputHook droppong the GIL first"); |
12701 | | |
12702 | | #define OS__INPUTHOOK_METHODDEF \ |
12703 | | {"_inputhook", (PyCFunction)os__inputhook, METH_NOARGS, os__inputhook__doc__}, |
12704 | | |
12705 | | static PyObject * |
12706 | | os__inputhook_impl(PyObject *module); |
12707 | | |
12708 | | static PyObject * |
12709 | | os__inputhook(PyObject *module, PyObject *Py_UNUSED(ignored)) |
12710 | 0 | { |
12711 | 0 | return os__inputhook_impl(module); |
12712 | 0 | } |
12713 | | |
12714 | | PyDoc_STRVAR(os__is_inputhook_installed__doc__, |
12715 | | "_is_inputhook_installed($module, /)\n" |
12716 | | "--\n" |
12717 | | "\n" |
12718 | | "Checks if PyOS_CallInputHook is set"); |
12719 | | |
12720 | | #define OS__IS_INPUTHOOK_INSTALLED_METHODDEF \ |
12721 | | {"_is_inputhook_installed", (PyCFunction)os__is_inputhook_installed, METH_NOARGS, os__is_inputhook_installed__doc__}, |
12722 | | |
12723 | | static PyObject * |
12724 | | os__is_inputhook_installed_impl(PyObject *module); |
12725 | | |
12726 | | static PyObject * |
12727 | | os__is_inputhook_installed(PyObject *module, PyObject *Py_UNUSED(ignored)) |
12728 | 0 | { |
12729 | 0 | return os__is_inputhook_installed_impl(module); |
12730 | 0 | } |
12731 | | |
12732 | | PyDoc_STRVAR(os__create_environ__doc__, |
12733 | | "_create_environ($module, /)\n" |
12734 | | "--\n" |
12735 | | "\n" |
12736 | | "Create the environment dictionary."); |
12737 | | |
12738 | | #define OS__CREATE_ENVIRON_METHODDEF \ |
12739 | | {"_create_environ", (PyCFunction)os__create_environ, METH_NOARGS, os__create_environ__doc__}, |
12740 | | |
12741 | | static PyObject * |
12742 | | os__create_environ_impl(PyObject *module); |
12743 | | |
12744 | | static PyObject * |
12745 | | os__create_environ(PyObject *module, PyObject *Py_UNUSED(ignored)) |
12746 | 0 | { |
12747 | 0 | return os__create_environ_impl(module); |
12748 | 0 | } |
12749 | | |
12750 | | #if defined(__EMSCRIPTEN__) |
12751 | | |
12752 | | PyDoc_STRVAR(os__emscripten_debugger__doc__, |
12753 | | "_emscripten_debugger($module, /)\n" |
12754 | | "--\n" |
12755 | | "\n" |
12756 | | "Create a breakpoint for the JavaScript debugger. Emscripten only."); |
12757 | | |
12758 | | #define OS__EMSCRIPTEN_DEBUGGER_METHODDEF \ |
12759 | | {"_emscripten_debugger", (PyCFunction)os__emscripten_debugger, METH_NOARGS, os__emscripten_debugger__doc__}, |
12760 | | |
12761 | | static PyObject * |
12762 | | os__emscripten_debugger_impl(PyObject *module); |
12763 | | |
12764 | | static PyObject * |
12765 | | os__emscripten_debugger(PyObject *module, PyObject *Py_UNUSED(ignored)) |
12766 | | { |
12767 | | return os__emscripten_debugger_impl(module); |
12768 | | } |
12769 | | |
12770 | | #endif /* defined(__EMSCRIPTEN__) */ |
12771 | | |
12772 | | #ifndef OS_TTYNAME_METHODDEF |
12773 | | #define OS_TTYNAME_METHODDEF |
12774 | | #endif /* !defined(OS_TTYNAME_METHODDEF) */ |
12775 | | |
12776 | | #ifndef OS_CTERMID_METHODDEF |
12777 | | #define OS_CTERMID_METHODDEF |
12778 | | #endif /* !defined(OS_CTERMID_METHODDEF) */ |
12779 | | |
12780 | | #ifndef OS_FCHDIR_METHODDEF |
12781 | | #define OS_FCHDIR_METHODDEF |
12782 | | #endif /* !defined(OS_FCHDIR_METHODDEF) */ |
12783 | | |
12784 | | #ifndef OS_FCHMOD_METHODDEF |
12785 | | #define OS_FCHMOD_METHODDEF |
12786 | | #endif /* !defined(OS_FCHMOD_METHODDEF) */ |
12787 | | |
12788 | | #ifndef OS_LCHMOD_METHODDEF |
12789 | | #define OS_LCHMOD_METHODDEF |
12790 | | #endif /* !defined(OS_LCHMOD_METHODDEF) */ |
12791 | | |
12792 | | #ifndef OS_CHFLAGS_METHODDEF |
12793 | | #define OS_CHFLAGS_METHODDEF |
12794 | | #endif /* !defined(OS_CHFLAGS_METHODDEF) */ |
12795 | | |
12796 | | #ifndef OS_LCHFLAGS_METHODDEF |
12797 | | #define OS_LCHFLAGS_METHODDEF |
12798 | | #endif /* !defined(OS_LCHFLAGS_METHODDEF) */ |
12799 | | |
12800 | | #ifndef OS_CHROOT_METHODDEF |
12801 | | #define OS_CHROOT_METHODDEF |
12802 | | #endif /* !defined(OS_CHROOT_METHODDEF) */ |
12803 | | |
12804 | | #ifndef OS_FSYNC_METHODDEF |
12805 | | #define OS_FSYNC_METHODDEF |
12806 | | #endif /* !defined(OS_FSYNC_METHODDEF) */ |
12807 | | |
12808 | | #ifndef OS_SYNC_METHODDEF |
12809 | | #define OS_SYNC_METHODDEF |
12810 | | #endif /* !defined(OS_SYNC_METHODDEF) */ |
12811 | | |
12812 | | #ifndef OS_FDATASYNC_METHODDEF |
12813 | | #define OS_FDATASYNC_METHODDEF |
12814 | | #endif /* !defined(OS_FDATASYNC_METHODDEF) */ |
12815 | | |
12816 | | #ifndef OS_CHOWN_METHODDEF |
12817 | | #define OS_CHOWN_METHODDEF |
12818 | | #endif /* !defined(OS_CHOWN_METHODDEF) */ |
12819 | | |
12820 | | #ifndef OS_FCHOWN_METHODDEF |
12821 | | #define OS_FCHOWN_METHODDEF |
12822 | | #endif /* !defined(OS_FCHOWN_METHODDEF) */ |
12823 | | |
12824 | | #ifndef OS_LCHOWN_METHODDEF |
12825 | | #define OS_LCHOWN_METHODDEF |
12826 | | #endif /* !defined(OS_LCHOWN_METHODDEF) */ |
12827 | | |
12828 | | #ifndef OS_LINK_METHODDEF |
12829 | | #define OS_LINK_METHODDEF |
12830 | | #endif /* !defined(OS_LINK_METHODDEF) */ |
12831 | | |
12832 | | #ifndef OS_LISTDRIVES_METHODDEF |
12833 | | #define OS_LISTDRIVES_METHODDEF |
12834 | | #endif /* !defined(OS_LISTDRIVES_METHODDEF) */ |
12835 | | |
12836 | | #ifndef OS_LISTVOLUMES_METHODDEF |
12837 | | #define OS_LISTVOLUMES_METHODDEF |
12838 | | #endif /* !defined(OS_LISTVOLUMES_METHODDEF) */ |
12839 | | |
12840 | | #ifndef OS_LISTMOUNTS_METHODDEF |
12841 | | #define OS_LISTMOUNTS_METHODDEF |
12842 | | #endif /* !defined(OS_LISTMOUNTS_METHODDEF) */ |
12843 | | |
12844 | | #ifndef OS__PATH_ISDEVDRIVE_METHODDEF |
12845 | | #define OS__PATH_ISDEVDRIVE_METHODDEF |
12846 | | #endif /* !defined(OS__PATH_ISDEVDRIVE_METHODDEF) */ |
12847 | | |
12848 | | #ifndef OS__GETFULLPATHNAME_METHODDEF |
12849 | | #define OS__GETFULLPATHNAME_METHODDEF |
12850 | | #endif /* !defined(OS__GETFULLPATHNAME_METHODDEF) */ |
12851 | | |
12852 | | #ifndef OS__GETFINALPATHNAME_METHODDEF |
12853 | | #define OS__GETFINALPATHNAME_METHODDEF |
12854 | | #endif /* !defined(OS__GETFINALPATHNAME_METHODDEF) */ |
12855 | | |
12856 | | #ifndef OS__FINDFIRSTFILE_METHODDEF |
12857 | | #define OS__FINDFIRSTFILE_METHODDEF |
12858 | | #endif /* !defined(OS__FINDFIRSTFILE_METHODDEF) */ |
12859 | | |
12860 | | #ifndef OS__GETVOLUMEPATHNAME_METHODDEF |
12861 | | #define OS__GETVOLUMEPATHNAME_METHODDEF |
12862 | | #endif /* !defined(OS__GETVOLUMEPATHNAME_METHODDEF) */ |
12863 | | |
12864 | | #ifndef OS__PATH_SPLITROOT_METHODDEF |
12865 | | #define OS__PATH_SPLITROOT_METHODDEF |
12866 | | #endif /* !defined(OS__PATH_SPLITROOT_METHODDEF) */ |
12867 | | |
12868 | | #ifndef OS__PATH_EXISTS_METHODDEF |
12869 | | #define OS__PATH_EXISTS_METHODDEF |
12870 | | #endif /* !defined(OS__PATH_EXISTS_METHODDEF) */ |
12871 | | |
12872 | | #ifndef OS__PATH_LEXISTS_METHODDEF |
12873 | | #define OS__PATH_LEXISTS_METHODDEF |
12874 | | #endif /* !defined(OS__PATH_LEXISTS_METHODDEF) */ |
12875 | | |
12876 | | #ifndef OS__PATH_ISDIR_METHODDEF |
12877 | | #define OS__PATH_ISDIR_METHODDEF |
12878 | | #endif /* !defined(OS__PATH_ISDIR_METHODDEF) */ |
12879 | | |
12880 | | #ifndef OS__PATH_ISFILE_METHODDEF |
12881 | | #define OS__PATH_ISFILE_METHODDEF |
12882 | | #endif /* !defined(OS__PATH_ISFILE_METHODDEF) */ |
12883 | | |
12884 | | #ifndef OS__PATH_ISLINK_METHODDEF |
12885 | | #define OS__PATH_ISLINK_METHODDEF |
12886 | | #endif /* !defined(OS__PATH_ISLINK_METHODDEF) */ |
12887 | | |
12888 | | #ifndef OS__PATH_ISJUNCTION_METHODDEF |
12889 | | #define OS__PATH_ISJUNCTION_METHODDEF |
12890 | | #endif /* !defined(OS__PATH_ISJUNCTION_METHODDEF) */ |
12891 | | |
12892 | | #ifndef OS_NICE_METHODDEF |
12893 | | #define OS_NICE_METHODDEF |
12894 | | #endif /* !defined(OS_NICE_METHODDEF) */ |
12895 | | |
12896 | | #ifndef OS_GETPRIORITY_METHODDEF |
12897 | | #define OS_GETPRIORITY_METHODDEF |
12898 | | #endif /* !defined(OS_GETPRIORITY_METHODDEF) */ |
12899 | | |
12900 | | #ifndef OS_SETPRIORITY_METHODDEF |
12901 | | #define OS_SETPRIORITY_METHODDEF |
12902 | | #endif /* !defined(OS_SETPRIORITY_METHODDEF) */ |
12903 | | |
12904 | | #ifndef OS_SYSTEM_METHODDEF |
12905 | | #define OS_SYSTEM_METHODDEF |
12906 | | #endif /* !defined(OS_SYSTEM_METHODDEF) */ |
12907 | | |
12908 | | #ifndef OS_UMASK_METHODDEF |
12909 | | #define OS_UMASK_METHODDEF |
12910 | | #endif /* !defined(OS_UMASK_METHODDEF) */ |
12911 | | |
12912 | | #ifndef OS_UNAME_METHODDEF |
12913 | | #define OS_UNAME_METHODDEF |
12914 | | #endif /* !defined(OS_UNAME_METHODDEF) */ |
12915 | | |
12916 | | #ifndef OS_EXECV_METHODDEF |
12917 | | #define OS_EXECV_METHODDEF |
12918 | | #endif /* !defined(OS_EXECV_METHODDEF) */ |
12919 | | |
12920 | | #ifndef OS_EXECVE_METHODDEF |
12921 | | #define OS_EXECVE_METHODDEF |
12922 | | #endif /* !defined(OS_EXECVE_METHODDEF) */ |
12923 | | |
12924 | | #ifndef OS_POSIX_SPAWN_METHODDEF |
12925 | | #define OS_POSIX_SPAWN_METHODDEF |
12926 | | #endif /* !defined(OS_POSIX_SPAWN_METHODDEF) */ |
12927 | | |
12928 | | #ifndef OS_POSIX_SPAWNP_METHODDEF |
12929 | | #define OS_POSIX_SPAWNP_METHODDEF |
12930 | | #endif /* !defined(OS_POSIX_SPAWNP_METHODDEF) */ |
12931 | | |
12932 | | #ifndef OS_SPAWNV_METHODDEF |
12933 | | #define OS_SPAWNV_METHODDEF |
12934 | | #endif /* !defined(OS_SPAWNV_METHODDEF) */ |
12935 | | |
12936 | | #ifndef OS_SPAWNVE_METHODDEF |
12937 | | #define OS_SPAWNVE_METHODDEF |
12938 | | #endif /* !defined(OS_SPAWNVE_METHODDEF) */ |
12939 | | |
12940 | | #ifndef OS_REGISTER_AT_FORK_METHODDEF |
12941 | | #define OS_REGISTER_AT_FORK_METHODDEF |
12942 | | #endif /* !defined(OS_REGISTER_AT_FORK_METHODDEF) */ |
12943 | | |
12944 | | #ifndef OS_FORK1_METHODDEF |
12945 | | #define OS_FORK1_METHODDEF |
12946 | | #endif /* !defined(OS_FORK1_METHODDEF) */ |
12947 | | |
12948 | | #ifndef OS_FORK_METHODDEF |
12949 | | #define OS_FORK_METHODDEF |
12950 | | #endif /* !defined(OS_FORK_METHODDEF) */ |
12951 | | |
12952 | | #ifndef OS_SCHED_GET_PRIORITY_MAX_METHODDEF |
12953 | | #define OS_SCHED_GET_PRIORITY_MAX_METHODDEF |
12954 | | #endif /* !defined(OS_SCHED_GET_PRIORITY_MAX_METHODDEF) */ |
12955 | | |
12956 | | #ifndef OS_SCHED_GET_PRIORITY_MIN_METHODDEF |
12957 | | #define OS_SCHED_GET_PRIORITY_MIN_METHODDEF |
12958 | | #endif /* !defined(OS_SCHED_GET_PRIORITY_MIN_METHODDEF) */ |
12959 | | |
12960 | | #ifndef OS_SCHED_GETSCHEDULER_METHODDEF |
12961 | | #define OS_SCHED_GETSCHEDULER_METHODDEF |
12962 | | #endif /* !defined(OS_SCHED_GETSCHEDULER_METHODDEF) */ |
12963 | | |
12964 | | #ifndef OS_SCHED_SETSCHEDULER_METHODDEF |
12965 | | #define OS_SCHED_SETSCHEDULER_METHODDEF |
12966 | | #endif /* !defined(OS_SCHED_SETSCHEDULER_METHODDEF) */ |
12967 | | |
12968 | | #ifndef OS_SCHED_GETPARAM_METHODDEF |
12969 | | #define OS_SCHED_GETPARAM_METHODDEF |
12970 | | #endif /* !defined(OS_SCHED_GETPARAM_METHODDEF) */ |
12971 | | |
12972 | | #ifndef OS_SCHED_SETPARAM_METHODDEF |
12973 | | #define OS_SCHED_SETPARAM_METHODDEF |
12974 | | #endif /* !defined(OS_SCHED_SETPARAM_METHODDEF) */ |
12975 | | |
12976 | | #ifndef OS_SCHED_RR_GET_INTERVAL_METHODDEF |
12977 | | #define OS_SCHED_RR_GET_INTERVAL_METHODDEF |
12978 | | #endif /* !defined(OS_SCHED_RR_GET_INTERVAL_METHODDEF) */ |
12979 | | |
12980 | | #ifndef OS_SCHED_YIELD_METHODDEF |
12981 | | #define OS_SCHED_YIELD_METHODDEF |
12982 | | #endif /* !defined(OS_SCHED_YIELD_METHODDEF) */ |
12983 | | |
12984 | | #ifndef OS_SCHED_SETAFFINITY_METHODDEF |
12985 | | #define OS_SCHED_SETAFFINITY_METHODDEF |
12986 | | #endif /* !defined(OS_SCHED_SETAFFINITY_METHODDEF) */ |
12987 | | |
12988 | | #ifndef OS_SCHED_GETAFFINITY_METHODDEF |
12989 | | #define OS_SCHED_GETAFFINITY_METHODDEF |
12990 | | #endif /* !defined(OS_SCHED_GETAFFINITY_METHODDEF) */ |
12991 | | |
12992 | | #ifndef OS_POSIX_OPENPT_METHODDEF |
12993 | | #define OS_POSIX_OPENPT_METHODDEF |
12994 | | #endif /* !defined(OS_POSIX_OPENPT_METHODDEF) */ |
12995 | | |
12996 | | #ifndef OS_GRANTPT_METHODDEF |
12997 | | #define OS_GRANTPT_METHODDEF |
12998 | | #endif /* !defined(OS_GRANTPT_METHODDEF) */ |
12999 | | |
13000 | | #ifndef OS_UNLOCKPT_METHODDEF |
13001 | | #define OS_UNLOCKPT_METHODDEF |
13002 | | #endif /* !defined(OS_UNLOCKPT_METHODDEF) */ |
13003 | | |
13004 | | #ifndef OS_PTSNAME_METHODDEF |
13005 | | #define OS_PTSNAME_METHODDEF |
13006 | | #endif /* !defined(OS_PTSNAME_METHODDEF) */ |
13007 | | |
13008 | | #ifndef OS_OPENPTY_METHODDEF |
13009 | | #define OS_OPENPTY_METHODDEF |
13010 | | #endif /* !defined(OS_OPENPTY_METHODDEF) */ |
13011 | | |
13012 | | #ifndef OS_LOGIN_TTY_METHODDEF |
13013 | | #define OS_LOGIN_TTY_METHODDEF |
13014 | | #endif /* !defined(OS_LOGIN_TTY_METHODDEF) */ |
13015 | | |
13016 | | #ifndef OS_FORKPTY_METHODDEF |
13017 | | #define OS_FORKPTY_METHODDEF |
13018 | | #endif /* !defined(OS_FORKPTY_METHODDEF) */ |
13019 | | |
13020 | | #ifndef OS_GETEGID_METHODDEF |
13021 | | #define OS_GETEGID_METHODDEF |
13022 | | #endif /* !defined(OS_GETEGID_METHODDEF) */ |
13023 | | |
13024 | | #ifndef OS_GETEUID_METHODDEF |
13025 | | #define OS_GETEUID_METHODDEF |
13026 | | #endif /* !defined(OS_GETEUID_METHODDEF) */ |
13027 | | |
13028 | | #ifndef OS_GETGID_METHODDEF |
13029 | | #define OS_GETGID_METHODDEF |
13030 | | #endif /* !defined(OS_GETGID_METHODDEF) */ |
13031 | | |
13032 | | #ifndef OS_GETPID_METHODDEF |
13033 | | #define OS_GETPID_METHODDEF |
13034 | | #endif /* !defined(OS_GETPID_METHODDEF) */ |
13035 | | |
13036 | | #ifndef OS_GETGROUPLIST_METHODDEF |
13037 | | #define OS_GETGROUPLIST_METHODDEF |
13038 | | #endif /* !defined(OS_GETGROUPLIST_METHODDEF) */ |
13039 | | |
13040 | | #ifndef OS_GETGROUPS_METHODDEF |
13041 | | #define OS_GETGROUPS_METHODDEF |
13042 | | #endif /* !defined(OS_GETGROUPS_METHODDEF) */ |
13043 | | |
13044 | | #ifndef OS_INITGROUPS_METHODDEF |
13045 | | #define OS_INITGROUPS_METHODDEF |
13046 | | #endif /* !defined(OS_INITGROUPS_METHODDEF) */ |
13047 | | |
13048 | | #ifndef OS_GETPGID_METHODDEF |
13049 | | #define OS_GETPGID_METHODDEF |
13050 | | #endif /* !defined(OS_GETPGID_METHODDEF) */ |
13051 | | |
13052 | | #ifndef OS_GETPGRP_METHODDEF |
13053 | | #define OS_GETPGRP_METHODDEF |
13054 | | #endif /* !defined(OS_GETPGRP_METHODDEF) */ |
13055 | | |
13056 | | #ifndef OS_SETPGRP_METHODDEF |
13057 | | #define OS_SETPGRP_METHODDEF |
13058 | | #endif /* !defined(OS_SETPGRP_METHODDEF) */ |
13059 | | |
13060 | | #ifndef OS_GETPPID_METHODDEF |
13061 | | #define OS_GETPPID_METHODDEF |
13062 | | #endif /* !defined(OS_GETPPID_METHODDEF) */ |
13063 | | |
13064 | | #ifndef OS_GETLOGIN_METHODDEF |
13065 | | #define OS_GETLOGIN_METHODDEF |
13066 | | #endif /* !defined(OS_GETLOGIN_METHODDEF) */ |
13067 | | |
13068 | | #ifndef OS_GETUID_METHODDEF |
13069 | | #define OS_GETUID_METHODDEF |
13070 | | #endif /* !defined(OS_GETUID_METHODDEF) */ |
13071 | | |
13072 | | #ifndef OS_KILL_METHODDEF |
13073 | | #define OS_KILL_METHODDEF |
13074 | | #endif /* !defined(OS_KILL_METHODDEF) */ |
13075 | | |
13076 | | #ifndef OS_KILLPG_METHODDEF |
13077 | | #define OS_KILLPG_METHODDEF |
13078 | | #endif /* !defined(OS_KILLPG_METHODDEF) */ |
13079 | | |
13080 | | #ifndef OS_PLOCK_METHODDEF |
13081 | | #define OS_PLOCK_METHODDEF |
13082 | | #endif /* !defined(OS_PLOCK_METHODDEF) */ |
13083 | | |
13084 | | #ifndef OS_SETUID_METHODDEF |
13085 | | #define OS_SETUID_METHODDEF |
13086 | | #endif /* !defined(OS_SETUID_METHODDEF) */ |
13087 | | |
13088 | | #ifndef OS_SETEUID_METHODDEF |
13089 | | #define OS_SETEUID_METHODDEF |
13090 | | #endif /* !defined(OS_SETEUID_METHODDEF) */ |
13091 | | |
13092 | | #ifndef OS_SETEGID_METHODDEF |
13093 | | #define OS_SETEGID_METHODDEF |
13094 | | #endif /* !defined(OS_SETEGID_METHODDEF) */ |
13095 | | |
13096 | | #ifndef OS_SETREUID_METHODDEF |
13097 | | #define OS_SETREUID_METHODDEF |
13098 | | #endif /* !defined(OS_SETREUID_METHODDEF) */ |
13099 | | |
13100 | | #ifndef OS_SETREGID_METHODDEF |
13101 | | #define OS_SETREGID_METHODDEF |
13102 | | #endif /* !defined(OS_SETREGID_METHODDEF) */ |
13103 | | |
13104 | | #ifndef OS_SETGID_METHODDEF |
13105 | | #define OS_SETGID_METHODDEF |
13106 | | #endif /* !defined(OS_SETGID_METHODDEF) */ |
13107 | | |
13108 | | #ifndef OS_SETGROUPS_METHODDEF |
13109 | | #define OS_SETGROUPS_METHODDEF |
13110 | | #endif /* !defined(OS_SETGROUPS_METHODDEF) */ |
13111 | | |
13112 | | #ifndef OS_WAIT3_METHODDEF |
13113 | | #define OS_WAIT3_METHODDEF |
13114 | | #endif /* !defined(OS_WAIT3_METHODDEF) */ |
13115 | | |
13116 | | #ifndef OS_WAIT4_METHODDEF |
13117 | | #define OS_WAIT4_METHODDEF |
13118 | | #endif /* !defined(OS_WAIT4_METHODDEF) */ |
13119 | | |
13120 | | #ifndef OS_WAITID_METHODDEF |
13121 | | #define OS_WAITID_METHODDEF |
13122 | | #endif /* !defined(OS_WAITID_METHODDEF) */ |
13123 | | |
13124 | | #ifndef OS_WAITPID_METHODDEF |
13125 | | #define OS_WAITPID_METHODDEF |
13126 | | #endif /* !defined(OS_WAITPID_METHODDEF) */ |
13127 | | |
13128 | | #ifndef OS_WAIT_METHODDEF |
13129 | | #define OS_WAIT_METHODDEF |
13130 | | #endif /* !defined(OS_WAIT_METHODDEF) */ |
13131 | | |
13132 | | #ifndef OS_PIDFD_OPEN_METHODDEF |
13133 | | #define OS_PIDFD_OPEN_METHODDEF |
13134 | | #endif /* !defined(OS_PIDFD_OPEN_METHODDEF) */ |
13135 | | |
13136 | | #ifndef OS_SETNS_METHODDEF |
13137 | | #define OS_SETNS_METHODDEF |
13138 | | #endif /* !defined(OS_SETNS_METHODDEF) */ |
13139 | | |
13140 | | #ifndef OS_UNSHARE_METHODDEF |
13141 | | #define OS_UNSHARE_METHODDEF |
13142 | | #endif /* !defined(OS_UNSHARE_METHODDEF) */ |
13143 | | |
13144 | | #ifndef OS_READLINK_METHODDEF |
13145 | | #define OS_READLINK_METHODDEF |
13146 | | #endif /* !defined(OS_READLINK_METHODDEF) */ |
13147 | | |
13148 | | #ifndef OS_SYMLINK_METHODDEF |
13149 | | #define OS_SYMLINK_METHODDEF |
13150 | | #endif /* !defined(OS_SYMLINK_METHODDEF) */ |
13151 | | |
13152 | | #ifndef OS_TIMERFD_CREATE_METHODDEF |
13153 | | #define OS_TIMERFD_CREATE_METHODDEF |
13154 | | #endif /* !defined(OS_TIMERFD_CREATE_METHODDEF) */ |
13155 | | |
13156 | | #ifndef OS_TIMERFD_SETTIME_METHODDEF |
13157 | | #define OS_TIMERFD_SETTIME_METHODDEF |
13158 | | #endif /* !defined(OS_TIMERFD_SETTIME_METHODDEF) */ |
13159 | | |
13160 | | #ifndef OS_TIMERFD_SETTIME_NS_METHODDEF |
13161 | | #define OS_TIMERFD_SETTIME_NS_METHODDEF |
13162 | | #endif /* !defined(OS_TIMERFD_SETTIME_NS_METHODDEF) */ |
13163 | | |
13164 | | #ifndef OS_TIMERFD_GETTIME_METHODDEF |
13165 | | #define OS_TIMERFD_GETTIME_METHODDEF |
13166 | | #endif /* !defined(OS_TIMERFD_GETTIME_METHODDEF) */ |
13167 | | |
13168 | | #ifndef OS_TIMERFD_GETTIME_NS_METHODDEF |
13169 | | #define OS_TIMERFD_GETTIME_NS_METHODDEF |
13170 | | #endif /* !defined(OS_TIMERFD_GETTIME_NS_METHODDEF) */ |
13171 | | |
13172 | | #ifndef OS_GETSID_METHODDEF |
13173 | | #define OS_GETSID_METHODDEF |
13174 | | #endif /* !defined(OS_GETSID_METHODDEF) */ |
13175 | | |
13176 | | #ifndef OS_SETSID_METHODDEF |
13177 | | #define OS_SETSID_METHODDEF |
13178 | | #endif /* !defined(OS_SETSID_METHODDEF) */ |
13179 | | |
13180 | | #ifndef OS_SETPGID_METHODDEF |
13181 | | #define OS_SETPGID_METHODDEF |
13182 | | #endif /* !defined(OS_SETPGID_METHODDEF) */ |
13183 | | |
13184 | | #ifndef OS_TCGETPGRP_METHODDEF |
13185 | | #define OS_TCGETPGRP_METHODDEF |
13186 | | #endif /* !defined(OS_TCGETPGRP_METHODDEF) */ |
13187 | | |
13188 | | #ifndef OS_TCSETPGRP_METHODDEF |
13189 | | #define OS_TCSETPGRP_METHODDEF |
13190 | | #endif /* !defined(OS_TCSETPGRP_METHODDEF) */ |
13191 | | |
13192 | | #ifndef OS_DUP2_METHODDEF |
13193 | | #define OS_DUP2_METHODDEF |
13194 | | #endif /* !defined(OS_DUP2_METHODDEF) */ |
13195 | | |
13196 | | #ifndef OS_LOCKF_METHODDEF |
13197 | | #define OS_LOCKF_METHODDEF |
13198 | | #endif /* !defined(OS_LOCKF_METHODDEF) */ |
13199 | | |
13200 | | #ifndef OS_READV_METHODDEF |
13201 | | #define OS_READV_METHODDEF |
13202 | | #endif /* !defined(OS_READV_METHODDEF) */ |
13203 | | |
13204 | | #ifndef OS_PREAD_METHODDEF |
13205 | | #define OS_PREAD_METHODDEF |
13206 | | #endif /* !defined(OS_PREAD_METHODDEF) */ |
13207 | | |
13208 | | #ifndef OS_PREADV_METHODDEF |
13209 | | #define OS_PREADV_METHODDEF |
13210 | | #endif /* !defined(OS_PREADV_METHODDEF) */ |
13211 | | |
13212 | | #ifndef OS_SENDFILE_METHODDEF |
13213 | | #define OS_SENDFILE_METHODDEF |
13214 | | #endif /* !defined(OS_SENDFILE_METHODDEF) */ |
13215 | | |
13216 | | #ifndef OS__FCOPYFILE_METHODDEF |
13217 | | #define OS__FCOPYFILE_METHODDEF |
13218 | | #endif /* !defined(OS__FCOPYFILE_METHODDEF) */ |
13219 | | |
13220 | | #ifndef OS_PIPE_METHODDEF |
13221 | | #define OS_PIPE_METHODDEF |
13222 | | #endif /* !defined(OS_PIPE_METHODDEF) */ |
13223 | | |
13224 | | #ifndef OS_PIPE2_METHODDEF |
13225 | | #define OS_PIPE2_METHODDEF |
13226 | | #endif /* !defined(OS_PIPE2_METHODDEF) */ |
13227 | | |
13228 | | #ifndef OS_WRITEV_METHODDEF |
13229 | | #define OS_WRITEV_METHODDEF |
13230 | | #endif /* !defined(OS_WRITEV_METHODDEF) */ |
13231 | | |
13232 | | #ifndef OS_PWRITE_METHODDEF |
13233 | | #define OS_PWRITE_METHODDEF |
13234 | | #endif /* !defined(OS_PWRITE_METHODDEF) */ |
13235 | | |
13236 | | #ifndef OS_PWRITEV_METHODDEF |
13237 | | #define OS_PWRITEV_METHODDEF |
13238 | | #endif /* !defined(OS_PWRITEV_METHODDEF) */ |
13239 | | |
13240 | | #ifndef OS_COPY_FILE_RANGE_METHODDEF |
13241 | | #define OS_COPY_FILE_RANGE_METHODDEF |
13242 | | #endif /* !defined(OS_COPY_FILE_RANGE_METHODDEF) */ |
13243 | | |
13244 | | #ifndef OS_SPLICE_METHODDEF |
13245 | | #define OS_SPLICE_METHODDEF |
13246 | | #endif /* !defined(OS_SPLICE_METHODDEF) */ |
13247 | | |
13248 | | #ifndef OS_MKFIFO_METHODDEF |
13249 | | #define OS_MKFIFO_METHODDEF |
13250 | | #endif /* !defined(OS_MKFIFO_METHODDEF) */ |
13251 | | |
13252 | | #ifndef OS_MKNOD_METHODDEF |
13253 | | #define OS_MKNOD_METHODDEF |
13254 | | #endif /* !defined(OS_MKNOD_METHODDEF) */ |
13255 | | |
13256 | | #ifndef OS_MAJOR_METHODDEF |
13257 | | #define OS_MAJOR_METHODDEF |
13258 | | #endif /* !defined(OS_MAJOR_METHODDEF) */ |
13259 | | |
13260 | | #ifndef OS_MINOR_METHODDEF |
13261 | | #define OS_MINOR_METHODDEF |
13262 | | #endif /* !defined(OS_MINOR_METHODDEF) */ |
13263 | | |
13264 | | #ifndef OS_MAKEDEV_METHODDEF |
13265 | | #define OS_MAKEDEV_METHODDEF |
13266 | | #endif /* !defined(OS_MAKEDEV_METHODDEF) */ |
13267 | | |
13268 | | #ifndef OS_FTRUNCATE_METHODDEF |
13269 | | #define OS_FTRUNCATE_METHODDEF |
13270 | | #endif /* !defined(OS_FTRUNCATE_METHODDEF) */ |
13271 | | |
13272 | | #ifndef OS_TRUNCATE_METHODDEF |
13273 | | #define OS_TRUNCATE_METHODDEF |
13274 | | #endif /* !defined(OS_TRUNCATE_METHODDEF) */ |
13275 | | |
13276 | | #ifndef OS_POSIX_FALLOCATE_METHODDEF |
13277 | | #define OS_POSIX_FALLOCATE_METHODDEF |
13278 | | #endif /* !defined(OS_POSIX_FALLOCATE_METHODDEF) */ |
13279 | | |
13280 | | #ifndef OS_POSIX_FADVISE_METHODDEF |
13281 | | #define OS_POSIX_FADVISE_METHODDEF |
13282 | | #endif /* !defined(OS_POSIX_FADVISE_METHODDEF) */ |
13283 | | |
13284 | | #ifndef OS_PUTENV_METHODDEF |
13285 | | #define OS_PUTENV_METHODDEF |
13286 | | #endif /* !defined(OS_PUTENV_METHODDEF) */ |
13287 | | |
13288 | | #ifndef OS_UNSETENV_METHODDEF |
13289 | | #define OS_UNSETENV_METHODDEF |
13290 | | #endif /* !defined(OS_UNSETENV_METHODDEF) */ |
13291 | | |
13292 | | #ifndef OS_WCOREDUMP_METHODDEF |
13293 | | #define OS_WCOREDUMP_METHODDEF |
13294 | | #endif /* !defined(OS_WCOREDUMP_METHODDEF) */ |
13295 | | |
13296 | | #ifndef OS_WIFCONTINUED_METHODDEF |
13297 | | #define OS_WIFCONTINUED_METHODDEF |
13298 | | #endif /* !defined(OS_WIFCONTINUED_METHODDEF) */ |
13299 | | |
13300 | | #ifndef OS_WIFSTOPPED_METHODDEF |
13301 | | #define OS_WIFSTOPPED_METHODDEF |
13302 | | #endif /* !defined(OS_WIFSTOPPED_METHODDEF) */ |
13303 | | |
13304 | | #ifndef OS_WIFSIGNALED_METHODDEF |
13305 | | #define OS_WIFSIGNALED_METHODDEF |
13306 | | #endif /* !defined(OS_WIFSIGNALED_METHODDEF) */ |
13307 | | |
13308 | | #ifndef OS_WIFEXITED_METHODDEF |
13309 | | #define OS_WIFEXITED_METHODDEF |
13310 | | #endif /* !defined(OS_WIFEXITED_METHODDEF) */ |
13311 | | |
13312 | | #ifndef OS_WEXITSTATUS_METHODDEF |
13313 | | #define OS_WEXITSTATUS_METHODDEF |
13314 | | #endif /* !defined(OS_WEXITSTATUS_METHODDEF) */ |
13315 | | |
13316 | | #ifndef OS_WTERMSIG_METHODDEF |
13317 | | #define OS_WTERMSIG_METHODDEF |
13318 | | #endif /* !defined(OS_WTERMSIG_METHODDEF) */ |
13319 | | |
13320 | | #ifndef OS_WSTOPSIG_METHODDEF |
13321 | | #define OS_WSTOPSIG_METHODDEF |
13322 | | #endif /* !defined(OS_WSTOPSIG_METHODDEF) */ |
13323 | | |
13324 | | #ifndef OS_FSTATVFS_METHODDEF |
13325 | | #define OS_FSTATVFS_METHODDEF |
13326 | | #endif /* !defined(OS_FSTATVFS_METHODDEF) */ |
13327 | | |
13328 | | #ifndef OS_STATVFS_METHODDEF |
13329 | | #define OS_STATVFS_METHODDEF |
13330 | | #endif /* !defined(OS_STATVFS_METHODDEF) */ |
13331 | | |
13332 | | #ifndef OS__GETDISKUSAGE_METHODDEF |
13333 | | #define OS__GETDISKUSAGE_METHODDEF |
13334 | | #endif /* !defined(OS__GETDISKUSAGE_METHODDEF) */ |
13335 | | |
13336 | | #ifndef OS_FPATHCONF_METHODDEF |
13337 | | #define OS_FPATHCONF_METHODDEF |
13338 | | #endif /* !defined(OS_FPATHCONF_METHODDEF) */ |
13339 | | |
13340 | | #ifndef OS_PATHCONF_METHODDEF |
13341 | | #define OS_PATHCONF_METHODDEF |
13342 | | #endif /* !defined(OS_PATHCONF_METHODDEF) */ |
13343 | | |
13344 | | #ifndef OS_CONFSTR_METHODDEF |
13345 | | #define OS_CONFSTR_METHODDEF |
13346 | | #endif /* !defined(OS_CONFSTR_METHODDEF) */ |
13347 | | |
13348 | | #ifndef OS_SYSCONF_METHODDEF |
13349 | | #define OS_SYSCONF_METHODDEF |
13350 | | #endif /* !defined(OS_SYSCONF_METHODDEF) */ |
13351 | | |
13352 | | #ifndef OS_STARTFILE_METHODDEF |
13353 | | #define OS_STARTFILE_METHODDEF |
13354 | | #endif /* !defined(OS_STARTFILE_METHODDEF) */ |
13355 | | |
13356 | | #ifndef OS_GETLOADAVG_METHODDEF |
13357 | | #define OS_GETLOADAVG_METHODDEF |
13358 | | #endif /* !defined(OS_GETLOADAVG_METHODDEF) */ |
13359 | | |
13360 | | #ifndef OS_SETRESUID_METHODDEF |
13361 | | #define OS_SETRESUID_METHODDEF |
13362 | | #endif /* !defined(OS_SETRESUID_METHODDEF) */ |
13363 | | |
13364 | | #ifndef OS_SETRESGID_METHODDEF |
13365 | | #define OS_SETRESGID_METHODDEF |
13366 | | #endif /* !defined(OS_SETRESGID_METHODDEF) */ |
13367 | | |
13368 | | #ifndef OS_GETRESUID_METHODDEF |
13369 | | #define OS_GETRESUID_METHODDEF |
13370 | | #endif /* !defined(OS_GETRESUID_METHODDEF) */ |
13371 | | |
13372 | | #ifndef OS_GETRESGID_METHODDEF |
13373 | | #define OS_GETRESGID_METHODDEF |
13374 | | #endif /* !defined(OS_GETRESGID_METHODDEF) */ |
13375 | | |
13376 | | #ifndef OS_GETXATTR_METHODDEF |
13377 | | #define OS_GETXATTR_METHODDEF |
13378 | | #endif /* !defined(OS_GETXATTR_METHODDEF) */ |
13379 | | |
13380 | | #ifndef OS_SETXATTR_METHODDEF |
13381 | | #define OS_SETXATTR_METHODDEF |
13382 | | #endif /* !defined(OS_SETXATTR_METHODDEF) */ |
13383 | | |
13384 | | #ifndef OS_REMOVEXATTR_METHODDEF |
13385 | | #define OS_REMOVEXATTR_METHODDEF |
13386 | | #endif /* !defined(OS_REMOVEXATTR_METHODDEF) */ |
13387 | | |
13388 | | #ifndef OS_LISTXATTR_METHODDEF |
13389 | | #define OS_LISTXATTR_METHODDEF |
13390 | | #endif /* !defined(OS_LISTXATTR_METHODDEF) */ |
13391 | | |
13392 | | #ifndef OS_MEMFD_CREATE_METHODDEF |
13393 | | #define OS_MEMFD_CREATE_METHODDEF |
13394 | | #endif /* !defined(OS_MEMFD_CREATE_METHODDEF) */ |
13395 | | |
13396 | | #ifndef OS_EVENTFD_METHODDEF |
13397 | | #define OS_EVENTFD_METHODDEF |
13398 | | #endif /* !defined(OS_EVENTFD_METHODDEF) */ |
13399 | | |
13400 | | #ifndef OS_EVENTFD_READ_METHODDEF |
13401 | | #define OS_EVENTFD_READ_METHODDEF |
13402 | | #endif /* !defined(OS_EVENTFD_READ_METHODDEF) */ |
13403 | | |
13404 | | #ifndef OS_EVENTFD_WRITE_METHODDEF |
13405 | | #define OS_EVENTFD_WRITE_METHODDEF |
13406 | | #endif /* !defined(OS_EVENTFD_WRITE_METHODDEF) */ |
13407 | | |
13408 | | #ifndef OS_GET_TERMINAL_SIZE_METHODDEF |
13409 | | #define OS_GET_TERMINAL_SIZE_METHODDEF |
13410 | | #endif /* !defined(OS_GET_TERMINAL_SIZE_METHODDEF) */ |
13411 | | |
13412 | | #ifndef OS_GET_HANDLE_INHERITABLE_METHODDEF |
13413 | | #define OS_GET_HANDLE_INHERITABLE_METHODDEF |
13414 | | #endif /* !defined(OS_GET_HANDLE_INHERITABLE_METHODDEF) */ |
13415 | | |
13416 | | #ifndef OS_SET_HANDLE_INHERITABLE_METHODDEF |
13417 | | #define OS_SET_HANDLE_INHERITABLE_METHODDEF |
13418 | | #endif /* !defined(OS_SET_HANDLE_INHERITABLE_METHODDEF) */ |
13419 | | |
13420 | | #ifndef OS_GETRANDOM_METHODDEF |
13421 | | #define OS_GETRANDOM_METHODDEF |
13422 | | #endif /* !defined(OS_GETRANDOM_METHODDEF) */ |
13423 | | |
13424 | | #ifndef OS__ADD_DLL_DIRECTORY_METHODDEF |
13425 | | #define OS__ADD_DLL_DIRECTORY_METHODDEF |
13426 | | #endif /* !defined(OS__ADD_DLL_DIRECTORY_METHODDEF) */ |
13427 | | |
13428 | | #ifndef OS__REMOVE_DLL_DIRECTORY_METHODDEF |
13429 | | #define OS__REMOVE_DLL_DIRECTORY_METHODDEF |
13430 | | #endif /* !defined(OS__REMOVE_DLL_DIRECTORY_METHODDEF) */ |
13431 | | |
13432 | | #ifndef OS_WAITSTATUS_TO_EXITCODE_METHODDEF |
13433 | | #define OS_WAITSTATUS_TO_EXITCODE_METHODDEF |
13434 | | #endif /* !defined(OS_WAITSTATUS_TO_EXITCODE_METHODDEF) */ |
13435 | | |
13436 | | #ifndef OS__SUPPORTS_VIRTUAL_TERMINAL_METHODDEF |
13437 | | #define OS__SUPPORTS_VIRTUAL_TERMINAL_METHODDEF |
13438 | | #endif /* !defined(OS__SUPPORTS_VIRTUAL_TERMINAL_METHODDEF) */ |
13439 | | |
13440 | | #ifndef OS__EMSCRIPTEN_DEBUGGER_METHODDEF |
13441 | | #define OS__EMSCRIPTEN_DEBUGGER_METHODDEF |
13442 | | #endif /* !defined(OS__EMSCRIPTEN_DEBUGGER_METHODDEF) */ |
13443 | | /*[clinic end generated code: output=6cfddb3b77dc7a40 input=a9049054013a1b77]*/ |