/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.98k | { |
47 | 4.98k | PyObject *return_value = NULL; |
48 | 4.98k | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
49 | | |
50 | 4.98k | #define NUM_KEYWORDS 3 |
51 | 4.98k | static struct { |
52 | 4.98k | PyGC_Head _this_is_not_used; |
53 | 4.98k | PyObject_VAR_HEAD |
54 | 4.98k | Py_hash_t ob_hash; |
55 | 4.98k | PyObject *ob_item[NUM_KEYWORDS]; |
56 | 4.98k | } _kwtuple = { |
57 | 4.98k | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
58 | 4.98k | .ob_hash = -1, |
59 | 4.98k | .ob_item = { &_Py_ID(path), &_Py_ID(dir_fd), &_Py_ID(follow_symlinks), }, |
60 | 4.98k | }; |
61 | 4.98k | #undef NUM_KEYWORDS |
62 | 4.98k | #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.98k | static const char * const _keywords[] = {"path", "dir_fd", "follow_symlinks", NULL}; |
69 | 4.98k | static _PyArg_Parser _parser = { |
70 | 4.98k | .keywords = _keywords, |
71 | 4.98k | .fname = "stat", |
72 | 4.98k | .kwtuple = KWTUPLE, |
73 | 4.98k | }; |
74 | 4.98k | #undef KWTUPLE |
75 | 4.98k | PyObject *argsbuf[3]; |
76 | 4.98k | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
77 | 4.98k | path_t path = PATH_T_INITIALIZE_P("stat", "path", 0, 0, 0, 1); |
78 | 4.98k | int dir_fd = DEFAULT_DIR_FD; |
79 | 4.98k | int follow_symlinks = 1; |
80 | | |
81 | 4.98k | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
82 | 4.98k | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
83 | 4.98k | if (!args) { |
84 | 0 | goto exit; |
85 | 0 | } |
86 | 4.98k | if (!path_converter(args[0], &path)) { |
87 | 0 | goto exit; |
88 | 0 | } |
89 | 4.98k | if (!noptargs) { |
90 | 4.98k | goto skip_optional_kwonly; |
91 | 4.98k | } |
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.98k | skip_optional_kwonly: |
105 | 4.98k | return_value = os_stat_impl(module, &path, dir_fd, follow_symlinks); |
106 | | |
107 | 4.98k | exit: |
108 | | /* Cleanup for path */ |
109 | 4.98k | path_cleanup(&path); |
110 | | |
111 | 4.98k | return return_value; |
112 | 4.98k | } |
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 | | flags = PyLong_AsUnsignedLongMask(args[1]); |
848 | | if (!noptargs) { |
849 | | goto skip_optional_pos; |
850 | | } |
851 | | follow_symlinks = PyObject_IsTrue(args[2]); |
852 | | if (follow_symlinks < 0) { |
853 | | goto exit; |
854 | | } |
855 | | skip_optional_pos: |
856 | | return_value = os_chflags_impl(module, &path, flags, follow_symlinks); |
857 | | |
858 | | exit: |
859 | | /* Cleanup for path */ |
860 | | path_cleanup(&path); |
861 | | |
862 | | return return_value; |
863 | | } |
864 | | |
865 | | #endif /* defined(HAVE_CHFLAGS) */ |
866 | | |
867 | | #if defined(HAVE_LCHFLAGS) |
868 | | |
869 | | PyDoc_STRVAR(os_lchflags__doc__, |
870 | | "lchflags($module, /, path, flags)\n" |
871 | | "--\n" |
872 | | "\n" |
873 | | "Set file flags.\n" |
874 | | "\n" |
875 | | "This function will not follow symbolic links.\n" |
876 | | "Equivalent to chflags(path, flags, follow_symlinks=False)."); |
877 | | |
878 | | #define OS_LCHFLAGS_METHODDEF \ |
879 | | {"lchflags", _PyCFunction_CAST(os_lchflags), METH_FASTCALL|METH_KEYWORDS, os_lchflags__doc__}, |
880 | | |
881 | | static PyObject * |
882 | | os_lchflags_impl(PyObject *module, path_t *path, unsigned long flags); |
883 | | |
884 | | static PyObject * |
885 | | os_lchflags(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
886 | | { |
887 | | PyObject *return_value = NULL; |
888 | | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
889 | | |
890 | | #define NUM_KEYWORDS 2 |
891 | | static struct { |
892 | | PyGC_Head _this_is_not_used; |
893 | | PyObject_VAR_HEAD |
894 | | Py_hash_t ob_hash; |
895 | | PyObject *ob_item[NUM_KEYWORDS]; |
896 | | } _kwtuple = { |
897 | | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
898 | | .ob_hash = -1, |
899 | | .ob_item = { &_Py_ID(path), &_Py_ID(flags), }, |
900 | | }; |
901 | | #undef NUM_KEYWORDS |
902 | | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
903 | | |
904 | | #else // !Py_BUILD_CORE |
905 | | # define KWTUPLE NULL |
906 | | #endif // !Py_BUILD_CORE |
907 | | |
908 | | static const char * const _keywords[] = {"path", "flags", NULL}; |
909 | | static _PyArg_Parser _parser = { |
910 | | .keywords = _keywords, |
911 | | .fname = "lchflags", |
912 | | .kwtuple = KWTUPLE, |
913 | | }; |
914 | | #undef KWTUPLE |
915 | | PyObject *argsbuf[2]; |
916 | | path_t path = PATH_T_INITIALIZE_P("lchflags", "path", 0, 0, 0, 0); |
917 | | unsigned long flags; |
918 | | |
919 | | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
920 | | /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
921 | | if (!args) { |
922 | | goto exit; |
923 | | } |
924 | | if (!path_converter(args[0], &path)) { |
925 | | goto exit; |
926 | | } |
927 | | if (!PyIndex_Check(args[1])) { |
928 | | _PyArg_BadArgument("lchflags", "argument 'flags'", "int", args[1]); |
929 | | goto exit; |
930 | | } |
931 | | flags = PyLong_AsUnsignedLongMask(args[1]); |
932 | | return_value = os_lchflags_impl(module, &path, flags); |
933 | | |
934 | | exit: |
935 | | /* Cleanup for path */ |
936 | | path_cleanup(&path); |
937 | | |
938 | | return return_value; |
939 | | } |
940 | | |
941 | | #endif /* defined(HAVE_LCHFLAGS) */ |
942 | | |
943 | | #if defined(HAVE_CHROOT) |
944 | | |
945 | | PyDoc_STRVAR(os_chroot__doc__, |
946 | | "chroot($module, /, path)\n" |
947 | | "--\n" |
948 | | "\n" |
949 | | "Change root directory to path."); |
950 | | |
951 | | #define OS_CHROOT_METHODDEF \ |
952 | | {"chroot", _PyCFunction_CAST(os_chroot), METH_FASTCALL|METH_KEYWORDS, os_chroot__doc__}, |
953 | | |
954 | | static PyObject * |
955 | | os_chroot_impl(PyObject *module, path_t *path); |
956 | | |
957 | | static PyObject * |
958 | | os_chroot(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
959 | 0 | { |
960 | 0 | PyObject *return_value = NULL; |
961 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
962 | |
|
963 | 0 | #define NUM_KEYWORDS 1 |
964 | 0 | static struct { |
965 | 0 | PyGC_Head _this_is_not_used; |
966 | 0 | PyObject_VAR_HEAD |
967 | 0 | Py_hash_t ob_hash; |
968 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
969 | 0 | } _kwtuple = { |
970 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
971 | 0 | .ob_hash = -1, |
972 | 0 | .ob_item = { &_Py_ID(path), }, |
973 | 0 | }; |
974 | 0 | #undef NUM_KEYWORDS |
975 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
976 | |
|
977 | | #else // !Py_BUILD_CORE |
978 | | # define KWTUPLE NULL |
979 | | #endif // !Py_BUILD_CORE |
980 | |
|
981 | 0 | static const char * const _keywords[] = {"path", NULL}; |
982 | 0 | static _PyArg_Parser _parser = { |
983 | 0 | .keywords = _keywords, |
984 | 0 | .fname = "chroot", |
985 | 0 | .kwtuple = KWTUPLE, |
986 | 0 | }; |
987 | 0 | #undef KWTUPLE |
988 | 0 | PyObject *argsbuf[1]; |
989 | 0 | path_t path = PATH_T_INITIALIZE_P("chroot", "path", 0, 0, 0, 0); |
990 | |
|
991 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
992 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
993 | 0 | if (!args) { |
994 | 0 | goto exit; |
995 | 0 | } |
996 | 0 | if (!path_converter(args[0], &path)) { |
997 | 0 | goto exit; |
998 | 0 | } |
999 | 0 | return_value = os_chroot_impl(module, &path); |
1000 | |
|
1001 | 0 | exit: |
1002 | | /* Cleanup for path */ |
1003 | 0 | path_cleanup(&path); |
1004 | |
|
1005 | 0 | return return_value; |
1006 | 0 | } |
1007 | | |
1008 | | #endif /* defined(HAVE_CHROOT) */ |
1009 | | |
1010 | | #if defined(HAVE_FSYNC) |
1011 | | |
1012 | | PyDoc_STRVAR(os_fsync__doc__, |
1013 | | "fsync($module, /, fd)\n" |
1014 | | "--\n" |
1015 | | "\n" |
1016 | | "Force write of fd to disk."); |
1017 | | |
1018 | | #define OS_FSYNC_METHODDEF \ |
1019 | | {"fsync", _PyCFunction_CAST(os_fsync), METH_FASTCALL|METH_KEYWORDS, os_fsync__doc__}, |
1020 | | |
1021 | | static PyObject * |
1022 | | os_fsync_impl(PyObject *module, int fd); |
1023 | | |
1024 | | static PyObject * |
1025 | | os_fsync(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
1026 | 0 | { |
1027 | 0 | PyObject *return_value = NULL; |
1028 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
1029 | |
|
1030 | 0 | #define NUM_KEYWORDS 1 |
1031 | 0 | static struct { |
1032 | 0 | PyGC_Head _this_is_not_used; |
1033 | 0 | PyObject_VAR_HEAD |
1034 | 0 | Py_hash_t ob_hash; |
1035 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
1036 | 0 | } _kwtuple = { |
1037 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
1038 | 0 | .ob_hash = -1, |
1039 | 0 | .ob_item = { &_Py_ID(fd), }, |
1040 | 0 | }; |
1041 | 0 | #undef NUM_KEYWORDS |
1042 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
1043 | |
|
1044 | | #else // !Py_BUILD_CORE |
1045 | | # define KWTUPLE NULL |
1046 | | #endif // !Py_BUILD_CORE |
1047 | |
|
1048 | 0 | static const char * const _keywords[] = {"fd", NULL}; |
1049 | 0 | static _PyArg_Parser _parser = { |
1050 | 0 | .keywords = _keywords, |
1051 | 0 | .fname = "fsync", |
1052 | 0 | .kwtuple = KWTUPLE, |
1053 | 0 | }; |
1054 | 0 | #undef KWTUPLE |
1055 | 0 | PyObject *argsbuf[1]; |
1056 | 0 | int fd; |
1057 | |
|
1058 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
1059 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
1060 | 0 | if (!args) { |
1061 | 0 | goto exit; |
1062 | 0 | } |
1063 | 0 | fd = PyObject_AsFileDescriptor(args[0]); |
1064 | 0 | if (fd < 0) { |
1065 | 0 | goto exit; |
1066 | 0 | } |
1067 | 0 | return_value = os_fsync_impl(module, fd); |
1068 | |
|
1069 | 0 | exit: |
1070 | 0 | return return_value; |
1071 | 0 | } |
1072 | | |
1073 | | #endif /* defined(HAVE_FSYNC) */ |
1074 | | |
1075 | | #if defined(HAVE_SYNC) |
1076 | | |
1077 | | PyDoc_STRVAR(os_sync__doc__, |
1078 | | "sync($module, /)\n" |
1079 | | "--\n" |
1080 | | "\n" |
1081 | | "Force write of everything to disk."); |
1082 | | |
1083 | | #define OS_SYNC_METHODDEF \ |
1084 | | {"sync", (PyCFunction)os_sync, METH_NOARGS, os_sync__doc__}, |
1085 | | |
1086 | | static PyObject * |
1087 | | os_sync_impl(PyObject *module); |
1088 | | |
1089 | | static PyObject * |
1090 | | os_sync(PyObject *module, PyObject *Py_UNUSED(ignored)) |
1091 | 0 | { |
1092 | 0 | return os_sync_impl(module); |
1093 | 0 | } |
1094 | | |
1095 | | #endif /* defined(HAVE_SYNC) */ |
1096 | | |
1097 | | #if defined(HAVE_FDATASYNC) |
1098 | | |
1099 | | PyDoc_STRVAR(os_fdatasync__doc__, |
1100 | | "fdatasync($module, /, fd)\n" |
1101 | | "--\n" |
1102 | | "\n" |
1103 | | "Force write of fd to disk without forcing update of metadata."); |
1104 | | |
1105 | | #define OS_FDATASYNC_METHODDEF \ |
1106 | | {"fdatasync", _PyCFunction_CAST(os_fdatasync), METH_FASTCALL|METH_KEYWORDS, os_fdatasync__doc__}, |
1107 | | |
1108 | | static PyObject * |
1109 | | os_fdatasync_impl(PyObject *module, int fd); |
1110 | | |
1111 | | static PyObject * |
1112 | | os_fdatasync(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
1113 | 0 | { |
1114 | 0 | PyObject *return_value = NULL; |
1115 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
1116 | |
|
1117 | 0 | #define NUM_KEYWORDS 1 |
1118 | 0 | static struct { |
1119 | 0 | PyGC_Head _this_is_not_used; |
1120 | 0 | PyObject_VAR_HEAD |
1121 | 0 | Py_hash_t ob_hash; |
1122 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
1123 | 0 | } _kwtuple = { |
1124 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
1125 | 0 | .ob_hash = -1, |
1126 | 0 | .ob_item = { &_Py_ID(fd), }, |
1127 | 0 | }; |
1128 | 0 | #undef NUM_KEYWORDS |
1129 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
1130 | |
|
1131 | | #else // !Py_BUILD_CORE |
1132 | | # define KWTUPLE NULL |
1133 | | #endif // !Py_BUILD_CORE |
1134 | |
|
1135 | 0 | static const char * const _keywords[] = {"fd", NULL}; |
1136 | 0 | static _PyArg_Parser _parser = { |
1137 | 0 | .keywords = _keywords, |
1138 | 0 | .fname = "fdatasync", |
1139 | 0 | .kwtuple = KWTUPLE, |
1140 | 0 | }; |
1141 | 0 | #undef KWTUPLE |
1142 | 0 | PyObject *argsbuf[1]; |
1143 | 0 | int fd; |
1144 | |
|
1145 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
1146 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
1147 | 0 | if (!args) { |
1148 | 0 | goto exit; |
1149 | 0 | } |
1150 | 0 | fd = PyObject_AsFileDescriptor(args[0]); |
1151 | 0 | if (fd < 0) { |
1152 | 0 | goto exit; |
1153 | 0 | } |
1154 | 0 | return_value = os_fdatasync_impl(module, fd); |
1155 | |
|
1156 | 0 | exit: |
1157 | 0 | return return_value; |
1158 | 0 | } |
1159 | | |
1160 | | #endif /* defined(HAVE_FDATASYNC) */ |
1161 | | |
1162 | | #if defined(HAVE_CHOWN) |
1163 | | |
1164 | | PyDoc_STRVAR(os_chown__doc__, |
1165 | | "chown($module, /, path, uid, gid, *, dir_fd=None, follow_symlinks=True)\n" |
1166 | | "--\n" |
1167 | | "\n" |
1168 | | "Change the owner and group id of path to the numeric uid and gid.\\\n" |
1169 | | "\n" |
1170 | | " path\n" |
1171 | | " Path to be examined; can be string, bytes, a path-like object, or open-file-descriptor int.\n" |
1172 | | " dir_fd\n" |
1173 | | " If not None, it should be a file descriptor open to a directory,\n" |
1174 | | " and path should be relative; path will then be relative to that\n" |
1175 | | " directory.\n" |
1176 | | " follow_symlinks\n" |
1177 | | " If False, and the last element of the path is a symbolic link,\n" |
1178 | | " stat will examine the symbolic link itself instead of the file\n" |
1179 | | " the link points to.\n" |
1180 | | "\n" |
1181 | | "path may always be specified as a string.\n" |
1182 | | "On some platforms, path may also be specified as an open file descriptor.\n" |
1183 | | " If this functionality is unavailable, using it raises an exception.\n" |
1184 | | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
1185 | | " and path should be relative; path will then be relative to that directory.\n" |
1186 | | "If follow_symlinks is False, and the last element of the path is a symbolic\n" |
1187 | | " link, chown will modify the symbolic link itself instead of the file the\n" |
1188 | | " link points to.\n" |
1189 | | "It is an error to use dir_fd or follow_symlinks when specifying path as\n" |
1190 | | " an open file descriptor.\n" |
1191 | | "dir_fd and follow_symlinks may not be implemented on your platform.\n" |
1192 | | " If they are unavailable, using them will raise a NotImplementedError."); |
1193 | | |
1194 | | #define OS_CHOWN_METHODDEF \ |
1195 | | {"chown", _PyCFunction_CAST(os_chown), METH_FASTCALL|METH_KEYWORDS, os_chown__doc__}, |
1196 | | |
1197 | | static PyObject * |
1198 | | os_chown_impl(PyObject *module, path_t *path, uid_t uid, gid_t gid, |
1199 | | int dir_fd, int follow_symlinks); |
1200 | | |
1201 | | static PyObject * |
1202 | | os_chown(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
1203 | 0 | { |
1204 | 0 | PyObject *return_value = NULL; |
1205 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
1206 | |
|
1207 | 0 | #define NUM_KEYWORDS 5 |
1208 | 0 | static struct { |
1209 | 0 | PyGC_Head _this_is_not_used; |
1210 | 0 | PyObject_VAR_HEAD |
1211 | 0 | Py_hash_t ob_hash; |
1212 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
1213 | 0 | } _kwtuple = { |
1214 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
1215 | 0 | .ob_hash = -1, |
1216 | 0 | .ob_item = { &_Py_ID(path), &_Py_ID(uid), &_Py_ID(gid), &_Py_ID(dir_fd), &_Py_ID(follow_symlinks), }, |
1217 | 0 | }; |
1218 | 0 | #undef NUM_KEYWORDS |
1219 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
1220 | |
|
1221 | | #else // !Py_BUILD_CORE |
1222 | | # define KWTUPLE NULL |
1223 | | #endif // !Py_BUILD_CORE |
1224 | |
|
1225 | 0 | static const char * const _keywords[] = {"path", "uid", "gid", "dir_fd", "follow_symlinks", NULL}; |
1226 | 0 | static _PyArg_Parser _parser = { |
1227 | 0 | .keywords = _keywords, |
1228 | 0 | .fname = "chown", |
1229 | 0 | .kwtuple = KWTUPLE, |
1230 | 0 | }; |
1231 | 0 | #undef KWTUPLE |
1232 | 0 | PyObject *argsbuf[5]; |
1233 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3; |
1234 | 0 | path_t path = PATH_T_INITIALIZE_P("chown", "path", 0, 0, 0, PATH_HAVE_FCHOWN); |
1235 | 0 | uid_t uid; |
1236 | 0 | gid_t gid; |
1237 | 0 | int dir_fd = DEFAULT_DIR_FD; |
1238 | 0 | int follow_symlinks = 1; |
1239 | |
|
1240 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
1241 | 0 | /*minpos*/ 3, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
1242 | 0 | if (!args) { |
1243 | 0 | goto exit; |
1244 | 0 | } |
1245 | 0 | if (!path_converter(args[0], &path)) { |
1246 | 0 | goto exit; |
1247 | 0 | } |
1248 | 0 | if (!_Py_Uid_Converter(args[1], &uid)) { |
1249 | 0 | goto exit; |
1250 | 0 | } |
1251 | 0 | if (!_Py_Gid_Converter(args[2], &gid)) { |
1252 | 0 | goto exit; |
1253 | 0 | } |
1254 | 0 | if (!noptargs) { |
1255 | 0 | goto skip_optional_kwonly; |
1256 | 0 | } |
1257 | 0 | if (args[3]) { |
1258 | 0 | if (!FCHOWNAT_DIR_FD_CONVERTER(args[3], &dir_fd)) { |
1259 | 0 | goto exit; |
1260 | 0 | } |
1261 | 0 | if (!--noptargs) { |
1262 | 0 | goto skip_optional_kwonly; |
1263 | 0 | } |
1264 | 0 | } |
1265 | 0 | follow_symlinks = PyObject_IsTrue(args[4]); |
1266 | 0 | if (follow_symlinks < 0) { |
1267 | 0 | goto exit; |
1268 | 0 | } |
1269 | 0 | skip_optional_kwonly: |
1270 | 0 | return_value = os_chown_impl(module, &path, uid, gid, dir_fd, follow_symlinks); |
1271 | |
|
1272 | 0 | exit: |
1273 | | /* Cleanup for path */ |
1274 | 0 | path_cleanup(&path); |
1275 | |
|
1276 | 0 | return return_value; |
1277 | 0 | } |
1278 | | |
1279 | | #endif /* defined(HAVE_CHOWN) */ |
1280 | | |
1281 | | #if defined(HAVE_FCHOWN) |
1282 | | |
1283 | | PyDoc_STRVAR(os_fchown__doc__, |
1284 | | "fchown($module, /, fd, uid, gid)\n" |
1285 | | "--\n" |
1286 | | "\n" |
1287 | | "Change the owner and group id of the file specified by file descriptor.\n" |
1288 | | "\n" |
1289 | | "Equivalent to os.chown(fd, uid, gid)."); |
1290 | | |
1291 | | #define OS_FCHOWN_METHODDEF \ |
1292 | | {"fchown", _PyCFunction_CAST(os_fchown), METH_FASTCALL|METH_KEYWORDS, os_fchown__doc__}, |
1293 | | |
1294 | | static PyObject * |
1295 | | os_fchown_impl(PyObject *module, int fd, uid_t uid, gid_t gid); |
1296 | | |
1297 | | static PyObject * |
1298 | | os_fchown(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
1299 | 0 | { |
1300 | 0 | PyObject *return_value = NULL; |
1301 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
1302 | |
|
1303 | 0 | #define NUM_KEYWORDS 3 |
1304 | 0 | static struct { |
1305 | 0 | PyGC_Head _this_is_not_used; |
1306 | 0 | PyObject_VAR_HEAD |
1307 | 0 | Py_hash_t ob_hash; |
1308 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
1309 | 0 | } _kwtuple = { |
1310 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
1311 | 0 | .ob_hash = -1, |
1312 | 0 | .ob_item = { &_Py_ID(fd), &_Py_ID(uid), &_Py_ID(gid), }, |
1313 | 0 | }; |
1314 | 0 | #undef NUM_KEYWORDS |
1315 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
1316 | |
|
1317 | | #else // !Py_BUILD_CORE |
1318 | | # define KWTUPLE NULL |
1319 | | #endif // !Py_BUILD_CORE |
1320 | |
|
1321 | 0 | static const char * const _keywords[] = {"fd", "uid", "gid", NULL}; |
1322 | 0 | static _PyArg_Parser _parser = { |
1323 | 0 | .keywords = _keywords, |
1324 | 0 | .fname = "fchown", |
1325 | 0 | .kwtuple = KWTUPLE, |
1326 | 0 | }; |
1327 | 0 | #undef KWTUPLE |
1328 | 0 | PyObject *argsbuf[3]; |
1329 | 0 | int fd; |
1330 | 0 | uid_t uid; |
1331 | 0 | gid_t gid; |
1332 | |
|
1333 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
1334 | 0 | /*minpos*/ 3, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
1335 | 0 | if (!args) { |
1336 | 0 | goto exit; |
1337 | 0 | } |
1338 | 0 | fd = PyLong_AsInt(args[0]); |
1339 | 0 | if (fd == -1 && PyErr_Occurred()) { |
1340 | 0 | goto exit; |
1341 | 0 | } |
1342 | 0 | if (!_Py_Uid_Converter(args[1], &uid)) { |
1343 | 0 | goto exit; |
1344 | 0 | } |
1345 | 0 | if (!_Py_Gid_Converter(args[2], &gid)) { |
1346 | 0 | goto exit; |
1347 | 0 | } |
1348 | 0 | return_value = os_fchown_impl(module, fd, uid, gid); |
1349 | |
|
1350 | 0 | exit: |
1351 | 0 | return return_value; |
1352 | 0 | } |
1353 | | |
1354 | | #endif /* defined(HAVE_FCHOWN) */ |
1355 | | |
1356 | | #if defined(HAVE_LCHOWN) |
1357 | | |
1358 | | PyDoc_STRVAR(os_lchown__doc__, |
1359 | | "lchown($module, /, path, uid, gid)\n" |
1360 | | "--\n" |
1361 | | "\n" |
1362 | | "Change the owner and group id of path to the numeric uid and gid.\n" |
1363 | | "\n" |
1364 | | "This function will not follow symbolic links.\n" |
1365 | | "Equivalent to os.chown(path, uid, gid, follow_symlinks=False)."); |
1366 | | |
1367 | | #define OS_LCHOWN_METHODDEF \ |
1368 | | {"lchown", _PyCFunction_CAST(os_lchown), METH_FASTCALL|METH_KEYWORDS, os_lchown__doc__}, |
1369 | | |
1370 | | static PyObject * |
1371 | | os_lchown_impl(PyObject *module, path_t *path, uid_t uid, gid_t gid); |
1372 | | |
1373 | | static PyObject * |
1374 | | os_lchown(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
1375 | 0 | { |
1376 | 0 | PyObject *return_value = NULL; |
1377 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
1378 | |
|
1379 | 0 | #define NUM_KEYWORDS 3 |
1380 | 0 | static struct { |
1381 | 0 | PyGC_Head _this_is_not_used; |
1382 | 0 | PyObject_VAR_HEAD |
1383 | 0 | Py_hash_t ob_hash; |
1384 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
1385 | 0 | } _kwtuple = { |
1386 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
1387 | 0 | .ob_hash = -1, |
1388 | 0 | .ob_item = { &_Py_ID(path), &_Py_ID(uid), &_Py_ID(gid), }, |
1389 | 0 | }; |
1390 | 0 | #undef NUM_KEYWORDS |
1391 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
1392 | |
|
1393 | | #else // !Py_BUILD_CORE |
1394 | | # define KWTUPLE NULL |
1395 | | #endif // !Py_BUILD_CORE |
1396 | |
|
1397 | 0 | static const char * const _keywords[] = {"path", "uid", "gid", NULL}; |
1398 | 0 | static _PyArg_Parser _parser = { |
1399 | 0 | .keywords = _keywords, |
1400 | 0 | .fname = "lchown", |
1401 | 0 | .kwtuple = KWTUPLE, |
1402 | 0 | }; |
1403 | 0 | #undef KWTUPLE |
1404 | 0 | PyObject *argsbuf[3]; |
1405 | 0 | path_t path = PATH_T_INITIALIZE_P("lchown", "path", 0, 0, 0, 0); |
1406 | 0 | uid_t uid; |
1407 | 0 | gid_t gid; |
1408 | |
|
1409 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
1410 | 0 | /*minpos*/ 3, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
1411 | 0 | if (!args) { |
1412 | 0 | goto exit; |
1413 | 0 | } |
1414 | 0 | if (!path_converter(args[0], &path)) { |
1415 | 0 | goto exit; |
1416 | 0 | } |
1417 | 0 | if (!_Py_Uid_Converter(args[1], &uid)) { |
1418 | 0 | goto exit; |
1419 | 0 | } |
1420 | 0 | if (!_Py_Gid_Converter(args[2], &gid)) { |
1421 | 0 | goto exit; |
1422 | 0 | } |
1423 | 0 | return_value = os_lchown_impl(module, &path, uid, gid); |
1424 | |
|
1425 | 0 | exit: |
1426 | | /* Cleanup for path */ |
1427 | 0 | path_cleanup(&path); |
1428 | |
|
1429 | 0 | return return_value; |
1430 | 0 | } |
1431 | | |
1432 | | #endif /* defined(HAVE_LCHOWN) */ |
1433 | | |
1434 | | PyDoc_STRVAR(os_getcwd__doc__, |
1435 | | "getcwd($module, /)\n" |
1436 | | "--\n" |
1437 | | "\n" |
1438 | | "Return a unicode string representing the current working directory."); |
1439 | | |
1440 | | #define OS_GETCWD_METHODDEF \ |
1441 | | {"getcwd", (PyCFunction)os_getcwd, METH_NOARGS, os_getcwd__doc__}, |
1442 | | |
1443 | | static PyObject * |
1444 | | os_getcwd_impl(PyObject *module); |
1445 | | |
1446 | | static PyObject * |
1447 | | os_getcwd(PyObject *module, PyObject *Py_UNUSED(ignored)) |
1448 | 0 | { |
1449 | 0 | return os_getcwd_impl(module); |
1450 | 0 | } |
1451 | | |
1452 | | PyDoc_STRVAR(os_getcwdb__doc__, |
1453 | | "getcwdb($module, /)\n" |
1454 | | "--\n" |
1455 | | "\n" |
1456 | | "Return a bytes string representing the current working directory."); |
1457 | | |
1458 | | #define OS_GETCWDB_METHODDEF \ |
1459 | | {"getcwdb", (PyCFunction)os_getcwdb, METH_NOARGS, os_getcwdb__doc__}, |
1460 | | |
1461 | | static PyObject * |
1462 | | os_getcwdb_impl(PyObject *module); |
1463 | | |
1464 | | static PyObject * |
1465 | | os_getcwdb(PyObject *module, PyObject *Py_UNUSED(ignored)) |
1466 | 0 | { |
1467 | 0 | return os_getcwdb_impl(module); |
1468 | 0 | } |
1469 | | |
1470 | | #if defined(HAVE_LINK) |
1471 | | |
1472 | | PyDoc_STRVAR(os_link__doc__, |
1473 | | "link($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None,\n" |
1474 | | " follow_symlinks=(os.name != \'nt\'))\n" |
1475 | | "--\n" |
1476 | | "\n" |
1477 | | "Create a hard link to a file.\n" |
1478 | | "\n" |
1479 | | "If either src_dir_fd or dst_dir_fd is not None, it should be a file\n" |
1480 | | " descriptor open to a directory, and the respective path string (src or dst)\n" |
1481 | | " should be relative; the path will then be relative to that directory.\n" |
1482 | | "If follow_symlinks is False, and the last element of src is a symbolic\n" |
1483 | | " link, link will create a link to the symbolic link itself instead of the\n" |
1484 | | " file the link points to.\n" |
1485 | | "src_dir_fd, dst_dir_fd, and follow_symlinks may not be implemented on your\n" |
1486 | | " platform. If they are unavailable, using them will raise a\n" |
1487 | | " NotImplementedError."); |
1488 | | |
1489 | | #define OS_LINK_METHODDEF \ |
1490 | | {"link", _PyCFunction_CAST(os_link), METH_FASTCALL|METH_KEYWORDS, os_link__doc__}, |
1491 | | |
1492 | | static PyObject * |
1493 | | os_link_impl(PyObject *module, path_t *src, path_t *dst, int src_dir_fd, |
1494 | | int dst_dir_fd, int follow_symlinks); |
1495 | | |
1496 | | static PyObject * |
1497 | | os_link(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
1498 | 0 | { |
1499 | 0 | PyObject *return_value = NULL; |
1500 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
1501 | |
|
1502 | 0 | #define NUM_KEYWORDS 5 |
1503 | 0 | static struct { |
1504 | 0 | PyGC_Head _this_is_not_used; |
1505 | 0 | PyObject_VAR_HEAD |
1506 | 0 | Py_hash_t ob_hash; |
1507 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
1508 | 0 | } _kwtuple = { |
1509 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
1510 | 0 | .ob_hash = -1, |
1511 | 0 | .ob_item = { &_Py_ID(src), &_Py_ID(dst), &_Py_ID(src_dir_fd), &_Py_ID(dst_dir_fd), &_Py_ID(follow_symlinks), }, |
1512 | 0 | }; |
1513 | 0 | #undef NUM_KEYWORDS |
1514 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
1515 | |
|
1516 | | #else // !Py_BUILD_CORE |
1517 | | # define KWTUPLE NULL |
1518 | | #endif // !Py_BUILD_CORE |
1519 | |
|
1520 | 0 | static const char * const _keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", "follow_symlinks", NULL}; |
1521 | 0 | static _PyArg_Parser _parser = { |
1522 | 0 | .keywords = _keywords, |
1523 | 0 | .fname = "link", |
1524 | 0 | .kwtuple = KWTUPLE, |
1525 | 0 | }; |
1526 | 0 | #undef KWTUPLE |
1527 | 0 | PyObject *argsbuf[5]; |
1528 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2; |
1529 | 0 | path_t src = PATH_T_INITIALIZE_P("link", "src", 0, 0, 0, 0); |
1530 | 0 | path_t dst = PATH_T_INITIALIZE_P("link", "dst", 0, 0, 0, 0); |
1531 | 0 | int src_dir_fd = DEFAULT_DIR_FD; |
1532 | 0 | int dst_dir_fd = DEFAULT_DIR_FD; |
1533 | 0 | int follow_symlinks = -1; |
1534 | |
|
1535 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
1536 | 0 | /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
1537 | 0 | if (!args) { |
1538 | 0 | goto exit; |
1539 | 0 | } |
1540 | 0 | if (!path_converter(args[0], &src)) { |
1541 | 0 | goto exit; |
1542 | 0 | } |
1543 | 0 | if (!path_converter(args[1], &dst)) { |
1544 | 0 | goto exit; |
1545 | 0 | } |
1546 | 0 | if (!noptargs) { |
1547 | 0 | goto skip_optional_kwonly; |
1548 | 0 | } |
1549 | 0 | if (args[2]) { |
1550 | 0 | if (!dir_fd_converter(args[2], &src_dir_fd)) { |
1551 | 0 | goto exit; |
1552 | 0 | } |
1553 | 0 | if (!--noptargs) { |
1554 | 0 | goto skip_optional_kwonly; |
1555 | 0 | } |
1556 | 0 | } |
1557 | 0 | if (args[3]) { |
1558 | 0 | if (!dir_fd_converter(args[3], &dst_dir_fd)) { |
1559 | 0 | goto exit; |
1560 | 0 | } |
1561 | 0 | if (!--noptargs) { |
1562 | 0 | goto skip_optional_kwonly; |
1563 | 0 | } |
1564 | 0 | } |
1565 | 0 | follow_symlinks = PyObject_IsTrue(args[4]); |
1566 | 0 | if (follow_symlinks < 0) { |
1567 | 0 | goto exit; |
1568 | 0 | } |
1569 | 0 | skip_optional_kwonly: |
1570 | 0 | return_value = os_link_impl(module, &src, &dst, src_dir_fd, dst_dir_fd, follow_symlinks); |
1571 | |
|
1572 | 0 | exit: |
1573 | | /* Cleanup for src */ |
1574 | 0 | path_cleanup(&src); |
1575 | | /* Cleanup for dst */ |
1576 | 0 | path_cleanup(&dst); |
1577 | |
|
1578 | 0 | return return_value; |
1579 | 0 | } |
1580 | | |
1581 | | #endif /* defined(HAVE_LINK) */ |
1582 | | |
1583 | | PyDoc_STRVAR(os_listdir__doc__, |
1584 | | "listdir($module, /, path=None)\n" |
1585 | | "--\n" |
1586 | | "\n" |
1587 | | "Return a list containing the names of the files in the directory.\n" |
1588 | | "\n" |
1589 | | "path can be specified as either str, bytes, or a path-like object. If path is bytes,\n" |
1590 | | " the filenames returned will also be bytes; in all other circumstances\n" |
1591 | | " the filenames returned will be str.\n" |
1592 | | "If path is None, uses the path=\'.\'.\n" |
1593 | | "On some platforms, path may also be specified as an open file descriptor;\\\n" |
1594 | | " the file descriptor must refer to a directory.\n" |
1595 | | " If this functionality is unavailable, using it raises NotImplementedError.\n" |
1596 | | "\n" |
1597 | | "The list is in arbitrary order. It does not include the special\n" |
1598 | | "entries \'.\' and \'..\' even if they are present in the directory."); |
1599 | | |
1600 | | #define OS_LISTDIR_METHODDEF \ |
1601 | | {"listdir", _PyCFunction_CAST(os_listdir), METH_FASTCALL|METH_KEYWORDS, os_listdir__doc__}, |
1602 | | |
1603 | | static PyObject * |
1604 | | os_listdir_impl(PyObject *module, path_t *path); |
1605 | | |
1606 | | static PyObject * |
1607 | | os_listdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
1608 | 119 | { |
1609 | 119 | PyObject *return_value = NULL; |
1610 | 119 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
1611 | | |
1612 | 119 | #define NUM_KEYWORDS 1 |
1613 | 119 | static struct { |
1614 | 119 | PyGC_Head _this_is_not_used; |
1615 | 119 | PyObject_VAR_HEAD |
1616 | 119 | Py_hash_t ob_hash; |
1617 | 119 | PyObject *ob_item[NUM_KEYWORDS]; |
1618 | 119 | } _kwtuple = { |
1619 | 119 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
1620 | 119 | .ob_hash = -1, |
1621 | 119 | .ob_item = { &_Py_ID(path), }, |
1622 | 119 | }; |
1623 | 119 | #undef NUM_KEYWORDS |
1624 | 119 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
1625 | | |
1626 | | #else // !Py_BUILD_CORE |
1627 | | # define KWTUPLE NULL |
1628 | | #endif // !Py_BUILD_CORE |
1629 | | |
1630 | 119 | static const char * const _keywords[] = {"path", NULL}; |
1631 | 119 | static _PyArg_Parser _parser = { |
1632 | 119 | .keywords = _keywords, |
1633 | 119 | .fname = "listdir", |
1634 | 119 | .kwtuple = KWTUPLE, |
1635 | 119 | }; |
1636 | 119 | #undef KWTUPLE |
1637 | 119 | PyObject *argsbuf[1]; |
1638 | 119 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; |
1639 | 119 | path_t path = PATH_T_INITIALIZE_P("listdir", "path", 1, 0, 0, PATH_HAVE_FDOPENDIR); |
1640 | | |
1641 | 119 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
1642 | 119 | /*minpos*/ 0, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
1643 | 119 | if (!args) { |
1644 | 0 | goto exit; |
1645 | 0 | } |
1646 | 119 | if (!noptargs) { |
1647 | 0 | goto skip_optional_pos; |
1648 | 0 | } |
1649 | 119 | if (!path_converter(args[0], &path)) { |
1650 | 0 | goto exit; |
1651 | 0 | } |
1652 | 119 | skip_optional_pos: |
1653 | 119 | return_value = os_listdir_impl(module, &path); |
1654 | | |
1655 | 119 | exit: |
1656 | | /* Cleanup for path */ |
1657 | 119 | path_cleanup(&path); |
1658 | | |
1659 | 119 | return return_value; |
1660 | 119 | } |
1661 | | |
1662 | | #if (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM)) |
1663 | | |
1664 | | PyDoc_STRVAR(os_listdrives__doc__, |
1665 | | "listdrives($module, /)\n" |
1666 | | "--\n" |
1667 | | "\n" |
1668 | | "Return a list containing the names of drives in the system.\n" |
1669 | | "\n" |
1670 | | "A drive name typically looks like \'C:\\\\\'."); |
1671 | | |
1672 | | #define OS_LISTDRIVES_METHODDEF \ |
1673 | | {"listdrives", (PyCFunction)os_listdrives, METH_NOARGS, os_listdrives__doc__}, |
1674 | | |
1675 | | static PyObject * |
1676 | | os_listdrives_impl(PyObject *module); |
1677 | | |
1678 | | static PyObject * |
1679 | | os_listdrives(PyObject *module, PyObject *Py_UNUSED(ignored)) |
1680 | | { |
1681 | | return os_listdrives_impl(module); |
1682 | | } |
1683 | | |
1684 | | #endif /* (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM)) */ |
1685 | | |
1686 | | #if (defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM)) |
1687 | | |
1688 | | PyDoc_STRVAR(os_listvolumes__doc__, |
1689 | | "listvolumes($module, /)\n" |
1690 | | "--\n" |
1691 | | "\n" |
1692 | | "Return a list containing the volumes in the system.\n" |
1693 | | "\n" |
1694 | | "Volumes are typically represented as a GUID path."); |
1695 | | |
1696 | | #define OS_LISTVOLUMES_METHODDEF \ |
1697 | | {"listvolumes", (PyCFunction)os_listvolumes, METH_NOARGS, os_listvolumes__doc__}, |
1698 | | |
1699 | | static PyObject * |
1700 | | os_listvolumes_impl(PyObject *module); |
1701 | | |
1702 | | static PyObject * |
1703 | | os_listvolumes(PyObject *module, PyObject *Py_UNUSED(ignored)) |
1704 | | { |
1705 | | return os_listvolumes_impl(module); |
1706 | | } |
1707 | | |
1708 | | #endif /* (defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM)) */ |
1709 | | |
1710 | | #if (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM)) |
1711 | | |
1712 | | PyDoc_STRVAR(os_listmounts__doc__, |
1713 | | "listmounts($module, /, volume)\n" |
1714 | | "--\n" |
1715 | | "\n" |
1716 | | "Return a list containing mount points for a particular volume.\n" |
1717 | | "\n" |
1718 | | "\'volume\' should be a GUID path as returned from os.listvolumes."); |
1719 | | |
1720 | | #define OS_LISTMOUNTS_METHODDEF \ |
1721 | | {"listmounts", _PyCFunction_CAST(os_listmounts), METH_FASTCALL|METH_KEYWORDS, os_listmounts__doc__}, |
1722 | | |
1723 | | static PyObject * |
1724 | | os_listmounts_impl(PyObject *module, path_t *volume); |
1725 | | |
1726 | | static PyObject * |
1727 | | os_listmounts(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
1728 | | { |
1729 | | PyObject *return_value = NULL; |
1730 | | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
1731 | | |
1732 | | #define NUM_KEYWORDS 1 |
1733 | | static struct { |
1734 | | PyGC_Head _this_is_not_used; |
1735 | | PyObject_VAR_HEAD |
1736 | | Py_hash_t ob_hash; |
1737 | | PyObject *ob_item[NUM_KEYWORDS]; |
1738 | | } _kwtuple = { |
1739 | | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
1740 | | .ob_hash = -1, |
1741 | | .ob_item = { &_Py_ID(volume), }, |
1742 | | }; |
1743 | | #undef NUM_KEYWORDS |
1744 | | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
1745 | | |
1746 | | #else // !Py_BUILD_CORE |
1747 | | # define KWTUPLE NULL |
1748 | | #endif // !Py_BUILD_CORE |
1749 | | |
1750 | | static const char * const _keywords[] = {"volume", NULL}; |
1751 | | static _PyArg_Parser _parser = { |
1752 | | .keywords = _keywords, |
1753 | | .fname = "listmounts", |
1754 | | .kwtuple = KWTUPLE, |
1755 | | }; |
1756 | | #undef KWTUPLE |
1757 | | PyObject *argsbuf[1]; |
1758 | | path_t volume = PATH_T_INITIALIZE_P("listmounts", "volume", 0, 0, 0, 0); |
1759 | | |
1760 | | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
1761 | | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
1762 | | if (!args) { |
1763 | | goto exit; |
1764 | | } |
1765 | | if (!path_converter(args[0], &volume)) { |
1766 | | goto exit; |
1767 | | } |
1768 | | return_value = os_listmounts_impl(module, &volume); |
1769 | | |
1770 | | exit: |
1771 | | /* Cleanup for volume */ |
1772 | | path_cleanup(&volume); |
1773 | | |
1774 | | return return_value; |
1775 | | } |
1776 | | |
1777 | | #endif /* (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM)) */ |
1778 | | |
1779 | | #if defined(MS_WINDOWS) |
1780 | | |
1781 | | PyDoc_STRVAR(os__path_isdevdrive__doc__, |
1782 | | "_path_isdevdrive($module, /, path)\n" |
1783 | | "--\n" |
1784 | | "\n" |
1785 | | "Determines whether the specified path is on a Windows Dev Drive."); |
1786 | | |
1787 | | #define OS__PATH_ISDEVDRIVE_METHODDEF \ |
1788 | | {"_path_isdevdrive", _PyCFunction_CAST(os__path_isdevdrive), METH_FASTCALL|METH_KEYWORDS, os__path_isdevdrive__doc__}, |
1789 | | |
1790 | | static PyObject * |
1791 | | os__path_isdevdrive_impl(PyObject *module, path_t *path); |
1792 | | |
1793 | | static PyObject * |
1794 | | os__path_isdevdrive(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
1795 | | { |
1796 | | PyObject *return_value = NULL; |
1797 | | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
1798 | | |
1799 | | #define NUM_KEYWORDS 1 |
1800 | | static struct { |
1801 | | PyGC_Head _this_is_not_used; |
1802 | | PyObject_VAR_HEAD |
1803 | | Py_hash_t ob_hash; |
1804 | | PyObject *ob_item[NUM_KEYWORDS]; |
1805 | | } _kwtuple = { |
1806 | | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
1807 | | .ob_hash = -1, |
1808 | | .ob_item = { &_Py_ID(path), }, |
1809 | | }; |
1810 | | #undef NUM_KEYWORDS |
1811 | | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
1812 | | |
1813 | | #else // !Py_BUILD_CORE |
1814 | | # define KWTUPLE NULL |
1815 | | #endif // !Py_BUILD_CORE |
1816 | | |
1817 | | static const char * const _keywords[] = {"path", NULL}; |
1818 | | static _PyArg_Parser _parser = { |
1819 | | .keywords = _keywords, |
1820 | | .fname = "_path_isdevdrive", |
1821 | | .kwtuple = KWTUPLE, |
1822 | | }; |
1823 | | #undef KWTUPLE |
1824 | | PyObject *argsbuf[1]; |
1825 | | path_t path = PATH_T_INITIALIZE_P("_path_isdevdrive", "path", 0, 0, 0, 0); |
1826 | | |
1827 | | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
1828 | | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
1829 | | if (!args) { |
1830 | | goto exit; |
1831 | | } |
1832 | | if (!path_converter(args[0], &path)) { |
1833 | | goto exit; |
1834 | | } |
1835 | | return_value = os__path_isdevdrive_impl(module, &path); |
1836 | | |
1837 | | exit: |
1838 | | /* Cleanup for path */ |
1839 | | path_cleanup(&path); |
1840 | | |
1841 | | return return_value; |
1842 | | } |
1843 | | |
1844 | | #endif /* defined(MS_WINDOWS) */ |
1845 | | |
1846 | | #if defined(MS_WINDOWS) |
1847 | | |
1848 | | PyDoc_STRVAR(os__getfullpathname__doc__, |
1849 | | "_getfullpathname($module, path, /)\n" |
1850 | | "--\n" |
1851 | | "\n"); |
1852 | | |
1853 | | #define OS__GETFULLPATHNAME_METHODDEF \ |
1854 | | {"_getfullpathname", (PyCFunction)os__getfullpathname, METH_O, os__getfullpathname__doc__}, |
1855 | | |
1856 | | static PyObject * |
1857 | | os__getfullpathname_impl(PyObject *module, path_t *path); |
1858 | | |
1859 | | static PyObject * |
1860 | | os__getfullpathname(PyObject *module, PyObject *arg) |
1861 | | { |
1862 | | PyObject *return_value = NULL; |
1863 | | path_t path = PATH_T_INITIALIZE_P("_getfullpathname", "path", 0, 0, 0, 0); |
1864 | | |
1865 | | if (!path_converter(arg, &path)) { |
1866 | | goto exit; |
1867 | | } |
1868 | | return_value = os__getfullpathname_impl(module, &path); |
1869 | | |
1870 | | exit: |
1871 | | /* Cleanup for path */ |
1872 | | path_cleanup(&path); |
1873 | | |
1874 | | return return_value; |
1875 | | } |
1876 | | |
1877 | | #endif /* defined(MS_WINDOWS) */ |
1878 | | |
1879 | | #if defined(MS_WINDOWS) |
1880 | | |
1881 | | PyDoc_STRVAR(os__getfinalpathname__doc__, |
1882 | | "_getfinalpathname($module, path, /)\n" |
1883 | | "--\n" |
1884 | | "\n" |
1885 | | "A helper function for samepath on windows."); |
1886 | | |
1887 | | #define OS__GETFINALPATHNAME_METHODDEF \ |
1888 | | {"_getfinalpathname", (PyCFunction)os__getfinalpathname, METH_O, os__getfinalpathname__doc__}, |
1889 | | |
1890 | | static PyObject * |
1891 | | os__getfinalpathname_impl(PyObject *module, path_t *path); |
1892 | | |
1893 | | static PyObject * |
1894 | | os__getfinalpathname(PyObject *module, PyObject *arg) |
1895 | | { |
1896 | | PyObject *return_value = NULL; |
1897 | | path_t path = PATH_T_INITIALIZE_P("_getfinalpathname", "path", 0, 0, 0, 0); |
1898 | | |
1899 | | if (!path_converter(arg, &path)) { |
1900 | | goto exit; |
1901 | | } |
1902 | | return_value = os__getfinalpathname_impl(module, &path); |
1903 | | |
1904 | | exit: |
1905 | | /* Cleanup for path */ |
1906 | | path_cleanup(&path); |
1907 | | |
1908 | | return return_value; |
1909 | | } |
1910 | | |
1911 | | #endif /* defined(MS_WINDOWS) */ |
1912 | | |
1913 | | #if defined(MS_WINDOWS) |
1914 | | |
1915 | | PyDoc_STRVAR(os__findfirstfile__doc__, |
1916 | | "_findfirstfile($module, path, /)\n" |
1917 | | "--\n" |
1918 | | "\n" |
1919 | | "A function to get the real file name without accessing the file in Windows."); |
1920 | | |
1921 | | #define OS__FINDFIRSTFILE_METHODDEF \ |
1922 | | {"_findfirstfile", (PyCFunction)os__findfirstfile, METH_O, os__findfirstfile__doc__}, |
1923 | | |
1924 | | static PyObject * |
1925 | | os__findfirstfile_impl(PyObject *module, path_t *path); |
1926 | | |
1927 | | static PyObject * |
1928 | | os__findfirstfile(PyObject *module, PyObject *arg) |
1929 | | { |
1930 | | PyObject *return_value = NULL; |
1931 | | path_t path = PATH_T_INITIALIZE_P("_findfirstfile", "path", 0, 0, 0, 0); |
1932 | | |
1933 | | if (!path_converter(arg, &path)) { |
1934 | | goto exit; |
1935 | | } |
1936 | | return_value = os__findfirstfile_impl(module, &path); |
1937 | | |
1938 | | exit: |
1939 | | /* Cleanup for path */ |
1940 | | path_cleanup(&path); |
1941 | | |
1942 | | return return_value; |
1943 | | } |
1944 | | |
1945 | | #endif /* defined(MS_WINDOWS) */ |
1946 | | |
1947 | | #if defined(MS_WINDOWS) |
1948 | | |
1949 | | PyDoc_STRVAR(os__getvolumepathname__doc__, |
1950 | | "_getvolumepathname($module, /, path)\n" |
1951 | | "--\n" |
1952 | | "\n" |
1953 | | "A helper function for ismount on Win32."); |
1954 | | |
1955 | | #define OS__GETVOLUMEPATHNAME_METHODDEF \ |
1956 | | {"_getvolumepathname", _PyCFunction_CAST(os__getvolumepathname), METH_FASTCALL|METH_KEYWORDS, os__getvolumepathname__doc__}, |
1957 | | |
1958 | | static PyObject * |
1959 | | os__getvolumepathname_impl(PyObject *module, path_t *path); |
1960 | | |
1961 | | static PyObject * |
1962 | | os__getvolumepathname(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
1963 | | { |
1964 | | PyObject *return_value = NULL; |
1965 | | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
1966 | | |
1967 | | #define NUM_KEYWORDS 1 |
1968 | | static struct { |
1969 | | PyGC_Head _this_is_not_used; |
1970 | | PyObject_VAR_HEAD |
1971 | | Py_hash_t ob_hash; |
1972 | | PyObject *ob_item[NUM_KEYWORDS]; |
1973 | | } _kwtuple = { |
1974 | | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
1975 | | .ob_hash = -1, |
1976 | | .ob_item = { &_Py_ID(path), }, |
1977 | | }; |
1978 | | #undef NUM_KEYWORDS |
1979 | | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
1980 | | |
1981 | | #else // !Py_BUILD_CORE |
1982 | | # define KWTUPLE NULL |
1983 | | #endif // !Py_BUILD_CORE |
1984 | | |
1985 | | static const char * const _keywords[] = {"path", NULL}; |
1986 | | static _PyArg_Parser _parser = { |
1987 | | .keywords = _keywords, |
1988 | | .fname = "_getvolumepathname", |
1989 | | .kwtuple = KWTUPLE, |
1990 | | }; |
1991 | | #undef KWTUPLE |
1992 | | PyObject *argsbuf[1]; |
1993 | | path_t path = PATH_T_INITIALIZE_P("_getvolumepathname", "path", 0, 0, 0, 0); |
1994 | | |
1995 | | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
1996 | | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
1997 | | if (!args) { |
1998 | | goto exit; |
1999 | | } |
2000 | | if (!path_converter(args[0], &path)) { |
2001 | | goto exit; |
2002 | | } |
2003 | | return_value = os__getvolumepathname_impl(module, &path); |
2004 | | |
2005 | | exit: |
2006 | | /* Cleanup for path */ |
2007 | | path_cleanup(&path); |
2008 | | |
2009 | | return return_value; |
2010 | | } |
2011 | | |
2012 | | #endif /* defined(MS_WINDOWS) */ |
2013 | | |
2014 | | #if defined(MS_WINDOWS) |
2015 | | |
2016 | | PyDoc_STRVAR(os__path_splitroot__doc__, |
2017 | | "_path_splitroot($module, /, path)\n" |
2018 | | "--\n" |
2019 | | "\n" |
2020 | | "Removes everything after the root on Win32."); |
2021 | | |
2022 | | #define OS__PATH_SPLITROOT_METHODDEF \ |
2023 | | {"_path_splitroot", _PyCFunction_CAST(os__path_splitroot), METH_FASTCALL|METH_KEYWORDS, os__path_splitroot__doc__}, |
2024 | | |
2025 | | static PyObject * |
2026 | | os__path_splitroot_impl(PyObject *module, path_t *path); |
2027 | | |
2028 | | static PyObject * |
2029 | | os__path_splitroot(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
2030 | | { |
2031 | | PyObject *return_value = NULL; |
2032 | | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
2033 | | |
2034 | | #define NUM_KEYWORDS 1 |
2035 | | static struct { |
2036 | | PyGC_Head _this_is_not_used; |
2037 | | PyObject_VAR_HEAD |
2038 | | Py_hash_t ob_hash; |
2039 | | PyObject *ob_item[NUM_KEYWORDS]; |
2040 | | } _kwtuple = { |
2041 | | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
2042 | | .ob_hash = -1, |
2043 | | .ob_item = { &_Py_ID(path), }, |
2044 | | }; |
2045 | | #undef NUM_KEYWORDS |
2046 | | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
2047 | | |
2048 | | #else // !Py_BUILD_CORE |
2049 | | # define KWTUPLE NULL |
2050 | | #endif // !Py_BUILD_CORE |
2051 | | |
2052 | | static const char * const _keywords[] = {"path", NULL}; |
2053 | | static _PyArg_Parser _parser = { |
2054 | | .keywords = _keywords, |
2055 | | .fname = "_path_splitroot", |
2056 | | .kwtuple = KWTUPLE, |
2057 | | }; |
2058 | | #undef KWTUPLE |
2059 | | PyObject *argsbuf[1]; |
2060 | | path_t path = PATH_T_INITIALIZE_P("_path_splitroot", "path", 0, 0, 0, 0); |
2061 | | |
2062 | | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
2063 | | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
2064 | | if (!args) { |
2065 | | goto exit; |
2066 | | } |
2067 | | if (!path_converter(args[0], &path)) { |
2068 | | goto exit; |
2069 | | } |
2070 | | return_value = os__path_splitroot_impl(module, &path); |
2071 | | |
2072 | | exit: |
2073 | | /* Cleanup for path */ |
2074 | | path_cleanup(&path); |
2075 | | |
2076 | | return return_value; |
2077 | | } |
2078 | | |
2079 | | #endif /* defined(MS_WINDOWS) */ |
2080 | | |
2081 | | #if defined(MS_WINDOWS) |
2082 | | |
2083 | | PyDoc_STRVAR(os__path_exists__doc__, |
2084 | | "_path_exists($module, /, path)\n" |
2085 | | "--\n" |
2086 | | "\n" |
2087 | | "Test whether a path exists. Returns False for broken symbolic links."); |
2088 | | |
2089 | | #define OS__PATH_EXISTS_METHODDEF \ |
2090 | | {"_path_exists", _PyCFunction_CAST(os__path_exists), METH_FASTCALL|METH_KEYWORDS, os__path_exists__doc__}, |
2091 | | |
2092 | | static int |
2093 | | os__path_exists_impl(PyObject *module, path_t *path); |
2094 | | |
2095 | | static PyObject * |
2096 | | os__path_exists(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
2097 | | { |
2098 | | PyObject *return_value = NULL; |
2099 | | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
2100 | | |
2101 | | #define NUM_KEYWORDS 1 |
2102 | | static struct { |
2103 | | PyGC_Head _this_is_not_used; |
2104 | | PyObject_VAR_HEAD |
2105 | | Py_hash_t ob_hash; |
2106 | | PyObject *ob_item[NUM_KEYWORDS]; |
2107 | | } _kwtuple = { |
2108 | | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
2109 | | .ob_hash = -1, |
2110 | | .ob_item = { &_Py_ID(path), }, |
2111 | | }; |
2112 | | #undef NUM_KEYWORDS |
2113 | | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
2114 | | |
2115 | | #else // !Py_BUILD_CORE |
2116 | | # define KWTUPLE NULL |
2117 | | #endif // !Py_BUILD_CORE |
2118 | | |
2119 | | static const char * const _keywords[] = {"path", NULL}; |
2120 | | static _PyArg_Parser _parser = { |
2121 | | .keywords = _keywords, |
2122 | | .fname = "_path_exists", |
2123 | | .kwtuple = KWTUPLE, |
2124 | | }; |
2125 | | #undef KWTUPLE |
2126 | | PyObject *argsbuf[1]; |
2127 | | path_t path = PATH_T_INITIALIZE_P("_path_exists", "path", 0, 0, 1, 1); |
2128 | | int _return_value; |
2129 | | |
2130 | | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
2131 | | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
2132 | | if (!args) { |
2133 | | goto exit; |
2134 | | } |
2135 | | if (!path_converter(args[0], &path)) { |
2136 | | goto exit; |
2137 | | } |
2138 | | _return_value = os__path_exists_impl(module, &path); |
2139 | | if ((_return_value == -1) && PyErr_Occurred()) { |
2140 | | goto exit; |
2141 | | } |
2142 | | return_value = PyBool_FromLong((long)_return_value); |
2143 | | |
2144 | | exit: |
2145 | | /* Cleanup for path */ |
2146 | | path_cleanup(&path); |
2147 | | |
2148 | | return return_value; |
2149 | | } |
2150 | | |
2151 | | #endif /* defined(MS_WINDOWS) */ |
2152 | | |
2153 | | #if defined(MS_WINDOWS) |
2154 | | |
2155 | | PyDoc_STRVAR(os__path_lexists__doc__, |
2156 | | "_path_lexists($module, /, path)\n" |
2157 | | "--\n" |
2158 | | "\n" |
2159 | | "Test whether a path exists. Returns True for broken symbolic links."); |
2160 | | |
2161 | | #define OS__PATH_LEXISTS_METHODDEF \ |
2162 | | {"_path_lexists", _PyCFunction_CAST(os__path_lexists), METH_FASTCALL|METH_KEYWORDS, os__path_lexists__doc__}, |
2163 | | |
2164 | | static int |
2165 | | os__path_lexists_impl(PyObject *module, path_t *path); |
2166 | | |
2167 | | static PyObject * |
2168 | | os__path_lexists(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
2169 | | { |
2170 | | PyObject *return_value = NULL; |
2171 | | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
2172 | | |
2173 | | #define NUM_KEYWORDS 1 |
2174 | | static struct { |
2175 | | PyGC_Head _this_is_not_used; |
2176 | | PyObject_VAR_HEAD |
2177 | | Py_hash_t ob_hash; |
2178 | | PyObject *ob_item[NUM_KEYWORDS]; |
2179 | | } _kwtuple = { |
2180 | | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
2181 | | .ob_hash = -1, |
2182 | | .ob_item = { &_Py_ID(path), }, |
2183 | | }; |
2184 | | #undef NUM_KEYWORDS |
2185 | | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
2186 | | |
2187 | | #else // !Py_BUILD_CORE |
2188 | | # define KWTUPLE NULL |
2189 | | #endif // !Py_BUILD_CORE |
2190 | | |
2191 | | static const char * const _keywords[] = {"path", NULL}; |
2192 | | static _PyArg_Parser _parser = { |
2193 | | .keywords = _keywords, |
2194 | | .fname = "_path_lexists", |
2195 | | .kwtuple = KWTUPLE, |
2196 | | }; |
2197 | | #undef KWTUPLE |
2198 | | PyObject *argsbuf[1]; |
2199 | | path_t path = PATH_T_INITIALIZE_P("_path_lexists", "path", 0, 0, 1, 1); |
2200 | | int _return_value; |
2201 | | |
2202 | | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
2203 | | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
2204 | | if (!args) { |
2205 | | goto exit; |
2206 | | } |
2207 | | if (!path_converter(args[0], &path)) { |
2208 | | goto exit; |
2209 | | } |
2210 | | _return_value = os__path_lexists_impl(module, &path); |
2211 | | if ((_return_value == -1) && PyErr_Occurred()) { |
2212 | | goto exit; |
2213 | | } |
2214 | | return_value = PyBool_FromLong((long)_return_value); |
2215 | | |
2216 | | exit: |
2217 | | /* Cleanup for path */ |
2218 | | path_cleanup(&path); |
2219 | | |
2220 | | return return_value; |
2221 | | } |
2222 | | |
2223 | | #endif /* defined(MS_WINDOWS) */ |
2224 | | |
2225 | | #if defined(MS_WINDOWS) |
2226 | | |
2227 | | PyDoc_STRVAR(os__path_isdir__doc__, |
2228 | | "_path_isdir($module, /, s)\n" |
2229 | | "--\n" |
2230 | | "\n" |
2231 | | "Return true if the pathname refers to an existing directory."); |
2232 | | |
2233 | | #define OS__PATH_ISDIR_METHODDEF \ |
2234 | | {"_path_isdir", _PyCFunction_CAST(os__path_isdir), METH_FASTCALL|METH_KEYWORDS, os__path_isdir__doc__}, |
2235 | | |
2236 | | static int |
2237 | | os__path_isdir_impl(PyObject *module, path_t *path); |
2238 | | |
2239 | | static PyObject * |
2240 | | os__path_isdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
2241 | | { |
2242 | | PyObject *return_value = NULL; |
2243 | | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
2244 | | |
2245 | | #define NUM_KEYWORDS 1 |
2246 | | static struct { |
2247 | | PyGC_Head _this_is_not_used; |
2248 | | PyObject_VAR_HEAD |
2249 | | Py_hash_t ob_hash; |
2250 | | PyObject *ob_item[NUM_KEYWORDS]; |
2251 | | } _kwtuple = { |
2252 | | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
2253 | | .ob_hash = -1, |
2254 | | .ob_item = { _Py_LATIN1_CHR('s'), }, |
2255 | | }; |
2256 | | #undef NUM_KEYWORDS |
2257 | | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
2258 | | |
2259 | | #else // !Py_BUILD_CORE |
2260 | | # define KWTUPLE NULL |
2261 | | #endif // !Py_BUILD_CORE |
2262 | | |
2263 | | static const char * const _keywords[] = {"s", NULL}; |
2264 | | static _PyArg_Parser _parser = { |
2265 | | .keywords = _keywords, |
2266 | | .fname = "_path_isdir", |
2267 | | .kwtuple = KWTUPLE, |
2268 | | }; |
2269 | | #undef KWTUPLE |
2270 | | PyObject *argsbuf[1]; |
2271 | | path_t path = PATH_T_INITIALIZE_P("_path_isdir", "path", 0, 0, 1, 1); |
2272 | | int _return_value; |
2273 | | |
2274 | | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
2275 | | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
2276 | | if (!args) { |
2277 | | goto exit; |
2278 | | } |
2279 | | if (!path_converter(args[0], &path)) { |
2280 | | goto exit; |
2281 | | } |
2282 | | _return_value = os__path_isdir_impl(module, &path); |
2283 | | if ((_return_value == -1) && PyErr_Occurred()) { |
2284 | | goto exit; |
2285 | | } |
2286 | | return_value = PyBool_FromLong((long)_return_value); |
2287 | | |
2288 | | exit: |
2289 | | /* Cleanup for path */ |
2290 | | path_cleanup(&path); |
2291 | | |
2292 | | return return_value; |
2293 | | } |
2294 | | |
2295 | | #endif /* defined(MS_WINDOWS) */ |
2296 | | |
2297 | | #if defined(MS_WINDOWS) |
2298 | | |
2299 | | PyDoc_STRVAR(os__path_isfile__doc__, |
2300 | | "_path_isfile($module, /, path)\n" |
2301 | | "--\n" |
2302 | | "\n" |
2303 | | "Test whether a path is a regular file"); |
2304 | | |
2305 | | #define OS__PATH_ISFILE_METHODDEF \ |
2306 | | {"_path_isfile", _PyCFunction_CAST(os__path_isfile), METH_FASTCALL|METH_KEYWORDS, os__path_isfile__doc__}, |
2307 | | |
2308 | | static int |
2309 | | os__path_isfile_impl(PyObject *module, path_t *path); |
2310 | | |
2311 | | static PyObject * |
2312 | | os__path_isfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
2313 | | { |
2314 | | PyObject *return_value = NULL; |
2315 | | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
2316 | | |
2317 | | #define NUM_KEYWORDS 1 |
2318 | | static struct { |
2319 | | PyGC_Head _this_is_not_used; |
2320 | | PyObject_VAR_HEAD |
2321 | | Py_hash_t ob_hash; |
2322 | | PyObject *ob_item[NUM_KEYWORDS]; |
2323 | | } _kwtuple = { |
2324 | | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
2325 | | .ob_hash = -1, |
2326 | | .ob_item = { &_Py_ID(path), }, |
2327 | | }; |
2328 | | #undef NUM_KEYWORDS |
2329 | | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
2330 | | |
2331 | | #else // !Py_BUILD_CORE |
2332 | | # define KWTUPLE NULL |
2333 | | #endif // !Py_BUILD_CORE |
2334 | | |
2335 | | static const char * const _keywords[] = {"path", NULL}; |
2336 | | static _PyArg_Parser _parser = { |
2337 | | .keywords = _keywords, |
2338 | | .fname = "_path_isfile", |
2339 | | .kwtuple = KWTUPLE, |
2340 | | }; |
2341 | | #undef KWTUPLE |
2342 | | PyObject *argsbuf[1]; |
2343 | | path_t path = PATH_T_INITIALIZE_P("_path_isfile", "path", 0, 0, 1, 1); |
2344 | | int _return_value; |
2345 | | |
2346 | | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
2347 | | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
2348 | | if (!args) { |
2349 | | goto exit; |
2350 | | } |
2351 | | if (!path_converter(args[0], &path)) { |
2352 | | goto exit; |
2353 | | } |
2354 | | _return_value = os__path_isfile_impl(module, &path); |
2355 | | if ((_return_value == -1) && PyErr_Occurred()) { |
2356 | | goto exit; |
2357 | | } |
2358 | | return_value = PyBool_FromLong((long)_return_value); |
2359 | | |
2360 | | exit: |
2361 | | /* Cleanup for path */ |
2362 | | path_cleanup(&path); |
2363 | | |
2364 | | return return_value; |
2365 | | } |
2366 | | |
2367 | | #endif /* defined(MS_WINDOWS) */ |
2368 | | |
2369 | | #if defined(MS_WINDOWS) |
2370 | | |
2371 | | PyDoc_STRVAR(os__path_islink__doc__, |
2372 | | "_path_islink($module, /, path)\n" |
2373 | | "--\n" |
2374 | | "\n" |
2375 | | "Test whether a path is a symbolic link"); |
2376 | | |
2377 | | #define OS__PATH_ISLINK_METHODDEF \ |
2378 | | {"_path_islink", _PyCFunction_CAST(os__path_islink), METH_FASTCALL|METH_KEYWORDS, os__path_islink__doc__}, |
2379 | | |
2380 | | static int |
2381 | | os__path_islink_impl(PyObject *module, path_t *path); |
2382 | | |
2383 | | static PyObject * |
2384 | | os__path_islink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
2385 | | { |
2386 | | PyObject *return_value = NULL; |
2387 | | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
2388 | | |
2389 | | #define NUM_KEYWORDS 1 |
2390 | | static struct { |
2391 | | PyGC_Head _this_is_not_used; |
2392 | | PyObject_VAR_HEAD |
2393 | | Py_hash_t ob_hash; |
2394 | | PyObject *ob_item[NUM_KEYWORDS]; |
2395 | | } _kwtuple = { |
2396 | | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
2397 | | .ob_hash = -1, |
2398 | | .ob_item = { &_Py_ID(path), }, |
2399 | | }; |
2400 | | #undef NUM_KEYWORDS |
2401 | | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
2402 | | |
2403 | | #else // !Py_BUILD_CORE |
2404 | | # define KWTUPLE NULL |
2405 | | #endif // !Py_BUILD_CORE |
2406 | | |
2407 | | static const char * const _keywords[] = {"path", NULL}; |
2408 | | static _PyArg_Parser _parser = { |
2409 | | .keywords = _keywords, |
2410 | | .fname = "_path_islink", |
2411 | | .kwtuple = KWTUPLE, |
2412 | | }; |
2413 | | #undef KWTUPLE |
2414 | | PyObject *argsbuf[1]; |
2415 | | path_t path = PATH_T_INITIALIZE_P("_path_islink", "path", 0, 0, 1, 1); |
2416 | | int _return_value; |
2417 | | |
2418 | | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
2419 | | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
2420 | | if (!args) { |
2421 | | goto exit; |
2422 | | } |
2423 | | if (!path_converter(args[0], &path)) { |
2424 | | goto exit; |
2425 | | } |
2426 | | _return_value = os__path_islink_impl(module, &path); |
2427 | | if ((_return_value == -1) && PyErr_Occurred()) { |
2428 | | goto exit; |
2429 | | } |
2430 | | return_value = PyBool_FromLong((long)_return_value); |
2431 | | |
2432 | | exit: |
2433 | | /* Cleanup for path */ |
2434 | | path_cleanup(&path); |
2435 | | |
2436 | | return return_value; |
2437 | | } |
2438 | | |
2439 | | #endif /* defined(MS_WINDOWS) */ |
2440 | | |
2441 | | #if defined(MS_WINDOWS) |
2442 | | |
2443 | | PyDoc_STRVAR(os__path_isjunction__doc__, |
2444 | | "_path_isjunction($module, /, path)\n" |
2445 | | "--\n" |
2446 | | "\n" |
2447 | | "Test whether a path is a junction"); |
2448 | | |
2449 | | #define OS__PATH_ISJUNCTION_METHODDEF \ |
2450 | | {"_path_isjunction", _PyCFunction_CAST(os__path_isjunction), METH_FASTCALL|METH_KEYWORDS, os__path_isjunction__doc__}, |
2451 | | |
2452 | | static int |
2453 | | os__path_isjunction_impl(PyObject *module, path_t *path); |
2454 | | |
2455 | | static PyObject * |
2456 | | os__path_isjunction(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
2457 | | { |
2458 | | PyObject *return_value = NULL; |
2459 | | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
2460 | | |
2461 | | #define NUM_KEYWORDS 1 |
2462 | | static struct { |
2463 | | PyGC_Head _this_is_not_used; |
2464 | | PyObject_VAR_HEAD |
2465 | | Py_hash_t ob_hash; |
2466 | | PyObject *ob_item[NUM_KEYWORDS]; |
2467 | | } _kwtuple = { |
2468 | | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
2469 | | .ob_hash = -1, |
2470 | | .ob_item = { &_Py_ID(path), }, |
2471 | | }; |
2472 | | #undef NUM_KEYWORDS |
2473 | | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
2474 | | |
2475 | | #else // !Py_BUILD_CORE |
2476 | | # define KWTUPLE NULL |
2477 | | #endif // !Py_BUILD_CORE |
2478 | | |
2479 | | static const char * const _keywords[] = {"path", NULL}; |
2480 | | static _PyArg_Parser _parser = { |
2481 | | .keywords = _keywords, |
2482 | | .fname = "_path_isjunction", |
2483 | | .kwtuple = KWTUPLE, |
2484 | | }; |
2485 | | #undef KWTUPLE |
2486 | | PyObject *argsbuf[1]; |
2487 | | path_t path = PATH_T_INITIALIZE_P("_path_isjunction", "path", 0, 0, 1, 1); |
2488 | | int _return_value; |
2489 | | |
2490 | | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
2491 | | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
2492 | | if (!args) { |
2493 | | goto exit; |
2494 | | } |
2495 | | if (!path_converter(args[0], &path)) { |
2496 | | goto exit; |
2497 | | } |
2498 | | _return_value = os__path_isjunction_impl(module, &path); |
2499 | | if ((_return_value == -1) && PyErr_Occurred()) { |
2500 | | goto exit; |
2501 | | } |
2502 | | return_value = PyBool_FromLong((long)_return_value); |
2503 | | |
2504 | | exit: |
2505 | | /* Cleanup for path */ |
2506 | | path_cleanup(&path); |
2507 | | |
2508 | | return return_value; |
2509 | | } |
2510 | | |
2511 | | #endif /* defined(MS_WINDOWS) */ |
2512 | | |
2513 | | PyDoc_STRVAR(os__path_splitroot_ex__doc__, |
2514 | | "_path_splitroot_ex($module, /, p)\n" |
2515 | | "--\n" |
2516 | | "\n" |
2517 | | "Split a pathname into drive, root and tail.\n" |
2518 | | "\n" |
2519 | | "The tail contains anything after the root."); |
2520 | | |
2521 | | #define OS__PATH_SPLITROOT_EX_METHODDEF \ |
2522 | | {"_path_splitroot_ex", _PyCFunction_CAST(os__path_splitroot_ex), METH_FASTCALL|METH_KEYWORDS, os__path_splitroot_ex__doc__}, |
2523 | | |
2524 | | static PyObject * |
2525 | | os__path_splitroot_ex_impl(PyObject *module, path_t *path); |
2526 | | |
2527 | | static PyObject * |
2528 | | os__path_splitroot_ex(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
2529 | 0 | { |
2530 | 0 | PyObject *return_value = NULL; |
2531 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
2532 | |
|
2533 | 0 | #define NUM_KEYWORDS 1 |
2534 | 0 | static struct { |
2535 | 0 | PyGC_Head _this_is_not_used; |
2536 | 0 | PyObject_VAR_HEAD |
2537 | 0 | Py_hash_t ob_hash; |
2538 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
2539 | 0 | } _kwtuple = { |
2540 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
2541 | 0 | .ob_hash = -1, |
2542 | 0 | .ob_item = { _Py_LATIN1_CHR('p'), }, |
2543 | 0 | }; |
2544 | 0 | #undef NUM_KEYWORDS |
2545 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
2546 | |
|
2547 | | #else // !Py_BUILD_CORE |
2548 | | # define KWTUPLE NULL |
2549 | | #endif // !Py_BUILD_CORE |
2550 | |
|
2551 | 0 | static const char * const _keywords[] = {"p", NULL}; |
2552 | 0 | static _PyArg_Parser _parser = { |
2553 | 0 | .keywords = _keywords, |
2554 | 0 | .fname = "_path_splitroot_ex", |
2555 | 0 | .kwtuple = KWTUPLE, |
2556 | 0 | }; |
2557 | 0 | #undef KWTUPLE |
2558 | 0 | PyObject *argsbuf[1]; |
2559 | 0 | path_t path = PATH_T_INITIALIZE("_path_splitroot_ex", "path", 0, 1, 1, 0, 0); |
2560 | |
|
2561 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
2562 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
2563 | 0 | if (!args) { |
2564 | 0 | goto exit; |
2565 | 0 | } |
2566 | 0 | if (!path_converter(args[0], &path)) { |
2567 | 0 | goto exit; |
2568 | 0 | } |
2569 | 0 | return_value = os__path_splitroot_ex_impl(module, &path); |
2570 | |
|
2571 | 0 | exit: |
2572 | | /* Cleanup for path */ |
2573 | 0 | path_cleanup(&path); |
2574 | |
|
2575 | 0 | return return_value; |
2576 | 0 | } |
2577 | | |
2578 | | PyDoc_STRVAR(os__path_normpath__doc__, |
2579 | | "_path_normpath($module, /, path)\n" |
2580 | | "--\n" |
2581 | | "\n" |
2582 | | "Normalize path, eliminating double slashes, etc."); |
2583 | | |
2584 | | #define OS__PATH_NORMPATH_METHODDEF \ |
2585 | | {"_path_normpath", _PyCFunction_CAST(os__path_normpath), METH_FASTCALL|METH_KEYWORDS, os__path_normpath__doc__}, |
2586 | | |
2587 | | static PyObject * |
2588 | | os__path_normpath_impl(PyObject *module, path_t *path); |
2589 | | |
2590 | | static PyObject * |
2591 | | os__path_normpath(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
2592 | 80 | { |
2593 | 80 | PyObject *return_value = NULL; |
2594 | 80 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
2595 | | |
2596 | 80 | #define NUM_KEYWORDS 1 |
2597 | 80 | static struct { |
2598 | 80 | PyGC_Head _this_is_not_used; |
2599 | 80 | PyObject_VAR_HEAD |
2600 | 80 | Py_hash_t ob_hash; |
2601 | 80 | PyObject *ob_item[NUM_KEYWORDS]; |
2602 | 80 | } _kwtuple = { |
2603 | 80 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
2604 | 80 | .ob_hash = -1, |
2605 | 80 | .ob_item = { &_Py_ID(path), }, |
2606 | 80 | }; |
2607 | 80 | #undef NUM_KEYWORDS |
2608 | 80 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
2609 | | |
2610 | | #else // !Py_BUILD_CORE |
2611 | | # define KWTUPLE NULL |
2612 | | #endif // !Py_BUILD_CORE |
2613 | | |
2614 | 80 | static const char * const _keywords[] = {"path", NULL}; |
2615 | 80 | static _PyArg_Parser _parser = { |
2616 | 80 | .keywords = _keywords, |
2617 | 80 | .fname = "_path_normpath", |
2618 | 80 | .kwtuple = KWTUPLE, |
2619 | 80 | }; |
2620 | 80 | #undef KWTUPLE |
2621 | 80 | PyObject *argsbuf[1]; |
2622 | 80 | path_t path = PATH_T_INITIALIZE("_path_normpath", "path", 0, 1, 1, 0, 0); |
2623 | | |
2624 | 80 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
2625 | 80 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
2626 | 80 | if (!args) { |
2627 | 0 | goto exit; |
2628 | 0 | } |
2629 | 80 | if (!path_converter(args[0], &path)) { |
2630 | 0 | goto exit; |
2631 | 0 | } |
2632 | 80 | return_value = os__path_normpath_impl(module, &path); |
2633 | | |
2634 | 80 | exit: |
2635 | | /* Cleanup for path */ |
2636 | 80 | path_cleanup(&path); |
2637 | | |
2638 | 80 | return return_value; |
2639 | 80 | } |
2640 | | |
2641 | | PyDoc_STRVAR(os_mkdir__doc__, |
2642 | | "mkdir($module, /, path, mode=511, *, dir_fd=None)\n" |
2643 | | "--\n" |
2644 | | "\n" |
2645 | | "Create a directory.\n" |
2646 | | "\n" |
2647 | | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
2648 | | " and path should be relative; path will then be relative to that directory.\n" |
2649 | | "dir_fd may not be implemented on your platform.\n" |
2650 | | " If it is unavailable, using it will raise a NotImplementedError.\n" |
2651 | | "\n" |
2652 | | "The mode argument is ignored on Windows. Where it is used, the current umask\n" |
2653 | | "value is first masked out."); |
2654 | | |
2655 | | #define OS_MKDIR_METHODDEF \ |
2656 | | {"mkdir", _PyCFunction_CAST(os_mkdir), METH_FASTCALL|METH_KEYWORDS, os_mkdir__doc__}, |
2657 | | |
2658 | | static PyObject * |
2659 | | os_mkdir_impl(PyObject *module, path_t *path, int mode, int dir_fd); |
2660 | | |
2661 | | static PyObject * |
2662 | | os_mkdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
2663 | 0 | { |
2664 | 0 | PyObject *return_value = NULL; |
2665 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
2666 | |
|
2667 | 0 | #define NUM_KEYWORDS 3 |
2668 | 0 | static struct { |
2669 | 0 | PyGC_Head _this_is_not_used; |
2670 | 0 | PyObject_VAR_HEAD |
2671 | 0 | Py_hash_t ob_hash; |
2672 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
2673 | 0 | } _kwtuple = { |
2674 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
2675 | 0 | .ob_hash = -1, |
2676 | 0 | .ob_item = { &_Py_ID(path), &_Py_ID(mode), &_Py_ID(dir_fd), }, |
2677 | 0 | }; |
2678 | 0 | #undef NUM_KEYWORDS |
2679 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
2680 | |
|
2681 | | #else // !Py_BUILD_CORE |
2682 | | # define KWTUPLE NULL |
2683 | | #endif // !Py_BUILD_CORE |
2684 | |
|
2685 | 0 | static const char * const _keywords[] = {"path", "mode", "dir_fd", NULL}; |
2686 | 0 | static _PyArg_Parser _parser = { |
2687 | 0 | .keywords = _keywords, |
2688 | 0 | .fname = "mkdir", |
2689 | 0 | .kwtuple = KWTUPLE, |
2690 | 0 | }; |
2691 | 0 | #undef KWTUPLE |
2692 | 0 | PyObject *argsbuf[3]; |
2693 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
2694 | 0 | path_t path = PATH_T_INITIALIZE_P("mkdir", "path", 0, 0, 0, 0); |
2695 | 0 | int mode = 511; |
2696 | 0 | int dir_fd = DEFAULT_DIR_FD; |
2697 | |
|
2698 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
2699 | 0 | /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
2700 | 0 | if (!args) { |
2701 | 0 | goto exit; |
2702 | 0 | } |
2703 | 0 | if (!path_converter(args[0], &path)) { |
2704 | 0 | goto exit; |
2705 | 0 | } |
2706 | 0 | if (!noptargs) { |
2707 | 0 | goto skip_optional_pos; |
2708 | 0 | } |
2709 | 0 | if (args[1]) { |
2710 | 0 | mode = PyLong_AsInt(args[1]); |
2711 | 0 | if (mode == -1 && PyErr_Occurred()) { |
2712 | 0 | goto exit; |
2713 | 0 | } |
2714 | 0 | if (!--noptargs) { |
2715 | 0 | goto skip_optional_pos; |
2716 | 0 | } |
2717 | 0 | } |
2718 | 0 | skip_optional_pos: |
2719 | 0 | if (!noptargs) { |
2720 | 0 | goto skip_optional_kwonly; |
2721 | 0 | } |
2722 | 0 | if (!MKDIRAT_DIR_FD_CONVERTER(args[2], &dir_fd)) { |
2723 | 0 | goto exit; |
2724 | 0 | } |
2725 | 0 | skip_optional_kwonly: |
2726 | 0 | return_value = os_mkdir_impl(module, &path, mode, dir_fd); |
2727 | |
|
2728 | 0 | exit: |
2729 | | /* Cleanup for path */ |
2730 | 0 | path_cleanup(&path); |
2731 | |
|
2732 | 0 | return return_value; |
2733 | 0 | } |
2734 | | |
2735 | | #if defined(HAVE_NICE) |
2736 | | |
2737 | | PyDoc_STRVAR(os_nice__doc__, |
2738 | | "nice($module, increment, /)\n" |
2739 | | "--\n" |
2740 | | "\n" |
2741 | | "Add increment to the priority of process and return the new priority."); |
2742 | | |
2743 | | #define OS_NICE_METHODDEF \ |
2744 | | {"nice", (PyCFunction)os_nice, METH_O, os_nice__doc__}, |
2745 | | |
2746 | | static PyObject * |
2747 | | os_nice_impl(PyObject *module, int increment); |
2748 | | |
2749 | | static PyObject * |
2750 | | os_nice(PyObject *module, PyObject *arg) |
2751 | 0 | { |
2752 | 0 | PyObject *return_value = NULL; |
2753 | 0 | int increment; |
2754 | |
|
2755 | 0 | increment = PyLong_AsInt(arg); |
2756 | 0 | if (increment == -1 && PyErr_Occurred()) { |
2757 | 0 | goto exit; |
2758 | 0 | } |
2759 | 0 | return_value = os_nice_impl(module, increment); |
2760 | |
|
2761 | 0 | exit: |
2762 | 0 | return return_value; |
2763 | 0 | } |
2764 | | |
2765 | | #endif /* defined(HAVE_NICE) */ |
2766 | | |
2767 | | #if defined(HAVE_GETPRIORITY) |
2768 | | |
2769 | | PyDoc_STRVAR(os_getpriority__doc__, |
2770 | | "getpriority($module, /, which, who)\n" |
2771 | | "--\n" |
2772 | | "\n" |
2773 | | "Return program scheduling priority."); |
2774 | | |
2775 | | #define OS_GETPRIORITY_METHODDEF \ |
2776 | | {"getpriority", _PyCFunction_CAST(os_getpriority), METH_FASTCALL|METH_KEYWORDS, os_getpriority__doc__}, |
2777 | | |
2778 | | static PyObject * |
2779 | | os_getpriority_impl(PyObject *module, int which, int who); |
2780 | | |
2781 | | static PyObject * |
2782 | | os_getpriority(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
2783 | 0 | { |
2784 | 0 | PyObject *return_value = NULL; |
2785 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
2786 | |
|
2787 | 0 | #define NUM_KEYWORDS 2 |
2788 | 0 | static struct { |
2789 | 0 | PyGC_Head _this_is_not_used; |
2790 | 0 | PyObject_VAR_HEAD |
2791 | 0 | Py_hash_t ob_hash; |
2792 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
2793 | 0 | } _kwtuple = { |
2794 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
2795 | 0 | .ob_hash = -1, |
2796 | 0 | .ob_item = { &_Py_ID(which), &_Py_ID(who), }, |
2797 | 0 | }; |
2798 | 0 | #undef NUM_KEYWORDS |
2799 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
2800 | |
|
2801 | | #else // !Py_BUILD_CORE |
2802 | | # define KWTUPLE NULL |
2803 | | #endif // !Py_BUILD_CORE |
2804 | |
|
2805 | 0 | static const char * const _keywords[] = {"which", "who", NULL}; |
2806 | 0 | static _PyArg_Parser _parser = { |
2807 | 0 | .keywords = _keywords, |
2808 | 0 | .fname = "getpriority", |
2809 | 0 | .kwtuple = KWTUPLE, |
2810 | 0 | }; |
2811 | 0 | #undef KWTUPLE |
2812 | 0 | PyObject *argsbuf[2]; |
2813 | 0 | int which; |
2814 | 0 | int who; |
2815 | |
|
2816 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
2817 | 0 | /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
2818 | 0 | if (!args) { |
2819 | 0 | goto exit; |
2820 | 0 | } |
2821 | 0 | which = PyLong_AsInt(args[0]); |
2822 | 0 | if (which == -1 && PyErr_Occurred()) { |
2823 | 0 | goto exit; |
2824 | 0 | } |
2825 | 0 | who = PyLong_AsInt(args[1]); |
2826 | 0 | if (who == -1 && PyErr_Occurred()) { |
2827 | 0 | goto exit; |
2828 | 0 | } |
2829 | 0 | return_value = os_getpriority_impl(module, which, who); |
2830 | |
|
2831 | 0 | exit: |
2832 | 0 | return return_value; |
2833 | 0 | } |
2834 | | |
2835 | | #endif /* defined(HAVE_GETPRIORITY) */ |
2836 | | |
2837 | | #if defined(HAVE_SETPRIORITY) |
2838 | | |
2839 | | PyDoc_STRVAR(os_setpriority__doc__, |
2840 | | "setpriority($module, /, which, who, priority)\n" |
2841 | | "--\n" |
2842 | | "\n" |
2843 | | "Set program scheduling priority."); |
2844 | | |
2845 | | #define OS_SETPRIORITY_METHODDEF \ |
2846 | | {"setpriority", _PyCFunction_CAST(os_setpriority), METH_FASTCALL|METH_KEYWORDS, os_setpriority__doc__}, |
2847 | | |
2848 | | static PyObject * |
2849 | | os_setpriority_impl(PyObject *module, int which, int who, int priority); |
2850 | | |
2851 | | static PyObject * |
2852 | | os_setpriority(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
2853 | 0 | { |
2854 | 0 | PyObject *return_value = NULL; |
2855 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
2856 | |
|
2857 | 0 | #define NUM_KEYWORDS 3 |
2858 | 0 | static struct { |
2859 | 0 | PyGC_Head _this_is_not_used; |
2860 | 0 | PyObject_VAR_HEAD |
2861 | 0 | Py_hash_t ob_hash; |
2862 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
2863 | 0 | } _kwtuple = { |
2864 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
2865 | 0 | .ob_hash = -1, |
2866 | 0 | .ob_item = { &_Py_ID(which), &_Py_ID(who), &_Py_ID(priority), }, |
2867 | 0 | }; |
2868 | 0 | #undef NUM_KEYWORDS |
2869 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
2870 | |
|
2871 | | #else // !Py_BUILD_CORE |
2872 | | # define KWTUPLE NULL |
2873 | | #endif // !Py_BUILD_CORE |
2874 | |
|
2875 | 0 | static const char * const _keywords[] = {"which", "who", "priority", NULL}; |
2876 | 0 | static _PyArg_Parser _parser = { |
2877 | 0 | .keywords = _keywords, |
2878 | 0 | .fname = "setpriority", |
2879 | 0 | .kwtuple = KWTUPLE, |
2880 | 0 | }; |
2881 | 0 | #undef KWTUPLE |
2882 | 0 | PyObject *argsbuf[3]; |
2883 | 0 | int which; |
2884 | 0 | int who; |
2885 | 0 | int priority; |
2886 | |
|
2887 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
2888 | 0 | /*minpos*/ 3, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
2889 | 0 | if (!args) { |
2890 | 0 | goto exit; |
2891 | 0 | } |
2892 | 0 | which = PyLong_AsInt(args[0]); |
2893 | 0 | if (which == -1 && PyErr_Occurred()) { |
2894 | 0 | goto exit; |
2895 | 0 | } |
2896 | 0 | who = PyLong_AsInt(args[1]); |
2897 | 0 | if (who == -1 && PyErr_Occurred()) { |
2898 | 0 | goto exit; |
2899 | 0 | } |
2900 | 0 | priority = PyLong_AsInt(args[2]); |
2901 | 0 | if (priority == -1 && PyErr_Occurred()) { |
2902 | 0 | goto exit; |
2903 | 0 | } |
2904 | 0 | return_value = os_setpriority_impl(module, which, who, priority); |
2905 | |
|
2906 | 0 | exit: |
2907 | 0 | return return_value; |
2908 | 0 | } |
2909 | | |
2910 | | #endif /* defined(HAVE_SETPRIORITY) */ |
2911 | | |
2912 | | PyDoc_STRVAR(os_rename__doc__, |
2913 | | "rename($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None)\n" |
2914 | | "--\n" |
2915 | | "\n" |
2916 | | "Rename a file or directory.\n" |
2917 | | "\n" |
2918 | | "If either src_dir_fd or dst_dir_fd is not None, it should be a file\n" |
2919 | | " descriptor open to a directory, and the respective path string (src or dst)\n" |
2920 | | " should be relative; the path will then be relative to that directory.\n" |
2921 | | "src_dir_fd and dst_dir_fd, may not be implemented on your platform.\n" |
2922 | | " If they are unavailable, using them will raise a NotImplementedError."); |
2923 | | |
2924 | | #define OS_RENAME_METHODDEF \ |
2925 | | {"rename", _PyCFunction_CAST(os_rename), METH_FASTCALL|METH_KEYWORDS, os_rename__doc__}, |
2926 | | |
2927 | | static PyObject * |
2928 | | os_rename_impl(PyObject *module, path_t *src, path_t *dst, int src_dir_fd, |
2929 | | int dst_dir_fd); |
2930 | | |
2931 | | static PyObject * |
2932 | | os_rename(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
2933 | 0 | { |
2934 | 0 | PyObject *return_value = NULL; |
2935 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
2936 | |
|
2937 | 0 | #define NUM_KEYWORDS 4 |
2938 | 0 | static struct { |
2939 | 0 | PyGC_Head _this_is_not_used; |
2940 | 0 | PyObject_VAR_HEAD |
2941 | 0 | Py_hash_t ob_hash; |
2942 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
2943 | 0 | } _kwtuple = { |
2944 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
2945 | 0 | .ob_hash = -1, |
2946 | 0 | .ob_item = { &_Py_ID(src), &_Py_ID(dst), &_Py_ID(src_dir_fd), &_Py_ID(dst_dir_fd), }, |
2947 | 0 | }; |
2948 | 0 | #undef NUM_KEYWORDS |
2949 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
2950 | |
|
2951 | | #else // !Py_BUILD_CORE |
2952 | | # define KWTUPLE NULL |
2953 | | #endif // !Py_BUILD_CORE |
2954 | |
|
2955 | 0 | static const char * const _keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", NULL}; |
2956 | 0 | static _PyArg_Parser _parser = { |
2957 | 0 | .keywords = _keywords, |
2958 | 0 | .fname = "rename", |
2959 | 0 | .kwtuple = KWTUPLE, |
2960 | 0 | }; |
2961 | 0 | #undef KWTUPLE |
2962 | 0 | PyObject *argsbuf[4]; |
2963 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2; |
2964 | 0 | path_t src = PATH_T_INITIALIZE_P("rename", "src", 0, 0, 0, 0); |
2965 | 0 | path_t dst = PATH_T_INITIALIZE_P("rename", "dst", 0, 0, 0, 0); |
2966 | 0 | int src_dir_fd = DEFAULT_DIR_FD; |
2967 | 0 | int dst_dir_fd = DEFAULT_DIR_FD; |
2968 | |
|
2969 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
2970 | 0 | /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
2971 | 0 | if (!args) { |
2972 | 0 | goto exit; |
2973 | 0 | } |
2974 | 0 | if (!path_converter(args[0], &src)) { |
2975 | 0 | goto exit; |
2976 | 0 | } |
2977 | 0 | if (!path_converter(args[1], &dst)) { |
2978 | 0 | goto exit; |
2979 | 0 | } |
2980 | 0 | if (!noptargs) { |
2981 | 0 | goto skip_optional_kwonly; |
2982 | 0 | } |
2983 | 0 | if (args[2]) { |
2984 | 0 | if (!dir_fd_converter(args[2], &src_dir_fd)) { |
2985 | 0 | goto exit; |
2986 | 0 | } |
2987 | 0 | if (!--noptargs) { |
2988 | 0 | goto skip_optional_kwonly; |
2989 | 0 | } |
2990 | 0 | } |
2991 | 0 | if (!dir_fd_converter(args[3], &dst_dir_fd)) { |
2992 | 0 | goto exit; |
2993 | 0 | } |
2994 | 0 | skip_optional_kwonly: |
2995 | 0 | return_value = os_rename_impl(module, &src, &dst, src_dir_fd, dst_dir_fd); |
2996 | |
|
2997 | 0 | exit: |
2998 | | /* Cleanup for src */ |
2999 | 0 | path_cleanup(&src); |
3000 | | /* Cleanup for dst */ |
3001 | 0 | path_cleanup(&dst); |
3002 | |
|
3003 | 0 | return return_value; |
3004 | 0 | } |
3005 | | |
3006 | | PyDoc_STRVAR(os_replace__doc__, |
3007 | | "replace($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None)\n" |
3008 | | "--\n" |
3009 | | "\n" |
3010 | | "Rename a file or directory, overwriting the destination.\n" |
3011 | | "\n" |
3012 | | "If either src_dir_fd or dst_dir_fd is not None, it should be a file\n" |
3013 | | " descriptor open to a directory, and the respective path string (src or dst)\n" |
3014 | | " should be relative; the path will then be relative to that directory.\n" |
3015 | | "src_dir_fd and dst_dir_fd, may not be implemented on your platform.\n" |
3016 | | " If they are unavailable, using them will raise a NotImplementedError."); |
3017 | | |
3018 | | #define OS_REPLACE_METHODDEF \ |
3019 | | {"replace", _PyCFunction_CAST(os_replace), METH_FASTCALL|METH_KEYWORDS, os_replace__doc__}, |
3020 | | |
3021 | | static PyObject * |
3022 | | os_replace_impl(PyObject *module, path_t *src, path_t *dst, int src_dir_fd, |
3023 | | int dst_dir_fd); |
3024 | | |
3025 | | static PyObject * |
3026 | | os_replace(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
3027 | 216 | { |
3028 | 216 | PyObject *return_value = NULL; |
3029 | 216 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
3030 | | |
3031 | 216 | #define NUM_KEYWORDS 4 |
3032 | 216 | static struct { |
3033 | 216 | PyGC_Head _this_is_not_used; |
3034 | 216 | PyObject_VAR_HEAD |
3035 | 216 | Py_hash_t ob_hash; |
3036 | 216 | PyObject *ob_item[NUM_KEYWORDS]; |
3037 | 216 | } _kwtuple = { |
3038 | 216 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
3039 | 216 | .ob_hash = -1, |
3040 | 216 | .ob_item = { &_Py_ID(src), &_Py_ID(dst), &_Py_ID(src_dir_fd), &_Py_ID(dst_dir_fd), }, |
3041 | 216 | }; |
3042 | 216 | #undef NUM_KEYWORDS |
3043 | 216 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
3044 | | |
3045 | | #else // !Py_BUILD_CORE |
3046 | | # define KWTUPLE NULL |
3047 | | #endif // !Py_BUILD_CORE |
3048 | | |
3049 | 216 | static const char * const _keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", NULL}; |
3050 | 216 | static _PyArg_Parser _parser = { |
3051 | 216 | .keywords = _keywords, |
3052 | 216 | .fname = "replace", |
3053 | 216 | .kwtuple = KWTUPLE, |
3054 | 216 | }; |
3055 | 216 | #undef KWTUPLE |
3056 | 216 | PyObject *argsbuf[4]; |
3057 | 216 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2; |
3058 | 216 | path_t src = PATH_T_INITIALIZE_P("replace", "src", 0, 0, 0, 0); |
3059 | 216 | path_t dst = PATH_T_INITIALIZE_P("replace", "dst", 0, 0, 0, 0); |
3060 | 216 | int src_dir_fd = DEFAULT_DIR_FD; |
3061 | 216 | int dst_dir_fd = DEFAULT_DIR_FD; |
3062 | | |
3063 | 216 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
3064 | 216 | /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
3065 | 216 | if (!args) { |
3066 | 0 | goto exit; |
3067 | 0 | } |
3068 | 216 | if (!path_converter(args[0], &src)) { |
3069 | 0 | goto exit; |
3070 | 0 | } |
3071 | 216 | if (!path_converter(args[1], &dst)) { |
3072 | 0 | goto exit; |
3073 | 0 | } |
3074 | 216 | if (!noptargs) { |
3075 | 216 | goto skip_optional_kwonly; |
3076 | 216 | } |
3077 | 0 | if (args[2]) { |
3078 | 0 | if (!dir_fd_converter(args[2], &src_dir_fd)) { |
3079 | 0 | goto exit; |
3080 | 0 | } |
3081 | 0 | if (!--noptargs) { |
3082 | 0 | goto skip_optional_kwonly; |
3083 | 0 | } |
3084 | 0 | } |
3085 | 0 | if (!dir_fd_converter(args[3], &dst_dir_fd)) { |
3086 | 0 | goto exit; |
3087 | 0 | } |
3088 | 216 | skip_optional_kwonly: |
3089 | 216 | return_value = os_replace_impl(module, &src, &dst, src_dir_fd, dst_dir_fd); |
3090 | | |
3091 | 216 | exit: |
3092 | | /* Cleanup for src */ |
3093 | 216 | path_cleanup(&src); |
3094 | | /* Cleanup for dst */ |
3095 | 216 | path_cleanup(&dst); |
3096 | | |
3097 | 216 | return return_value; |
3098 | 216 | } |
3099 | | |
3100 | | PyDoc_STRVAR(os_rmdir__doc__, |
3101 | | "rmdir($module, /, path, *, dir_fd=None)\n" |
3102 | | "--\n" |
3103 | | "\n" |
3104 | | "Remove a directory.\n" |
3105 | | "\n" |
3106 | | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
3107 | | " and path should be relative; path will then be relative to that directory.\n" |
3108 | | "dir_fd may not be implemented on your platform.\n" |
3109 | | " If it is unavailable, using it will raise a NotImplementedError."); |
3110 | | |
3111 | | #define OS_RMDIR_METHODDEF \ |
3112 | | {"rmdir", _PyCFunction_CAST(os_rmdir), METH_FASTCALL|METH_KEYWORDS, os_rmdir__doc__}, |
3113 | | |
3114 | | static PyObject * |
3115 | | os_rmdir_impl(PyObject *module, path_t *path, int dir_fd); |
3116 | | |
3117 | | static PyObject * |
3118 | | os_rmdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
3119 | 0 | { |
3120 | 0 | PyObject *return_value = NULL; |
3121 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
3122 | |
|
3123 | 0 | #define NUM_KEYWORDS 2 |
3124 | 0 | static struct { |
3125 | 0 | PyGC_Head _this_is_not_used; |
3126 | 0 | PyObject_VAR_HEAD |
3127 | 0 | Py_hash_t ob_hash; |
3128 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
3129 | 0 | } _kwtuple = { |
3130 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
3131 | 0 | .ob_hash = -1, |
3132 | 0 | .ob_item = { &_Py_ID(path), &_Py_ID(dir_fd), }, |
3133 | 0 | }; |
3134 | 0 | #undef NUM_KEYWORDS |
3135 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
3136 | |
|
3137 | | #else // !Py_BUILD_CORE |
3138 | | # define KWTUPLE NULL |
3139 | | #endif // !Py_BUILD_CORE |
3140 | |
|
3141 | 0 | static const char * const _keywords[] = {"path", "dir_fd", NULL}; |
3142 | 0 | static _PyArg_Parser _parser = { |
3143 | 0 | .keywords = _keywords, |
3144 | 0 | .fname = "rmdir", |
3145 | 0 | .kwtuple = KWTUPLE, |
3146 | 0 | }; |
3147 | 0 | #undef KWTUPLE |
3148 | 0 | PyObject *argsbuf[2]; |
3149 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
3150 | 0 | path_t path = PATH_T_INITIALIZE_P("rmdir", "path", 0, 0, 0, 0); |
3151 | 0 | int dir_fd = DEFAULT_DIR_FD; |
3152 | |
|
3153 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
3154 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
3155 | 0 | if (!args) { |
3156 | 0 | goto exit; |
3157 | 0 | } |
3158 | 0 | if (!path_converter(args[0], &path)) { |
3159 | 0 | goto exit; |
3160 | 0 | } |
3161 | 0 | if (!noptargs) { |
3162 | 0 | goto skip_optional_kwonly; |
3163 | 0 | } |
3164 | 0 | if (!UNLINKAT_DIR_FD_CONVERTER(args[1], &dir_fd)) { |
3165 | 0 | goto exit; |
3166 | 0 | } |
3167 | 0 | skip_optional_kwonly: |
3168 | 0 | return_value = os_rmdir_impl(module, &path, dir_fd); |
3169 | |
|
3170 | 0 | exit: |
3171 | | /* Cleanup for path */ |
3172 | 0 | path_cleanup(&path); |
3173 | |
|
3174 | 0 | return return_value; |
3175 | 0 | } |
3176 | | |
3177 | | #if defined(HAVE_SYSTEM) && defined(MS_WINDOWS) |
3178 | | |
3179 | | PyDoc_STRVAR(os_system__doc__, |
3180 | | "system($module, /, command)\n" |
3181 | | "--\n" |
3182 | | "\n" |
3183 | | "Execute the command in a subshell."); |
3184 | | |
3185 | | #define OS_SYSTEM_METHODDEF \ |
3186 | | {"system", _PyCFunction_CAST(os_system), METH_FASTCALL|METH_KEYWORDS, os_system__doc__}, |
3187 | | |
3188 | | static long |
3189 | | os_system_impl(PyObject *module, const wchar_t *command); |
3190 | | |
3191 | | static PyObject * |
3192 | | os_system(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
3193 | | { |
3194 | | PyObject *return_value = NULL; |
3195 | | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
3196 | | |
3197 | | #define NUM_KEYWORDS 1 |
3198 | | static struct { |
3199 | | PyGC_Head _this_is_not_used; |
3200 | | PyObject_VAR_HEAD |
3201 | | Py_hash_t ob_hash; |
3202 | | PyObject *ob_item[NUM_KEYWORDS]; |
3203 | | } _kwtuple = { |
3204 | | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
3205 | | .ob_hash = -1, |
3206 | | .ob_item = { &_Py_ID(command), }, |
3207 | | }; |
3208 | | #undef NUM_KEYWORDS |
3209 | | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
3210 | | |
3211 | | #else // !Py_BUILD_CORE |
3212 | | # define KWTUPLE NULL |
3213 | | #endif // !Py_BUILD_CORE |
3214 | | |
3215 | | static const char * const _keywords[] = {"command", NULL}; |
3216 | | static _PyArg_Parser _parser = { |
3217 | | .keywords = _keywords, |
3218 | | .fname = "system", |
3219 | | .kwtuple = KWTUPLE, |
3220 | | }; |
3221 | | #undef KWTUPLE |
3222 | | PyObject *argsbuf[1]; |
3223 | | const wchar_t *command = NULL; |
3224 | | long _return_value; |
3225 | | |
3226 | | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
3227 | | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
3228 | | if (!args) { |
3229 | | goto exit; |
3230 | | } |
3231 | | if (!PyUnicode_Check(args[0])) { |
3232 | | _PyArg_BadArgument("system", "argument 'command'", "str", args[0]); |
3233 | | goto exit; |
3234 | | } |
3235 | | command = PyUnicode_AsWideCharString(args[0], NULL); |
3236 | | if (command == NULL) { |
3237 | | goto exit; |
3238 | | } |
3239 | | _return_value = os_system_impl(module, command); |
3240 | | if ((_return_value == -1) && PyErr_Occurred()) { |
3241 | | goto exit; |
3242 | | } |
3243 | | return_value = PyLong_FromLong(_return_value); |
3244 | | |
3245 | | exit: |
3246 | | /* Cleanup for command */ |
3247 | | PyMem_Free((void *)command); |
3248 | | |
3249 | | return return_value; |
3250 | | } |
3251 | | |
3252 | | #endif /* defined(HAVE_SYSTEM) && defined(MS_WINDOWS) */ |
3253 | | |
3254 | | #if defined(HAVE_SYSTEM) && !defined(MS_WINDOWS) |
3255 | | |
3256 | | PyDoc_STRVAR(os_system__doc__, |
3257 | | "system($module, /, command)\n" |
3258 | | "--\n" |
3259 | | "\n" |
3260 | | "Execute the command in a subshell."); |
3261 | | |
3262 | | #define OS_SYSTEM_METHODDEF \ |
3263 | | {"system", _PyCFunction_CAST(os_system), METH_FASTCALL|METH_KEYWORDS, os_system__doc__}, |
3264 | | |
3265 | | static long |
3266 | | os_system_impl(PyObject *module, PyObject *command); |
3267 | | |
3268 | | static PyObject * |
3269 | | os_system(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
3270 | 0 | { |
3271 | 0 | PyObject *return_value = NULL; |
3272 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
3273 | |
|
3274 | 0 | #define NUM_KEYWORDS 1 |
3275 | 0 | static struct { |
3276 | 0 | PyGC_Head _this_is_not_used; |
3277 | 0 | PyObject_VAR_HEAD |
3278 | 0 | Py_hash_t ob_hash; |
3279 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
3280 | 0 | } _kwtuple = { |
3281 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
3282 | 0 | .ob_hash = -1, |
3283 | 0 | .ob_item = { &_Py_ID(command), }, |
3284 | 0 | }; |
3285 | 0 | #undef NUM_KEYWORDS |
3286 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
3287 | |
|
3288 | | #else // !Py_BUILD_CORE |
3289 | | # define KWTUPLE NULL |
3290 | | #endif // !Py_BUILD_CORE |
3291 | |
|
3292 | 0 | static const char * const _keywords[] = {"command", NULL}; |
3293 | 0 | static _PyArg_Parser _parser = { |
3294 | 0 | .keywords = _keywords, |
3295 | 0 | .fname = "system", |
3296 | 0 | .kwtuple = KWTUPLE, |
3297 | 0 | }; |
3298 | 0 | #undef KWTUPLE |
3299 | 0 | PyObject *argsbuf[1]; |
3300 | 0 | PyObject *command = NULL; |
3301 | 0 | long _return_value; |
3302 | |
|
3303 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
3304 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
3305 | 0 | if (!args) { |
3306 | 0 | goto exit; |
3307 | 0 | } |
3308 | 0 | if (!PyUnicode_FSConverter(args[0], &command)) { |
3309 | 0 | goto exit; |
3310 | 0 | } |
3311 | 0 | _return_value = os_system_impl(module, command); |
3312 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
3313 | 0 | goto exit; |
3314 | 0 | } |
3315 | 0 | return_value = PyLong_FromLong(_return_value); |
3316 | |
|
3317 | 0 | exit: |
3318 | | /* Cleanup for command */ |
3319 | 0 | Py_XDECREF(command); |
3320 | |
|
3321 | 0 | return return_value; |
3322 | 0 | } |
3323 | | |
3324 | | #endif /* defined(HAVE_SYSTEM) && !defined(MS_WINDOWS) */ |
3325 | | |
3326 | | #if defined(HAVE_UMASK) |
3327 | | |
3328 | | PyDoc_STRVAR(os_umask__doc__, |
3329 | | "umask($module, mask, /)\n" |
3330 | | "--\n" |
3331 | | "\n" |
3332 | | "Set the current numeric umask and return the previous umask."); |
3333 | | |
3334 | | #define OS_UMASK_METHODDEF \ |
3335 | | {"umask", (PyCFunction)os_umask, METH_O, os_umask__doc__}, |
3336 | | |
3337 | | static PyObject * |
3338 | | os_umask_impl(PyObject *module, int mask); |
3339 | | |
3340 | | static PyObject * |
3341 | | os_umask(PyObject *module, PyObject *arg) |
3342 | 0 | { |
3343 | 0 | PyObject *return_value = NULL; |
3344 | 0 | int mask; |
3345 | |
|
3346 | 0 | mask = PyLong_AsInt(arg); |
3347 | 0 | if (mask == -1 && PyErr_Occurred()) { |
3348 | 0 | goto exit; |
3349 | 0 | } |
3350 | 0 | return_value = os_umask_impl(module, mask); |
3351 | |
|
3352 | 0 | exit: |
3353 | 0 | return return_value; |
3354 | 0 | } |
3355 | | |
3356 | | #endif /* defined(HAVE_UMASK) */ |
3357 | | |
3358 | | PyDoc_STRVAR(os_unlink__doc__, |
3359 | | "unlink($module, /, path, *, dir_fd=None)\n" |
3360 | | "--\n" |
3361 | | "\n" |
3362 | | "Remove a file (same as remove()).\n" |
3363 | | "\n" |
3364 | | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
3365 | | " and path should be relative; path will then be relative to that directory.\n" |
3366 | | "dir_fd may not be implemented on your platform.\n" |
3367 | | " If it is unavailable, using it will raise a NotImplementedError."); |
3368 | | |
3369 | | #define OS_UNLINK_METHODDEF \ |
3370 | | {"unlink", _PyCFunction_CAST(os_unlink), METH_FASTCALL|METH_KEYWORDS, os_unlink__doc__}, |
3371 | | |
3372 | | static PyObject * |
3373 | | os_unlink_impl(PyObject *module, path_t *path, int dir_fd); |
3374 | | |
3375 | | static PyObject * |
3376 | | os_unlink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
3377 | 0 | { |
3378 | 0 | PyObject *return_value = NULL; |
3379 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
3380 | |
|
3381 | 0 | #define NUM_KEYWORDS 2 |
3382 | 0 | static struct { |
3383 | 0 | PyGC_Head _this_is_not_used; |
3384 | 0 | PyObject_VAR_HEAD |
3385 | 0 | Py_hash_t ob_hash; |
3386 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
3387 | 0 | } _kwtuple = { |
3388 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
3389 | 0 | .ob_hash = -1, |
3390 | 0 | .ob_item = { &_Py_ID(path), &_Py_ID(dir_fd), }, |
3391 | 0 | }; |
3392 | 0 | #undef NUM_KEYWORDS |
3393 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
3394 | |
|
3395 | | #else // !Py_BUILD_CORE |
3396 | | # define KWTUPLE NULL |
3397 | | #endif // !Py_BUILD_CORE |
3398 | |
|
3399 | 0 | static const char * const _keywords[] = {"path", "dir_fd", NULL}; |
3400 | 0 | static _PyArg_Parser _parser = { |
3401 | 0 | .keywords = _keywords, |
3402 | 0 | .fname = "unlink", |
3403 | 0 | .kwtuple = KWTUPLE, |
3404 | 0 | }; |
3405 | 0 | #undef KWTUPLE |
3406 | 0 | PyObject *argsbuf[2]; |
3407 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
3408 | 0 | path_t path = PATH_T_INITIALIZE_P("unlink", "path", 0, 0, 0, 0); |
3409 | 0 | int dir_fd = DEFAULT_DIR_FD; |
3410 | |
|
3411 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
3412 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
3413 | 0 | if (!args) { |
3414 | 0 | goto exit; |
3415 | 0 | } |
3416 | 0 | if (!path_converter(args[0], &path)) { |
3417 | 0 | goto exit; |
3418 | 0 | } |
3419 | 0 | if (!noptargs) { |
3420 | 0 | goto skip_optional_kwonly; |
3421 | 0 | } |
3422 | 0 | if (!UNLINKAT_DIR_FD_CONVERTER(args[1], &dir_fd)) { |
3423 | 0 | goto exit; |
3424 | 0 | } |
3425 | 0 | skip_optional_kwonly: |
3426 | 0 | return_value = os_unlink_impl(module, &path, dir_fd); |
3427 | |
|
3428 | 0 | exit: |
3429 | | /* Cleanup for path */ |
3430 | 0 | path_cleanup(&path); |
3431 | |
|
3432 | 0 | return return_value; |
3433 | 0 | } |
3434 | | |
3435 | | PyDoc_STRVAR(os_remove__doc__, |
3436 | | "remove($module, /, path, *, dir_fd=None)\n" |
3437 | | "--\n" |
3438 | | "\n" |
3439 | | "Remove a file (same as unlink()).\n" |
3440 | | "\n" |
3441 | | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
3442 | | " and path should be relative; path will then be relative to that directory.\n" |
3443 | | "dir_fd may not be implemented on your platform.\n" |
3444 | | " If it is unavailable, using it will raise a NotImplementedError."); |
3445 | | |
3446 | | #define OS_REMOVE_METHODDEF \ |
3447 | | {"remove", _PyCFunction_CAST(os_remove), METH_FASTCALL|METH_KEYWORDS, os_remove__doc__}, |
3448 | | |
3449 | | static PyObject * |
3450 | | os_remove_impl(PyObject *module, path_t *path, int dir_fd); |
3451 | | |
3452 | | static PyObject * |
3453 | | os_remove(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
3454 | 0 | { |
3455 | 0 | PyObject *return_value = NULL; |
3456 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
3457 | |
|
3458 | 0 | #define NUM_KEYWORDS 2 |
3459 | 0 | static struct { |
3460 | 0 | PyGC_Head _this_is_not_used; |
3461 | 0 | PyObject_VAR_HEAD |
3462 | 0 | Py_hash_t ob_hash; |
3463 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
3464 | 0 | } _kwtuple = { |
3465 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
3466 | 0 | .ob_hash = -1, |
3467 | 0 | .ob_item = { &_Py_ID(path), &_Py_ID(dir_fd), }, |
3468 | 0 | }; |
3469 | 0 | #undef NUM_KEYWORDS |
3470 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
3471 | |
|
3472 | | #else // !Py_BUILD_CORE |
3473 | | # define KWTUPLE NULL |
3474 | | #endif // !Py_BUILD_CORE |
3475 | |
|
3476 | 0 | static const char * const _keywords[] = {"path", "dir_fd", NULL}; |
3477 | 0 | static _PyArg_Parser _parser = { |
3478 | 0 | .keywords = _keywords, |
3479 | 0 | .fname = "remove", |
3480 | 0 | .kwtuple = KWTUPLE, |
3481 | 0 | }; |
3482 | 0 | #undef KWTUPLE |
3483 | 0 | PyObject *argsbuf[2]; |
3484 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
3485 | 0 | path_t path = PATH_T_INITIALIZE_P("remove", "path", 0, 0, 0, 0); |
3486 | 0 | int dir_fd = DEFAULT_DIR_FD; |
3487 | |
|
3488 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
3489 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
3490 | 0 | if (!args) { |
3491 | 0 | goto exit; |
3492 | 0 | } |
3493 | 0 | if (!path_converter(args[0], &path)) { |
3494 | 0 | goto exit; |
3495 | 0 | } |
3496 | 0 | if (!noptargs) { |
3497 | 0 | goto skip_optional_kwonly; |
3498 | 0 | } |
3499 | 0 | if (!UNLINKAT_DIR_FD_CONVERTER(args[1], &dir_fd)) { |
3500 | 0 | goto exit; |
3501 | 0 | } |
3502 | 0 | skip_optional_kwonly: |
3503 | 0 | return_value = os_remove_impl(module, &path, dir_fd); |
3504 | |
|
3505 | 0 | exit: |
3506 | | /* Cleanup for path */ |
3507 | 0 | path_cleanup(&path); |
3508 | |
|
3509 | 0 | return return_value; |
3510 | 0 | } |
3511 | | |
3512 | | #if defined(HAVE_UNAME) |
3513 | | |
3514 | | PyDoc_STRVAR(os_uname__doc__, |
3515 | | "uname($module, /)\n" |
3516 | | "--\n" |
3517 | | "\n" |
3518 | | "Return an object identifying the current operating system.\n" |
3519 | | "\n" |
3520 | | "The object behaves like a named tuple with the following fields:\n" |
3521 | | " (sysname, nodename, release, version, machine)"); |
3522 | | |
3523 | | #define OS_UNAME_METHODDEF \ |
3524 | | {"uname", (PyCFunction)os_uname, METH_NOARGS, os_uname__doc__}, |
3525 | | |
3526 | | static PyObject * |
3527 | | os_uname_impl(PyObject *module); |
3528 | | |
3529 | | static PyObject * |
3530 | | os_uname(PyObject *module, PyObject *Py_UNUSED(ignored)) |
3531 | 0 | { |
3532 | 0 | return os_uname_impl(module); |
3533 | 0 | } |
3534 | | |
3535 | | #endif /* defined(HAVE_UNAME) */ |
3536 | | |
3537 | | PyDoc_STRVAR(os_utime__doc__, |
3538 | | "utime($module, /, path, times=None, *, ns=<unrepresentable>,\n" |
3539 | | " dir_fd=None, follow_symlinks=True)\n" |
3540 | | "--\n" |
3541 | | "\n" |
3542 | | "Set the access and modified time of path.\n" |
3543 | | "\n" |
3544 | | "path may always be specified as a string.\n" |
3545 | | "On some platforms, path may also be specified as an open file descriptor.\n" |
3546 | | " If this functionality is unavailable, using it raises an exception.\n" |
3547 | | "\n" |
3548 | | "If times is not None, it must be a tuple (atime, mtime);\n" |
3549 | | " atime and mtime should be expressed as float seconds since the epoch.\n" |
3550 | | "If ns is specified, it must be a tuple (atime_ns, mtime_ns);\n" |
3551 | | " atime_ns and mtime_ns should be expressed as integer nanoseconds\n" |
3552 | | " since the epoch.\n" |
3553 | | "If times is None and ns is unspecified, utime uses the current time.\n" |
3554 | | "Specifying tuples for both times and ns is an error.\n" |
3555 | | "\n" |
3556 | | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
3557 | | " and path should be relative; path will then be relative to that directory.\n" |
3558 | | "If follow_symlinks is False, and the last element of the path is a symbolic\n" |
3559 | | " link, utime will modify the symbolic link itself instead of the file the\n" |
3560 | | " link points to.\n" |
3561 | | "It is an error to use dir_fd or follow_symlinks when specifying path\n" |
3562 | | " as an open file descriptor.\n" |
3563 | | "dir_fd and follow_symlinks may not be available on your platform.\n" |
3564 | | " If they are unavailable, using them will raise a NotImplementedError."); |
3565 | | |
3566 | | #define OS_UTIME_METHODDEF \ |
3567 | | {"utime", _PyCFunction_CAST(os_utime), METH_FASTCALL|METH_KEYWORDS, os_utime__doc__}, |
3568 | | |
3569 | | static PyObject * |
3570 | | os_utime_impl(PyObject *module, path_t *path, PyObject *times, PyObject *ns, |
3571 | | int dir_fd, int follow_symlinks); |
3572 | | |
3573 | | static PyObject * |
3574 | | os_utime(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
3575 | 0 | { |
3576 | 0 | PyObject *return_value = NULL; |
3577 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
3578 | |
|
3579 | 0 | #define NUM_KEYWORDS 5 |
3580 | 0 | static struct { |
3581 | 0 | PyGC_Head _this_is_not_used; |
3582 | 0 | PyObject_VAR_HEAD |
3583 | 0 | Py_hash_t ob_hash; |
3584 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
3585 | 0 | } _kwtuple = { |
3586 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
3587 | 0 | .ob_hash = -1, |
3588 | 0 | .ob_item = { &_Py_ID(path), &_Py_ID(times), &_Py_ID(ns), &_Py_ID(dir_fd), &_Py_ID(follow_symlinks), }, |
3589 | 0 | }; |
3590 | 0 | #undef NUM_KEYWORDS |
3591 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
3592 | |
|
3593 | | #else // !Py_BUILD_CORE |
3594 | | # define KWTUPLE NULL |
3595 | | #endif // !Py_BUILD_CORE |
3596 | |
|
3597 | 0 | static const char * const _keywords[] = {"path", "times", "ns", "dir_fd", "follow_symlinks", NULL}; |
3598 | 0 | static _PyArg_Parser _parser = { |
3599 | 0 | .keywords = _keywords, |
3600 | 0 | .fname = "utime", |
3601 | 0 | .kwtuple = KWTUPLE, |
3602 | 0 | }; |
3603 | 0 | #undef KWTUPLE |
3604 | 0 | PyObject *argsbuf[5]; |
3605 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
3606 | 0 | path_t path = PATH_T_INITIALIZE_P("utime", "path", 0, 0, 0, PATH_UTIME_HAVE_FD); |
3607 | 0 | PyObject *times = Py_None; |
3608 | 0 | PyObject *ns = NULL; |
3609 | 0 | int dir_fd = DEFAULT_DIR_FD; |
3610 | 0 | int follow_symlinks = 1; |
3611 | |
|
3612 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
3613 | 0 | /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
3614 | 0 | if (!args) { |
3615 | 0 | goto exit; |
3616 | 0 | } |
3617 | 0 | if (!path_converter(args[0], &path)) { |
3618 | 0 | goto exit; |
3619 | 0 | } |
3620 | 0 | if (!noptargs) { |
3621 | 0 | goto skip_optional_pos; |
3622 | 0 | } |
3623 | 0 | if (args[1]) { |
3624 | 0 | times = args[1]; |
3625 | 0 | if (!--noptargs) { |
3626 | 0 | goto skip_optional_pos; |
3627 | 0 | } |
3628 | 0 | } |
3629 | 0 | skip_optional_pos: |
3630 | 0 | if (!noptargs) { |
3631 | 0 | goto skip_optional_kwonly; |
3632 | 0 | } |
3633 | 0 | if (args[2]) { |
3634 | 0 | ns = args[2]; |
3635 | 0 | if (!--noptargs) { |
3636 | 0 | goto skip_optional_kwonly; |
3637 | 0 | } |
3638 | 0 | } |
3639 | 0 | if (args[3]) { |
3640 | 0 | if (!FUTIMENSAT_DIR_FD_CONVERTER(args[3], &dir_fd)) { |
3641 | 0 | goto exit; |
3642 | 0 | } |
3643 | 0 | if (!--noptargs) { |
3644 | 0 | goto skip_optional_kwonly; |
3645 | 0 | } |
3646 | 0 | } |
3647 | 0 | follow_symlinks = PyObject_IsTrue(args[4]); |
3648 | 0 | if (follow_symlinks < 0) { |
3649 | 0 | goto exit; |
3650 | 0 | } |
3651 | 0 | skip_optional_kwonly: |
3652 | 0 | return_value = os_utime_impl(module, &path, times, ns, dir_fd, follow_symlinks); |
3653 | |
|
3654 | 0 | exit: |
3655 | | /* Cleanup for path */ |
3656 | 0 | path_cleanup(&path); |
3657 | |
|
3658 | 0 | return return_value; |
3659 | 0 | } |
3660 | | |
3661 | | PyDoc_STRVAR(os__exit__doc__, |
3662 | | "_exit($module, /, status)\n" |
3663 | | "--\n" |
3664 | | "\n" |
3665 | | "Exit to the system with specified status, without normal exit processing."); |
3666 | | |
3667 | | #define OS__EXIT_METHODDEF \ |
3668 | | {"_exit", _PyCFunction_CAST(os__exit), METH_FASTCALL|METH_KEYWORDS, os__exit__doc__}, |
3669 | | |
3670 | | static PyObject * |
3671 | | os__exit_impl(PyObject *module, int status); |
3672 | | |
3673 | | static PyObject * |
3674 | | os__exit(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
3675 | 0 | { |
3676 | 0 | PyObject *return_value = NULL; |
3677 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
3678 | |
|
3679 | 0 | #define NUM_KEYWORDS 1 |
3680 | 0 | static struct { |
3681 | 0 | PyGC_Head _this_is_not_used; |
3682 | 0 | PyObject_VAR_HEAD |
3683 | 0 | Py_hash_t ob_hash; |
3684 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
3685 | 0 | } _kwtuple = { |
3686 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
3687 | 0 | .ob_hash = -1, |
3688 | 0 | .ob_item = { &_Py_ID(status), }, |
3689 | 0 | }; |
3690 | 0 | #undef NUM_KEYWORDS |
3691 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
3692 | |
|
3693 | | #else // !Py_BUILD_CORE |
3694 | | # define KWTUPLE NULL |
3695 | | #endif // !Py_BUILD_CORE |
3696 | |
|
3697 | 0 | static const char * const _keywords[] = {"status", NULL}; |
3698 | 0 | static _PyArg_Parser _parser = { |
3699 | 0 | .keywords = _keywords, |
3700 | 0 | .fname = "_exit", |
3701 | 0 | .kwtuple = KWTUPLE, |
3702 | 0 | }; |
3703 | 0 | #undef KWTUPLE |
3704 | 0 | PyObject *argsbuf[1]; |
3705 | 0 | int status; |
3706 | |
|
3707 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
3708 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
3709 | 0 | if (!args) { |
3710 | 0 | goto exit; |
3711 | 0 | } |
3712 | 0 | status = PyLong_AsInt(args[0]); |
3713 | 0 | if (status == -1 && PyErr_Occurred()) { |
3714 | 0 | goto exit; |
3715 | 0 | } |
3716 | 0 | return_value = os__exit_impl(module, status); |
3717 | |
|
3718 | 0 | exit: |
3719 | 0 | return return_value; |
3720 | 0 | } |
3721 | | |
3722 | | #if defined(HAVE_EXECV) |
3723 | | |
3724 | | PyDoc_STRVAR(os_execv__doc__, |
3725 | | "execv($module, path, argv, /)\n" |
3726 | | "--\n" |
3727 | | "\n" |
3728 | | "Execute an executable path with arguments, replacing current process.\n" |
3729 | | "\n" |
3730 | | " path\n" |
3731 | | " Path of executable file.\n" |
3732 | | " argv\n" |
3733 | | " Tuple or list of strings."); |
3734 | | |
3735 | | #define OS_EXECV_METHODDEF \ |
3736 | | {"execv", _PyCFunction_CAST(os_execv), METH_FASTCALL, os_execv__doc__}, |
3737 | | |
3738 | | static PyObject * |
3739 | | os_execv_impl(PyObject *module, path_t *path, PyObject *argv); |
3740 | | |
3741 | | static PyObject * |
3742 | | os_execv(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
3743 | 0 | { |
3744 | 0 | PyObject *return_value = NULL; |
3745 | 0 | path_t path = PATH_T_INITIALIZE_P("execv", "path", 0, 0, 0, 0); |
3746 | 0 | PyObject *argv; |
3747 | |
|
3748 | 0 | if (!_PyArg_CheckPositional("execv", nargs, 2, 2)) { |
3749 | 0 | goto exit; |
3750 | 0 | } |
3751 | 0 | if (!path_converter(args[0], &path)) { |
3752 | 0 | goto exit; |
3753 | 0 | } |
3754 | 0 | argv = args[1]; |
3755 | 0 | return_value = os_execv_impl(module, &path, argv); |
3756 | |
|
3757 | 0 | exit: |
3758 | | /* Cleanup for path */ |
3759 | 0 | path_cleanup(&path); |
3760 | |
|
3761 | 0 | return return_value; |
3762 | 0 | } |
3763 | | |
3764 | | #endif /* defined(HAVE_EXECV) */ |
3765 | | |
3766 | | #if defined(HAVE_EXECV) |
3767 | | |
3768 | | PyDoc_STRVAR(os_execve__doc__, |
3769 | | "execve($module, /, path, argv, env)\n" |
3770 | | "--\n" |
3771 | | "\n" |
3772 | | "Execute an executable path with arguments, replacing current process.\n" |
3773 | | "\n" |
3774 | | " path\n" |
3775 | | " Path of executable file.\n" |
3776 | | " argv\n" |
3777 | | " Tuple or list of strings.\n" |
3778 | | " env\n" |
3779 | | " Dictionary of strings mapping to strings."); |
3780 | | |
3781 | | #define OS_EXECVE_METHODDEF \ |
3782 | | {"execve", _PyCFunction_CAST(os_execve), METH_FASTCALL|METH_KEYWORDS, os_execve__doc__}, |
3783 | | |
3784 | | static PyObject * |
3785 | | os_execve_impl(PyObject *module, path_t *path, PyObject *argv, PyObject *env); |
3786 | | |
3787 | | static PyObject * |
3788 | | os_execve(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
3789 | 0 | { |
3790 | 0 | PyObject *return_value = NULL; |
3791 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
3792 | |
|
3793 | 0 | #define NUM_KEYWORDS 3 |
3794 | 0 | static struct { |
3795 | 0 | PyGC_Head _this_is_not_used; |
3796 | 0 | PyObject_VAR_HEAD |
3797 | 0 | Py_hash_t ob_hash; |
3798 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
3799 | 0 | } _kwtuple = { |
3800 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
3801 | 0 | .ob_hash = -1, |
3802 | 0 | .ob_item = { &_Py_ID(path), &_Py_ID(argv), &_Py_ID(env), }, |
3803 | 0 | }; |
3804 | 0 | #undef NUM_KEYWORDS |
3805 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
3806 | |
|
3807 | | #else // !Py_BUILD_CORE |
3808 | | # define KWTUPLE NULL |
3809 | | #endif // !Py_BUILD_CORE |
3810 | |
|
3811 | 0 | static const char * const _keywords[] = {"path", "argv", "env", NULL}; |
3812 | 0 | static _PyArg_Parser _parser = { |
3813 | 0 | .keywords = _keywords, |
3814 | 0 | .fname = "execve", |
3815 | 0 | .kwtuple = KWTUPLE, |
3816 | 0 | }; |
3817 | 0 | #undef KWTUPLE |
3818 | 0 | PyObject *argsbuf[3]; |
3819 | 0 | path_t path = PATH_T_INITIALIZE_P("execve", "path", 0, 0, 0, PATH_HAVE_FEXECVE); |
3820 | 0 | PyObject *argv; |
3821 | 0 | PyObject *env; |
3822 | |
|
3823 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
3824 | 0 | /*minpos*/ 3, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
3825 | 0 | if (!args) { |
3826 | 0 | goto exit; |
3827 | 0 | } |
3828 | 0 | if (!path_converter(args[0], &path)) { |
3829 | 0 | goto exit; |
3830 | 0 | } |
3831 | 0 | argv = args[1]; |
3832 | 0 | env = args[2]; |
3833 | 0 | return_value = os_execve_impl(module, &path, argv, env); |
3834 | |
|
3835 | 0 | exit: |
3836 | | /* Cleanup for path */ |
3837 | 0 | path_cleanup(&path); |
3838 | |
|
3839 | 0 | return return_value; |
3840 | 0 | } |
3841 | | |
3842 | | #endif /* defined(HAVE_EXECV) */ |
3843 | | |
3844 | | #if defined(HAVE_POSIX_SPAWN) |
3845 | | |
3846 | | PyDoc_STRVAR(os_posix_spawn__doc__, |
3847 | | "posix_spawn($module, path, argv, env, /, *, file_actions=(),\n" |
3848 | | " setpgroup=<unrepresentable>, resetids=False, setsid=False,\n" |
3849 | | " setsigmask=(), setsigdef=(), scheduler=<unrepresentable>)\n" |
3850 | | "--\n" |
3851 | | "\n" |
3852 | | "Execute the program specified by path in a new process.\n" |
3853 | | "\n" |
3854 | | " path\n" |
3855 | | " Path of executable file.\n" |
3856 | | " argv\n" |
3857 | | " Tuple or list of strings.\n" |
3858 | | " env\n" |
3859 | | " Dictionary of strings mapping to strings.\n" |
3860 | | " file_actions\n" |
3861 | | " A sequence of file action tuples.\n" |
3862 | | " setpgroup\n" |
3863 | | " The pgroup to use with the POSIX_SPAWN_SETPGROUP flag.\n" |
3864 | | " resetids\n" |
3865 | | " If the value is `true` the POSIX_SPAWN_RESETIDS will be activated.\n" |
3866 | | " setsid\n" |
3867 | | " If the value is `true` the POSIX_SPAWN_SETSID or POSIX_SPAWN_SETSID_NP will be activated.\n" |
3868 | | " setsigmask\n" |
3869 | | " The sigmask to use with the POSIX_SPAWN_SETSIGMASK flag.\n" |
3870 | | " setsigdef\n" |
3871 | | " The sigmask to use with the POSIX_SPAWN_SETSIGDEF flag.\n" |
3872 | | " scheduler\n" |
3873 | | " A tuple with the scheduler policy (optional) and parameters."); |
3874 | | |
3875 | | #define OS_POSIX_SPAWN_METHODDEF \ |
3876 | | {"posix_spawn", _PyCFunction_CAST(os_posix_spawn), METH_FASTCALL|METH_KEYWORDS, os_posix_spawn__doc__}, |
3877 | | |
3878 | | static PyObject * |
3879 | | os_posix_spawn_impl(PyObject *module, path_t *path, PyObject *argv, |
3880 | | PyObject *env, PyObject *file_actions, |
3881 | | PyObject *setpgroup, int resetids, int setsid, |
3882 | | PyObject *setsigmask, PyObject *setsigdef, |
3883 | | PyObject *scheduler); |
3884 | | |
3885 | | static PyObject * |
3886 | | os_posix_spawn(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
3887 | 0 | { |
3888 | 0 | PyObject *return_value = NULL; |
3889 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
3890 | |
|
3891 | 0 | #define NUM_KEYWORDS 7 |
3892 | 0 | static struct { |
3893 | 0 | PyGC_Head _this_is_not_used; |
3894 | 0 | PyObject_VAR_HEAD |
3895 | 0 | Py_hash_t ob_hash; |
3896 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
3897 | 0 | } _kwtuple = { |
3898 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
3899 | 0 | .ob_hash = -1, |
3900 | 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), }, |
3901 | 0 | }; |
3902 | 0 | #undef NUM_KEYWORDS |
3903 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
3904 | |
|
3905 | | #else // !Py_BUILD_CORE |
3906 | | # define KWTUPLE NULL |
3907 | | #endif // !Py_BUILD_CORE |
3908 | |
|
3909 | 0 | static const char * const _keywords[] = {"", "", "", "file_actions", "setpgroup", "resetids", "setsid", "setsigmask", "setsigdef", "scheduler", NULL}; |
3910 | 0 | static _PyArg_Parser _parser = { |
3911 | 0 | .keywords = _keywords, |
3912 | 0 | .fname = "posix_spawn", |
3913 | 0 | .kwtuple = KWTUPLE, |
3914 | 0 | }; |
3915 | 0 | #undef KWTUPLE |
3916 | 0 | PyObject *argsbuf[10]; |
3917 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3; |
3918 | 0 | path_t path = PATH_T_INITIALIZE_P("posix_spawn", "path", 0, 0, 0, 0); |
3919 | 0 | PyObject *argv; |
3920 | 0 | PyObject *env; |
3921 | 0 | PyObject *file_actions = NULL; |
3922 | 0 | PyObject *setpgroup = NULL; |
3923 | 0 | int resetids = 0; |
3924 | 0 | int setsid = 0; |
3925 | 0 | PyObject *setsigmask = NULL; |
3926 | 0 | PyObject *setsigdef = NULL; |
3927 | 0 | PyObject *scheduler = NULL; |
3928 | |
|
3929 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
3930 | 0 | /*minpos*/ 3, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
3931 | 0 | if (!args) { |
3932 | 0 | goto exit; |
3933 | 0 | } |
3934 | 0 | if (!path_converter(args[0], &path)) { |
3935 | 0 | goto exit; |
3936 | 0 | } |
3937 | 0 | argv = args[1]; |
3938 | 0 | env = args[2]; |
3939 | 0 | if (!noptargs) { |
3940 | 0 | goto skip_optional_kwonly; |
3941 | 0 | } |
3942 | 0 | if (args[3]) { |
3943 | 0 | file_actions = args[3]; |
3944 | 0 | if (!--noptargs) { |
3945 | 0 | goto skip_optional_kwonly; |
3946 | 0 | } |
3947 | 0 | } |
3948 | 0 | if (args[4]) { |
3949 | 0 | setpgroup = args[4]; |
3950 | 0 | if (!--noptargs) { |
3951 | 0 | goto skip_optional_kwonly; |
3952 | 0 | } |
3953 | 0 | } |
3954 | 0 | if (args[5]) { |
3955 | 0 | resetids = PyObject_IsTrue(args[5]); |
3956 | 0 | if (resetids < 0) { |
3957 | 0 | goto exit; |
3958 | 0 | } |
3959 | 0 | if (!--noptargs) { |
3960 | 0 | goto skip_optional_kwonly; |
3961 | 0 | } |
3962 | 0 | } |
3963 | 0 | if (args[6]) { |
3964 | 0 | setsid = PyObject_IsTrue(args[6]); |
3965 | 0 | if (setsid < 0) { |
3966 | 0 | goto exit; |
3967 | 0 | } |
3968 | 0 | if (!--noptargs) { |
3969 | 0 | goto skip_optional_kwonly; |
3970 | 0 | } |
3971 | 0 | } |
3972 | 0 | if (args[7]) { |
3973 | 0 | setsigmask = args[7]; |
3974 | 0 | if (!--noptargs) { |
3975 | 0 | goto skip_optional_kwonly; |
3976 | 0 | } |
3977 | 0 | } |
3978 | 0 | if (args[8]) { |
3979 | 0 | setsigdef = args[8]; |
3980 | 0 | if (!--noptargs) { |
3981 | 0 | goto skip_optional_kwonly; |
3982 | 0 | } |
3983 | 0 | } |
3984 | 0 | scheduler = args[9]; |
3985 | 0 | skip_optional_kwonly: |
3986 | 0 | return_value = os_posix_spawn_impl(module, &path, argv, env, file_actions, setpgroup, resetids, setsid, setsigmask, setsigdef, scheduler); |
3987 | |
|
3988 | 0 | exit: |
3989 | | /* Cleanup for path */ |
3990 | 0 | path_cleanup(&path); |
3991 | |
|
3992 | 0 | return return_value; |
3993 | 0 | } |
3994 | | |
3995 | | #endif /* defined(HAVE_POSIX_SPAWN) */ |
3996 | | |
3997 | | #if defined(HAVE_POSIX_SPAWNP) |
3998 | | |
3999 | | PyDoc_STRVAR(os_posix_spawnp__doc__, |
4000 | | "posix_spawnp($module, path, argv, env, /, *, file_actions=(),\n" |
4001 | | " setpgroup=<unrepresentable>, resetids=False, setsid=False,\n" |
4002 | | " setsigmask=(), setsigdef=(), scheduler=<unrepresentable>)\n" |
4003 | | "--\n" |
4004 | | "\n" |
4005 | | "Execute the program specified by path in a new process.\n" |
4006 | | "\n" |
4007 | | " path\n" |
4008 | | " Path of executable file.\n" |
4009 | | " argv\n" |
4010 | | " Tuple or list of strings.\n" |
4011 | | " env\n" |
4012 | | " Dictionary of strings mapping to strings.\n" |
4013 | | " file_actions\n" |
4014 | | " A sequence of file action tuples.\n" |
4015 | | " setpgroup\n" |
4016 | | " The pgroup to use with the POSIX_SPAWN_SETPGROUP flag.\n" |
4017 | | " resetids\n" |
4018 | | " If the value is `True` the POSIX_SPAWN_RESETIDS will be activated.\n" |
4019 | | " setsid\n" |
4020 | | " If the value is `True` the POSIX_SPAWN_SETSID or POSIX_SPAWN_SETSID_NP will be activated.\n" |
4021 | | " setsigmask\n" |
4022 | | " The sigmask to use with the POSIX_SPAWN_SETSIGMASK flag.\n" |
4023 | | " setsigdef\n" |
4024 | | " The sigmask to use with the POSIX_SPAWN_SETSIGDEF flag.\n" |
4025 | | " scheduler\n" |
4026 | | " A tuple with the scheduler policy (optional) and parameters."); |
4027 | | |
4028 | | #define OS_POSIX_SPAWNP_METHODDEF \ |
4029 | | {"posix_spawnp", _PyCFunction_CAST(os_posix_spawnp), METH_FASTCALL|METH_KEYWORDS, os_posix_spawnp__doc__}, |
4030 | | |
4031 | | static PyObject * |
4032 | | os_posix_spawnp_impl(PyObject *module, path_t *path, PyObject *argv, |
4033 | | PyObject *env, PyObject *file_actions, |
4034 | | PyObject *setpgroup, int resetids, int setsid, |
4035 | | PyObject *setsigmask, PyObject *setsigdef, |
4036 | | PyObject *scheduler); |
4037 | | |
4038 | | static PyObject * |
4039 | | os_posix_spawnp(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
4040 | 0 | { |
4041 | 0 | PyObject *return_value = NULL; |
4042 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
4043 | |
|
4044 | 0 | #define NUM_KEYWORDS 7 |
4045 | 0 | static struct { |
4046 | 0 | PyGC_Head _this_is_not_used; |
4047 | 0 | PyObject_VAR_HEAD |
4048 | 0 | Py_hash_t ob_hash; |
4049 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
4050 | 0 | } _kwtuple = { |
4051 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
4052 | 0 | .ob_hash = -1, |
4053 | 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), }, |
4054 | 0 | }; |
4055 | 0 | #undef NUM_KEYWORDS |
4056 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
4057 | |
|
4058 | | #else // !Py_BUILD_CORE |
4059 | | # define KWTUPLE NULL |
4060 | | #endif // !Py_BUILD_CORE |
4061 | |
|
4062 | 0 | static const char * const _keywords[] = {"", "", "", "file_actions", "setpgroup", "resetids", "setsid", "setsigmask", "setsigdef", "scheduler", NULL}; |
4063 | 0 | static _PyArg_Parser _parser = { |
4064 | 0 | .keywords = _keywords, |
4065 | 0 | .fname = "posix_spawnp", |
4066 | 0 | .kwtuple = KWTUPLE, |
4067 | 0 | }; |
4068 | 0 | #undef KWTUPLE |
4069 | 0 | PyObject *argsbuf[10]; |
4070 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3; |
4071 | 0 | path_t path = PATH_T_INITIALIZE_P("posix_spawnp", "path", 0, 0, 0, 0); |
4072 | 0 | PyObject *argv; |
4073 | 0 | PyObject *env; |
4074 | 0 | PyObject *file_actions = NULL; |
4075 | 0 | PyObject *setpgroup = NULL; |
4076 | 0 | int resetids = 0; |
4077 | 0 | int setsid = 0; |
4078 | 0 | PyObject *setsigmask = NULL; |
4079 | 0 | PyObject *setsigdef = NULL; |
4080 | 0 | PyObject *scheduler = NULL; |
4081 | |
|
4082 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
4083 | 0 | /*minpos*/ 3, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
4084 | 0 | if (!args) { |
4085 | 0 | goto exit; |
4086 | 0 | } |
4087 | 0 | if (!path_converter(args[0], &path)) { |
4088 | 0 | goto exit; |
4089 | 0 | } |
4090 | 0 | argv = args[1]; |
4091 | 0 | env = args[2]; |
4092 | 0 | if (!noptargs) { |
4093 | 0 | goto skip_optional_kwonly; |
4094 | 0 | } |
4095 | 0 | if (args[3]) { |
4096 | 0 | file_actions = args[3]; |
4097 | 0 | if (!--noptargs) { |
4098 | 0 | goto skip_optional_kwonly; |
4099 | 0 | } |
4100 | 0 | } |
4101 | 0 | if (args[4]) { |
4102 | 0 | setpgroup = args[4]; |
4103 | 0 | if (!--noptargs) { |
4104 | 0 | goto skip_optional_kwonly; |
4105 | 0 | } |
4106 | 0 | } |
4107 | 0 | if (args[5]) { |
4108 | 0 | resetids = PyObject_IsTrue(args[5]); |
4109 | 0 | if (resetids < 0) { |
4110 | 0 | goto exit; |
4111 | 0 | } |
4112 | 0 | if (!--noptargs) { |
4113 | 0 | goto skip_optional_kwonly; |
4114 | 0 | } |
4115 | 0 | } |
4116 | 0 | if (args[6]) { |
4117 | 0 | setsid = PyObject_IsTrue(args[6]); |
4118 | 0 | if (setsid < 0) { |
4119 | 0 | goto exit; |
4120 | 0 | } |
4121 | 0 | if (!--noptargs) { |
4122 | 0 | goto skip_optional_kwonly; |
4123 | 0 | } |
4124 | 0 | } |
4125 | 0 | if (args[7]) { |
4126 | 0 | setsigmask = args[7]; |
4127 | 0 | if (!--noptargs) { |
4128 | 0 | goto skip_optional_kwonly; |
4129 | 0 | } |
4130 | 0 | } |
4131 | 0 | if (args[8]) { |
4132 | 0 | setsigdef = args[8]; |
4133 | 0 | if (!--noptargs) { |
4134 | 0 | goto skip_optional_kwonly; |
4135 | 0 | } |
4136 | 0 | } |
4137 | 0 | scheduler = args[9]; |
4138 | 0 | skip_optional_kwonly: |
4139 | 0 | return_value = os_posix_spawnp_impl(module, &path, argv, env, file_actions, setpgroup, resetids, setsid, setsigmask, setsigdef, scheduler); |
4140 | |
|
4141 | 0 | exit: |
4142 | | /* Cleanup for path */ |
4143 | 0 | path_cleanup(&path); |
4144 | |
|
4145 | 0 | return return_value; |
4146 | 0 | } |
4147 | | |
4148 | | #endif /* defined(HAVE_POSIX_SPAWNP) */ |
4149 | | |
4150 | | #if (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV) || defined(HAVE_RTPSPAWN)) |
4151 | | |
4152 | | PyDoc_STRVAR(os_spawnv__doc__, |
4153 | | "spawnv($module, mode, path, argv, /)\n" |
4154 | | "--\n" |
4155 | | "\n" |
4156 | | "Execute the program specified by path in a new process.\n" |
4157 | | "\n" |
4158 | | " mode\n" |
4159 | | " Mode of process creation.\n" |
4160 | | " path\n" |
4161 | | " Path of executable file.\n" |
4162 | | " argv\n" |
4163 | | " Tuple or list of strings."); |
4164 | | |
4165 | | #define OS_SPAWNV_METHODDEF \ |
4166 | | {"spawnv", _PyCFunction_CAST(os_spawnv), METH_FASTCALL, os_spawnv__doc__}, |
4167 | | |
4168 | | static PyObject * |
4169 | | os_spawnv_impl(PyObject *module, int mode, path_t *path, PyObject *argv); |
4170 | | |
4171 | | static PyObject * |
4172 | | os_spawnv(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
4173 | | { |
4174 | | PyObject *return_value = NULL; |
4175 | | int mode; |
4176 | | path_t path = PATH_T_INITIALIZE_P("spawnv", "path", 0, 0, 0, 0); |
4177 | | PyObject *argv; |
4178 | | |
4179 | | if (!_PyArg_CheckPositional("spawnv", nargs, 3, 3)) { |
4180 | | goto exit; |
4181 | | } |
4182 | | mode = PyLong_AsInt(args[0]); |
4183 | | if (mode == -1 && PyErr_Occurred()) { |
4184 | | goto exit; |
4185 | | } |
4186 | | if (!path_converter(args[1], &path)) { |
4187 | | goto exit; |
4188 | | } |
4189 | | argv = args[2]; |
4190 | | return_value = os_spawnv_impl(module, mode, &path, argv); |
4191 | | |
4192 | | exit: |
4193 | | /* Cleanup for path */ |
4194 | | path_cleanup(&path); |
4195 | | |
4196 | | return return_value; |
4197 | | } |
4198 | | |
4199 | | #endif /* (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV) || defined(HAVE_RTPSPAWN)) */ |
4200 | | |
4201 | | #if (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV) || defined(HAVE_RTPSPAWN)) |
4202 | | |
4203 | | PyDoc_STRVAR(os_spawnve__doc__, |
4204 | | "spawnve($module, mode, path, argv, env, /)\n" |
4205 | | "--\n" |
4206 | | "\n" |
4207 | | "Execute the program specified by path in a new process.\n" |
4208 | | "\n" |
4209 | | " mode\n" |
4210 | | " Mode of process creation.\n" |
4211 | | " path\n" |
4212 | | " Path of executable file.\n" |
4213 | | " argv\n" |
4214 | | " Tuple or list of strings.\n" |
4215 | | " env\n" |
4216 | | " Dictionary of strings mapping to strings."); |
4217 | | |
4218 | | #define OS_SPAWNVE_METHODDEF \ |
4219 | | {"spawnve", _PyCFunction_CAST(os_spawnve), METH_FASTCALL, os_spawnve__doc__}, |
4220 | | |
4221 | | static PyObject * |
4222 | | os_spawnve_impl(PyObject *module, int mode, path_t *path, PyObject *argv, |
4223 | | PyObject *env); |
4224 | | |
4225 | | static PyObject * |
4226 | | os_spawnve(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
4227 | | { |
4228 | | PyObject *return_value = NULL; |
4229 | | int mode; |
4230 | | path_t path = PATH_T_INITIALIZE_P("spawnve", "path", 0, 0, 0, 0); |
4231 | | PyObject *argv; |
4232 | | PyObject *env; |
4233 | | |
4234 | | if (!_PyArg_CheckPositional("spawnve", nargs, 4, 4)) { |
4235 | | goto exit; |
4236 | | } |
4237 | | mode = PyLong_AsInt(args[0]); |
4238 | | if (mode == -1 && PyErr_Occurred()) { |
4239 | | goto exit; |
4240 | | } |
4241 | | if (!path_converter(args[1], &path)) { |
4242 | | goto exit; |
4243 | | } |
4244 | | argv = args[2]; |
4245 | | env = args[3]; |
4246 | | return_value = os_spawnve_impl(module, mode, &path, argv, env); |
4247 | | |
4248 | | exit: |
4249 | | /* Cleanup for path */ |
4250 | | path_cleanup(&path); |
4251 | | |
4252 | | return return_value; |
4253 | | } |
4254 | | |
4255 | | #endif /* (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV) || defined(HAVE_RTPSPAWN)) */ |
4256 | | |
4257 | | #if defined(HAVE_FORK) |
4258 | | |
4259 | | PyDoc_STRVAR(os_register_at_fork__doc__, |
4260 | | "register_at_fork($module, /, *, before=<unrepresentable>,\n" |
4261 | | " after_in_child=<unrepresentable>,\n" |
4262 | | " after_in_parent=<unrepresentable>)\n" |
4263 | | "--\n" |
4264 | | "\n" |
4265 | | "Register callables to be called when forking a new process.\n" |
4266 | | "\n" |
4267 | | " before\n" |
4268 | | " A callable to be called in the parent before the fork() syscall.\n" |
4269 | | " after_in_child\n" |
4270 | | " A callable to be called in the child after fork().\n" |
4271 | | " after_in_parent\n" |
4272 | | " A callable to be called in the parent after fork().\n" |
4273 | | "\n" |
4274 | | "\'before\' callbacks are called in reverse order.\n" |
4275 | | "\'after_in_child\' and \'after_in_parent\' callbacks are called in order."); |
4276 | | |
4277 | | #define OS_REGISTER_AT_FORK_METHODDEF \ |
4278 | | {"register_at_fork", _PyCFunction_CAST(os_register_at_fork), METH_FASTCALL|METH_KEYWORDS, os_register_at_fork__doc__}, |
4279 | | |
4280 | | static PyObject * |
4281 | | os_register_at_fork_impl(PyObject *module, PyObject *before, |
4282 | | PyObject *after_in_child, PyObject *after_in_parent); |
4283 | | |
4284 | | static PyObject * |
4285 | | os_register_at_fork(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
4286 | 2 | { |
4287 | 2 | PyObject *return_value = NULL; |
4288 | 2 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
4289 | | |
4290 | 2 | #define NUM_KEYWORDS 3 |
4291 | 2 | static struct { |
4292 | 2 | PyGC_Head _this_is_not_used; |
4293 | 2 | PyObject_VAR_HEAD |
4294 | 2 | Py_hash_t ob_hash; |
4295 | 2 | PyObject *ob_item[NUM_KEYWORDS]; |
4296 | 2 | } _kwtuple = { |
4297 | 2 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
4298 | 2 | .ob_hash = -1, |
4299 | 2 | .ob_item = { &_Py_ID(before), &_Py_ID(after_in_child), &_Py_ID(after_in_parent), }, |
4300 | 2 | }; |
4301 | 2 | #undef NUM_KEYWORDS |
4302 | 2 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
4303 | | |
4304 | | #else // !Py_BUILD_CORE |
4305 | | # define KWTUPLE NULL |
4306 | | #endif // !Py_BUILD_CORE |
4307 | | |
4308 | 2 | static const char * const _keywords[] = {"before", "after_in_child", "after_in_parent", NULL}; |
4309 | 2 | static _PyArg_Parser _parser = { |
4310 | 2 | .keywords = _keywords, |
4311 | 2 | .fname = "register_at_fork", |
4312 | 2 | .kwtuple = KWTUPLE, |
4313 | 2 | }; |
4314 | 2 | #undef KWTUPLE |
4315 | 2 | PyObject *argsbuf[3]; |
4316 | 2 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; |
4317 | 2 | PyObject *before = NULL; |
4318 | 2 | PyObject *after_in_child = NULL; |
4319 | 2 | PyObject *after_in_parent = NULL; |
4320 | | |
4321 | 2 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
4322 | 2 | /*minpos*/ 0, /*maxpos*/ 0, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
4323 | 2 | if (!args) { |
4324 | 0 | goto exit; |
4325 | 0 | } |
4326 | 2 | if (!noptargs) { |
4327 | 0 | goto skip_optional_kwonly; |
4328 | 0 | } |
4329 | 2 | if (args[0]) { |
4330 | 0 | before = args[0]; |
4331 | 0 | if (!--noptargs) { |
4332 | 0 | goto skip_optional_kwonly; |
4333 | 0 | } |
4334 | 0 | } |
4335 | 2 | if (args[1]) { |
4336 | 2 | after_in_child = args[1]; |
4337 | 2 | if (!--noptargs) { |
4338 | 2 | goto skip_optional_kwonly; |
4339 | 2 | } |
4340 | 2 | } |
4341 | 0 | after_in_parent = args[2]; |
4342 | 2 | skip_optional_kwonly: |
4343 | 2 | return_value = os_register_at_fork_impl(module, before, after_in_child, after_in_parent); |
4344 | | |
4345 | 2 | exit: |
4346 | 2 | return return_value; |
4347 | 2 | } |
4348 | | |
4349 | | #endif /* defined(HAVE_FORK) */ |
4350 | | |
4351 | | #if defined(HAVE_FORK1) |
4352 | | |
4353 | | PyDoc_STRVAR(os_fork1__doc__, |
4354 | | "fork1($module, /)\n" |
4355 | | "--\n" |
4356 | | "\n" |
4357 | | "Fork a child process with a single multiplexed (i.e., not bound) thread.\n" |
4358 | | "\n" |
4359 | | "Return 0 to child process and PID of child to parent process."); |
4360 | | |
4361 | | #define OS_FORK1_METHODDEF \ |
4362 | | {"fork1", (PyCFunction)os_fork1, METH_NOARGS, os_fork1__doc__}, |
4363 | | |
4364 | | static PyObject * |
4365 | | os_fork1_impl(PyObject *module); |
4366 | | |
4367 | | static PyObject * |
4368 | | os_fork1(PyObject *module, PyObject *Py_UNUSED(ignored)) |
4369 | | { |
4370 | | return os_fork1_impl(module); |
4371 | | } |
4372 | | |
4373 | | #endif /* defined(HAVE_FORK1) */ |
4374 | | |
4375 | | #if defined(HAVE_FORK) |
4376 | | |
4377 | | PyDoc_STRVAR(os_fork__doc__, |
4378 | | "fork($module, /)\n" |
4379 | | "--\n" |
4380 | | "\n" |
4381 | | "Fork a child process.\n" |
4382 | | "\n" |
4383 | | "Return 0 to child process and PID of child to parent process."); |
4384 | | |
4385 | | #define OS_FORK_METHODDEF \ |
4386 | | {"fork", (PyCFunction)os_fork, METH_NOARGS, os_fork__doc__}, |
4387 | | |
4388 | | static PyObject * |
4389 | | os_fork_impl(PyObject *module); |
4390 | | |
4391 | | static PyObject * |
4392 | | os_fork(PyObject *module, PyObject *Py_UNUSED(ignored)) |
4393 | 0 | { |
4394 | 0 | return os_fork_impl(module); |
4395 | 0 | } |
4396 | | |
4397 | | #endif /* defined(HAVE_FORK) */ |
4398 | | |
4399 | | #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) |
4400 | | |
4401 | | PyDoc_STRVAR(os_sched_get_priority_max__doc__, |
4402 | | "sched_get_priority_max($module, /, policy)\n" |
4403 | | "--\n" |
4404 | | "\n" |
4405 | | "Get the maximum scheduling priority for policy."); |
4406 | | |
4407 | | #define OS_SCHED_GET_PRIORITY_MAX_METHODDEF \ |
4408 | | {"sched_get_priority_max", _PyCFunction_CAST(os_sched_get_priority_max), METH_FASTCALL|METH_KEYWORDS, os_sched_get_priority_max__doc__}, |
4409 | | |
4410 | | static PyObject * |
4411 | | os_sched_get_priority_max_impl(PyObject *module, int policy); |
4412 | | |
4413 | | static PyObject * |
4414 | | os_sched_get_priority_max(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
4415 | 0 | { |
4416 | 0 | PyObject *return_value = NULL; |
4417 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
4418 | |
|
4419 | 0 | #define NUM_KEYWORDS 1 |
4420 | 0 | static struct { |
4421 | 0 | PyGC_Head _this_is_not_used; |
4422 | 0 | PyObject_VAR_HEAD |
4423 | 0 | Py_hash_t ob_hash; |
4424 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
4425 | 0 | } _kwtuple = { |
4426 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
4427 | 0 | .ob_hash = -1, |
4428 | 0 | .ob_item = { &_Py_ID(policy), }, |
4429 | 0 | }; |
4430 | 0 | #undef NUM_KEYWORDS |
4431 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
4432 | |
|
4433 | | #else // !Py_BUILD_CORE |
4434 | | # define KWTUPLE NULL |
4435 | | #endif // !Py_BUILD_CORE |
4436 | |
|
4437 | 0 | static const char * const _keywords[] = {"policy", NULL}; |
4438 | 0 | static _PyArg_Parser _parser = { |
4439 | 0 | .keywords = _keywords, |
4440 | 0 | .fname = "sched_get_priority_max", |
4441 | 0 | .kwtuple = KWTUPLE, |
4442 | 0 | }; |
4443 | 0 | #undef KWTUPLE |
4444 | 0 | PyObject *argsbuf[1]; |
4445 | 0 | int policy; |
4446 | |
|
4447 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
4448 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
4449 | 0 | if (!args) { |
4450 | 0 | goto exit; |
4451 | 0 | } |
4452 | 0 | policy = PyLong_AsInt(args[0]); |
4453 | 0 | if (policy == -1 && PyErr_Occurred()) { |
4454 | 0 | goto exit; |
4455 | 0 | } |
4456 | 0 | return_value = os_sched_get_priority_max_impl(module, policy); |
4457 | |
|
4458 | 0 | exit: |
4459 | 0 | return return_value; |
4460 | 0 | } |
4461 | | |
4462 | | #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) */ |
4463 | | |
4464 | | #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) |
4465 | | |
4466 | | PyDoc_STRVAR(os_sched_get_priority_min__doc__, |
4467 | | "sched_get_priority_min($module, /, policy)\n" |
4468 | | "--\n" |
4469 | | "\n" |
4470 | | "Get the minimum scheduling priority for policy."); |
4471 | | |
4472 | | #define OS_SCHED_GET_PRIORITY_MIN_METHODDEF \ |
4473 | | {"sched_get_priority_min", _PyCFunction_CAST(os_sched_get_priority_min), METH_FASTCALL|METH_KEYWORDS, os_sched_get_priority_min__doc__}, |
4474 | | |
4475 | | static PyObject * |
4476 | | os_sched_get_priority_min_impl(PyObject *module, int policy); |
4477 | | |
4478 | | static PyObject * |
4479 | | os_sched_get_priority_min(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
4480 | 0 | { |
4481 | 0 | PyObject *return_value = NULL; |
4482 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
4483 | |
|
4484 | 0 | #define NUM_KEYWORDS 1 |
4485 | 0 | static struct { |
4486 | 0 | PyGC_Head _this_is_not_used; |
4487 | 0 | PyObject_VAR_HEAD |
4488 | 0 | Py_hash_t ob_hash; |
4489 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
4490 | 0 | } _kwtuple = { |
4491 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
4492 | 0 | .ob_hash = -1, |
4493 | 0 | .ob_item = { &_Py_ID(policy), }, |
4494 | 0 | }; |
4495 | 0 | #undef NUM_KEYWORDS |
4496 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
4497 | |
|
4498 | | #else // !Py_BUILD_CORE |
4499 | | # define KWTUPLE NULL |
4500 | | #endif // !Py_BUILD_CORE |
4501 | |
|
4502 | 0 | static const char * const _keywords[] = {"policy", NULL}; |
4503 | 0 | static _PyArg_Parser _parser = { |
4504 | 0 | .keywords = _keywords, |
4505 | 0 | .fname = "sched_get_priority_min", |
4506 | 0 | .kwtuple = KWTUPLE, |
4507 | 0 | }; |
4508 | 0 | #undef KWTUPLE |
4509 | 0 | PyObject *argsbuf[1]; |
4510 | 0 | int policy; |
4511 | |
|
4512 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
4513 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
4514 | 0 | if (!args) { |
4515 | 0 | goto exit; |
4516 | 0 | } |
4517 | 0 | policy = PyLong_AsInt(args[0]); |
4518 | 0 | if (policy == -1 && PyErr_Occurred()) { |
4519 | 0 | goto exit; |
4520 | 0 | } |
4521 | 0 | return_value = os_sched_get_priority_min_impl(module, policy); |
4522 | |
|
4523 | 0 | exit: |
4524 | 0 | return return_value; |
4525 | 0 | } |
4526 | | |
4527 | | #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) */ |
4528 | | |
4529 | | #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) |
4530 | | |
4531 | | PyDoc_STRVAR(os_sched_getscheduler__doc__, |
4532 | | "sched_getscheduler($module, pid, /)\n" |
4533 | | "--\n" |
4534 | | "\n" |
4535 | | "Get the scheduling policy for the process identified by pid.\n" |
4536 | | "\n" |
4537 | | "Passing 0 for pid returns the scheduling policy for the calling process."); |
4538 | | |
4539 | | #define OS_SCHED_GETSCHEDULER_METHODDEF \ |
4540 | | {"sched_getscheduler", (PyCFunction)os_sched_getscheduler, METH_O, os_sched_getscheduler__doc__}, |
4541 | | |
4542 | | static PyObject * |
4543 | | os_sched_getscheduler_impl(PyObject *module, pid_t pid); |
4544 | | |
4545 | | static PyObject * |
4546 | | os_sched_getscheduler(PyObject *module, PyObject *arg) |
4547 | 0 | { |
4548 | 0 | PyObject *return_value = NULL; |
4549 | 0 | pid_t pid; |
4550 | |
|
4551 | 0 | pid = PyLong_AsPid(arg); |
4552 | 0 | if (pid == (pid_t)(-1) && PyErr_Occurred()) { |
4553 | 0 | goto exit; |
4554 | 0 | } |
4555 | 0 | return_value = os_sched_getscheduler_impl(module, pid); |
4556 | |
|
4557 | 0 | exit: |
4558 | 0 | return return_value; |
4559 | 0 | } |
4560 | | |
4561 | | #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) */ |
4562 | | |
4563 | | #if defined(HAVE_SCHED_H) && (defined(HAVE_SCHED_SETPARAM) || defined(HAVE_SCHED_SETSCHEDULER) || defined(POSIX_SPAWN_SETSCHEDULER) || defined(POSIX_SPAWN_SETSCHEDPARAM)) |
4564 | | |
4565 | | PyDoc_STRVAR(os_sched_param__doc__, |
4566 | | "sched_param(sched_priority)\n" |
4567 | | "--\n" |
4568 | | "\n" |
4569 | | "Currently has only one field: sched_priority\n" |
4570 | | "\n" |
4571 | | " sched_priority\n" |
4572 | | " A scheduling parameter."); |
4573 | | |
4574 | | static PyObject * |
4575 | | os_sched_param_impl(PyTypeObject *type, PyObject *sched_priority); |
4576 | | |
4577 | | static PyObject * |
4578 | | os_sched_param(PyTypeObject *type, PyObject *args, PyObject *kwargs) |
4579 | 0 | { |
4580 | 0 | PyObject *return_value = NULL; |
4581 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
4582 | |
|
4583 | 0 | #define NUM_KEYWORDS 1 |
4584 | 0 | static struct { |
4585 | 0 | PyGC_Head _this_is_not_used; |
4586 | 0 | PyObject_VAR_HEAD |
4587 | 0 | Py_hash_t ob_hash; |
4588 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
4589 | 0 | } _kwtuple = { |
4590 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
4591 | 0 | .ob_hash = -1, |
4592 | 0 | .ob_item = { &_Py_ID(sched_priority), }, |
4593 | 0 | }; |
4594 | 0 | #undef NUM_KEYWORDS |
4595 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
4596 | |
|
4597 | | #else // !Py_BUILD_CORE |
4598 | | # define KWTUPLE NULL |
4599 | | #endif // !Py_BUILD_CORE |
4600 | |
|
4601 | 0 | static const char * const _keywords[] = {"sched_priority", NULL}; |
4602 | 0 | static _PyArg_Parser _parser = { |
4603 | 0 | .keywords = _keywords, |
4604 | 0 | .fname = "sched_param", |
4605 | 0 | .kwtuple = KWTUPLE, |
4606 | 0 | }; |
4607 | 0 | #undef KWTUPLE |
4608 | 0 | PyObject *argsbuf[1]; |
4609 | 0 | PyObject * const *fastargs; |
4610 | 0 | Py_ssize_t nargs = PyTuple_GET_SIZE(args); |
4611 | 0 | PyObject *sched_priority; |
4612 | |
|
4613 | 0 | fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, |
4614 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
4615 | 0 | if (!fastargs) { |
4616 | 0 | goto exit; |
4617 | 0 | } |
4618 | 0 | sched_priority = fastargs[0]; |
4619 | 0 | return_value = os_sched_param_impl(type, sched_priority); |
4620 | |
|
4621 | 0 | exit: |
4622 | 0 | return return_value; |
4623 | 0 | } |
4624 | | |
4625 | | #endif /* defined(HAVE_SCHED_H) && (defined(HAVE_SCHED_SETPARAM) || defined(HAVE_SCHED_SETSCHEDULER) || defined(POSIX_SPAWN_SETSCHEDULER) || defined(POSIX_SPAWN_SETSCHEDPARAM)) */ |
4626 | | |
4627 | | #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) |
4628 | | |
4629 | | PyDoc_STRVAR(os_sched_setscheduler__doc__, |
4630 | | "sched_setscheduler($module, pid, policy, param, /)\n" |
4631 | | "--\n" |
4632 | | "\n" |
4633 | | "Set the scheduling policy for the process identified by pid.\n" |
4634 | | "\n" |
4635 | | "If pid is 0, the calling process is changed.\n" |
4636 | | "param is an instance of sched_param."); |
4637 | | |
4638 | | #define OS_SCHED_SETSCHEDULER_METHODDEF \ |
4639 | | {"sched_setscheduler", _PyCFunction_CAST(os_sched_setscheduler), METH_FASTCALL, os_sched_setscheduler__doc__}, |
4640 | | |
4641 | | static PyObject * |
4642 | | os_sched_setscheduler_impl(PyObject *module, pid_t pid, int policy, |
4643 | | PyObject *param_obj); |
4644 | | |
4645 | | static PyObject * |
4646 | | os_sched_setscheduler(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
4647 | 0 | { |
4648 | 0 | PyObject *return_value = NULL; |
4649 | 0 | pid_t pid; |
4650 | 0 | int policy; |
4651 | 0 | PyObject *param_obj; |
4652 | |
|
4653 | 0 | if (!_PyArg_CheckPositional("sched_setscheduler", nargs, 3, 3)) { |
4654 | 0 | goto exit; |
4655 | 0 | } |
4656 | 0 | pid = PyLong_AsPid(args[0]); |
4657 | 0 | if (pid == (pid_t)(-1) && PyErr_Occurred()) { |
4658 | 0 | goto exit; |
4659 | 0 | } |
4660 | 0 | policy = PyLong_AsInt(args[1]); |
4661 | 0 | if (policy == -1 && PyErr_Occurred()) { |
4662 | 0 | goto exit; |
4663 | 0 | } |
4664 | 0 | param_obj = args[2]; |
4665 | 0 | return_value = os_sched_setscheduler_impl(module, pid, policy, param_obj); |
4666 | |
|
4667 | 0 | exit: |
4668 | 0 | return return_value; |
4669 | 0 | } |
4670 | | |
4671 | | #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) */ |
4672 | | |
4673 | | #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) |
4674 | | |
4675 | | PyDoc_STRVAR(os_sched_getparam__doc__, |
4676 | | "sched_getparam($module, pid, /)\n" |
4677 | | "--\n" |
4678 | | "\n" |
4679 | | "Returns scheduling parameters for the process identified by pid.\n" |
4680 | | "\n" |
4681 | | "If pid is 0, returns parameters for the calling process.\n" |
4682 | | "Return value is an instance of sched_param."); |
4683 | | |
4684 | | #define OS_SCHED_GETPARAM_METHODDEF \ |
4685 | | {"sched_getparam", (PyCFunction)os_sched_getparam, METH_O, os_sched_getparam__doc__}, |
4686 | | |
4687 | | static PyObject * |
4688 | | os_sched_getparam_impl(PyObject *module, pid_t pid); |
4689 | | |
4690 | | static PyObject * |
4691 | | os_sched_getparam(PyObject *module, PyObject *arg) |
4692 | 0 | { |
4693 | 0 | PyObject *return_value = NULL; |
4694 | 0 | pid_t pid; |
4695 | |
|
4696 | 0 | pid = PyLong_AsPid(arg); |
4697 | 0 | if (pid == (pid_t)(-1) && PyErr_Occurred()) { |
4698 | 0 | goto exit; |
4699 | 0 | } |
4700 | 0 | return_value = os_sched_getparam_impl(module, pid); |
4701 | |
|
4702 | 0 | exit: |
4703 | 0 | return return_value; |
4704 | 0 | } |
4705 | | |
4706 | | #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) */ |
4707 | | |
4708 | | #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) |
4709 | | |
4710 | | PyDoc_STRVAR(os_sched_setparam__doc__, |
4711 | | "sched_setparam($module, pid, param, /)\n" |
4712 | | "--\n" |
4713 | | "\n" |
4714 | | "Set scheduling parameters for the process identified by pid.\n" |
4715 | | "\n" |
4716 | | "If pid is 0, sets parameters for the calling process.\n" |
4717 | | "param should be an instance of sched_param."); |
4718 | | |
4719 | | #define OS_SCHED_SETPARAM_METHODDEF \ |
4720 | | {"sched_setparam", _PyCFunction_CAST(os_sched_setparam), METH_FASTCALL, os_sched_setparam__doc__}, |
4721 | | |
4722 | | static PyObject * |
4723 | | os_sched_setparam_impl(PyObject *module, pid_t pid, PyObject *param_obj); |
4724 | | |
4725 | | static PyObject * |
4726 | | os_sched_setparam(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
4727 | 0 | { |
4728 | 0 | PyObject *return_value = NULL; |
4729 | 0 | pid_t pid; |
4730 | 0 | PyObject *param_obj; |
4731 | |
|
4732 | 0 | if (!_PyArg_CheckPositional("sched_setparam", nargs, 2, 2)) { |
4733 | 0 | goto exit; |
4734 | 0 | } |
4735 | 0 | pid = PyLong_AsPid(args[0]); |
4736 | 0 | if (pid == (pid_t)(-1) && PyErr_Occurred()) { |
4737 | 0 | goto exit; |
4738 | 0 | } |
4739 | 0 | param_obj = args[1]; |
4740 | 0 | return_value = os_sched_setparam_impl(module, pid, param_obj); |
4741 | |
|
4742 | 0 | exit: |
4743 | 0 | return return_value; |
4744 | 0 | } |
4745 | | |
4746 | | #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) */ |
4747 | | |
4748 | | #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_RR_GET_INTERVAL) |
4749 | | |
4750 | | PyDoc_STRVAR(os_sched_rr_get_interval__doc__, |
4751 | | "sched_rr_get_interval($module, pid, /)\n" |
4752 | | "--\n" |
4753 | | "\n" |
4754 | | "Return the round-robin quantum for the process identified by pid, in seconds.\n" |
4755 | | "\n" |
4756 | | "Value returned is a float."); |
4757 | | |
4758 | | #define OS_SCHED_RR_GET_INTERVAL_METHODDEF \ |
4759 | | {"sched_rr_get_interval", (PyCFunction)os_sched_rr_get_interval, METH_O, os_sched_rr_get_interval__doc__}, |
4760 | | |
4761 | | static double |
4762 | | os_sched_rr_get_interval_impl(PyObject *module, pid_t pid); |
4763 | | |
4764 | | static PyObject * |
4765 | | os_sched_rr_get_interval(PyObject *module, PyObject *arg) |
4766 | 0 | { |
4767 | 0 | PyObject *return_value = NULL; |
4768 | 0 | pid_t pid; |
4769 | 0 | double _return_value; |
4770 | |
|
4771 | 0 | pid = PyLong_AsPid(arg); |
4772 | 0 | if (pid == (pid_t)(-1) && PyErr_Occurred()) { |
4773 | 0 | goto exit; |
4774 | 0 | } |
4775 | 0 | _return_value = os_sched_rr_get_interval_impl(module, pid); |
4776 | 0 | if ((_return_value == -1.0) && PyErr_Occurred()) { |
4777 | 0 | goto exit; |
4778 | 0 | } |
4779 | 0 | return_value = PyFloat_FromDouble(_return_value); |
4780 | |
|
4781 | 0 | exit: |
4782 | 0 | return return_value; |
4783 | 0 | } |
4784 | | |
4785 | | #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_RR_GET_INTERVAL) */ |
4786 | | |
4787 | | #if defined(HAVE_SCHED_H) |
4788 | | |
4789 | | PyDoc_STRVAR(os_sched_yield__doc__, |
4790 | | "sched_yield($module, /)\n" |
4791 | | "--\n" |
4792 | | "\n" |
4793 | | "Voluntarily relinquish the CPU."); |
4794 | | |
4795 | | #define OS_SCHED_YIELD_METHODDEF \ |
4796 | | {"sched_yield", (PyCFunction)os_sched_yield, METH_NOARGS, os_sched_yield__doc__}, |
4797 | | |
4798 | | static PyObject * |
4799 | | os_sched_yield_impl(PyObject *module); |
4800 | | |
4801 | | static PyObject * |
4802 | | os_sched_yield(PyObject *module, PyObject *Py_UNUSED(ignored)) |
4803 | 0 | { |
4804 | 0 | return os_sched_yield_impl(module); |
4805 | 0 | } |
4806 | | |
4807 | | #endif /* defined(HAVE_SCHED_H) */ |
4808 | | |
4809 | | #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) |
4810 | | |
4811 | | PyDoc_STRVAR(os_sched_setaffinity__doc__, |
4812 | | "sched_setaffinity($module, pid, mask, /)\n" |
4813 | | "--\n" |
4814 | | "\n" |
4815 | | "Set the CPU affinity of the process identified by pid to mask.\n" |
4816 | | "\n" |
4817 | | "mask should be an iterable of integers identifying CPUs."); |
4818 | | |
4819 | | #define OS_SCHED_SETAFFINITY_METHODDEF \ |
4820 | | {"sched_setaffinity", _PyCFunction_CAST(os_sched_setaffinity), METH_FASTCALL, os_sched_setaffinity__doc__}, |
4821 | | |
4822 | | static PyObject * |
4823 | | os_sched_setaffinity_impl(PyObject *module, pid_t pid, PyObject *mask); |
4824 | | |
4825 | | static PyObject * |
4826 | | os_sched_setaffinity(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
4827 | 0 | { |
4828 | 0 | PyObject *return_value = NULL; |
4829 | 0 | pid_t pid; |
4830 | 0 | PyObject *mask; |
4831 | |
|
4832 | 0 | if (!_PyArg_CheckPositional("sched_setaffinity", nargs, 2, 2)) { |
4833 | 0 | goto exit; |
4834 | 0 | } |
4835 | 0 | pid = PyLong_AsPid(args[0]); |
4836 | 0 | if (pid == (pid_t)(-1) && PyErr_Occurred()) { |
4837 | 0 | goto exit; |
4838 | 0 | } |
4839 | 0 | mask = args[1]; |
4840 | 0 | return_value = os_sched_setaffinity_impl(module, pid, mask); |
4841 | |
|
4842 | 0 | exit: |
4843 | 0 | return return_value; |
4844 | 0 | } |
4845 | | |
4846 | | #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) */ |
4847 | | |
4848 | | #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) |
4849 | | |
4850 | | PyDoc_STRVAR(os_sched_getaffinity__doc__, |
4851 | | "sched_getaffinity($module, pid, /)\n" |
4852 | | "--\n" |
4853 | | "\n" |
4854 | | "Return the affinity of the process identified by pid (or the current process if zero).\n" |
4855 | | "\n" |
4856 | | "The affinity is returned as a set of CPU identifiers."); |
4857 | | |
4858 | | #define OS_SCHED_GETAFFINITY_METHODDEF \ |
4859 | | {"sched_getaffinity", (PyCFunction)os_sched_getaffinity, METH_O, os_sched_getaffinity__doc__}, |
4860 | | |
4861 | | static PyObject * |
4862 | | os_sched_getaffinity_impl(PyObject *module, pid_t pid); |
4863 | | |
4864 | | static PyObject * |
4865 | | os_sched_getaffinity(PyObject *module, PyObject *arg) |
4866 | 0 | { |
4867 | 0 | PyObject *return_value = NULL; |
4868 | 0 | pid_t pid; |
4869 | |
|
4870 | 0 | pid = PyLong_AsPid(arg); |
4871 | 0 | if (pid == (pid_t)(-1) && PyErr_Occurred()) { |
4872 | 0 | goto exit; |
4873 | 0 | } |
4874 | 0 | return_value = os_sched_getaffinity_impl(module, pid); |
4875 | |
|
4876 | 0 | exit: |
4877 | 0 | return return_value; |
4878 | 0 | } |
4879 | | |
4880 | | #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) */ |
4881 | | |
4882 | | #if defined(HAVE_POSIX_OPENPT) |
4883 | | |
4884 | | PyDoc_STRVAR(os_posix_openpt__doc__, |
4885 | | "posix_openpt($module, oflag, /)\n" |
4886 | | "--\n" |
4887 | | "\n" |
4888 | | "Open and return a file descriptor for a master pseudo-terminal device.\n" |
4889 | | "\n" |
4890 | | "Performs a posix_openpt() C function call. The oflag argument is used to\n" |
4891 | | "set file status flags and file access modes as specified in the manual page\n" |
4892 | | "of posix_openpt() of your system."); |
4893 | | |
4894 | | #define OS_POSIX_OPENPT_METHODDEF \ |
4895 | | {"posix_openpt", (PyCFunction)os_posix_openpt, METH_O, os_posix_openpt__doc__}, |
4896 | | |
4897 | | static int |
4898 | | os_posix_openpt_impl(PyObject *module, int oflag); |
4899 | | |
4900 | | static PyObject * |
4901 | | os_posix_openpt(PyObject *module, PyObject *arg) |
4902 | 0 | { |
4903 | 0 | PyObject *return_value = NULL; |
4904 | 0 | int oflag; |
4905 | 0 | int _return_value; |
4906 | |
|
4907 | 0 | oflag = PyLong_AsInt(arg); |
4908 | 0 | if (oflag == -1 && PyErr_Occurred()) { |
4909 | 0 | goto exit; |
4910 | 0 | } |
4911 | 0 | _return_value = os_posix_openpt_impl(module, oflag); |
4912 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
4913 | 0 | goto exit; |
4914 | 0 | } |
4915 | 0 | return_value = PyLong_FromLong((long)_return_value); |
4916 | |
|
4917 | 0 | exit: |
4918 | 0 | return return_value; |
4919 | 0 | } |
4920 | | |
4921 | | #endif /* defined(HAVE_POSIX_OPENPT) */ |
4922 | | |
4923 | | #if defined(HAVE_GRANTPT) |
4924 | | |
4925 | | PyDoc_STRVAR(os_grantpt__doc__, |
4926 | | "grantpt($module, fd, /)\n" |
4927 | | "--\n" |
4928 | | "\n" |
4929 | | "Grant access to the slave pseudo-terminal device.\n" |
4930 | | "\n" |
4931 | | " fd\n" |
4932 | | " File descriptor of a master pseudo-terminal device.\n" |
4933 | | "\n" |
4934 | | "Performs a grantpt() C function call."); |
4935 | | |
4936 | | #define OS_GRANTPT_METHODDEF \ |
4937 | | {"grantpt", (PyCFunction)os_grantpt, METH_O, os_grantpt__doc__}, |
4938 | | |
4939 | | static PyObject * |
4940 | | os_grantpt_impl(PyObject *module, int fd); |
4941 | | |
4942 | | static PyObject * |
4943 | | os_grantpt(PyObject *module, PyObject *arg) |
4944 | 0 | { |
4945 | 0 | PyObject *return_value = NULL; |
4946 | 0 | int fd; |
4947 | |
|
4948 | 0 | fd = PyObject_AsFileDescriptor(arg); |
4949 | 0 | if (fd < 0) { |
4950 | 0 | goto exit; |
4951 | 0 | } |
4952 | 0 | return_value = os_grantpt_impl(module, fd); |
4953 | |
|
4954 | 0 | exit: |
4955 | 0 | return return_value; |
4956 | 0 | } |
4957 | | |
4958 | | #endif /* defined(HAVE_GRANTPT) */ |
4959 | | |
4960 | | #if defined(HAVE_UNLOCKPT) |
4961 | | |
4962 | | PyDoc_STRVAR(os_unlockpt__doc__, |
4963 | | "unlockpt($module, fd, /)\n" |
4964 | | "--\n" |
4965 | | "\n" |
4966 | | "Unlock a pseudo-terminal master/slave pair.\n" |
4967 | | "\n" |
4968 | | " fd\n" |
4969 | | " File descriptor of a master pseudo-terminal device.\n" |
4970 | | "\n" |
4971 | | "Performs an unlockpt() C function call."); |
4972 | | |
4973 | | #define OS_UNLOCKPT_METHODDEF \ |
4974 | | {"unlockpt", (PyCFunction)os_unlockpt, METH_O, os_unlockpt__doc__}, |
4975 | | |
4976 | | static PyObject * |
4977 | | os_unlockpt_impl(PyObject *module, int fd); |
4978 | | |
4979 | | static PyObject * |
4980 | | os_unlockpt(PyObject *module, PyObject *arg) |
4981 | 0 | { |
4982 | 0 | PyObject *return_value = NULL; |
4983 | 0 | int fd; |
4984 | |
|
4985 | 0 | fd = PyObject_AsFileDescriptor(arg); |
4986 | 0 | if (fd < 0) { |
4987 | 0 | goto exit; |
4988 | 0 | } |
4989 | 0 | return_value = os_unlockpt_impl(module, fd); |
4990 | |
|
4991 | 0 | exit: |
4992 | 0 | return return_value; |
4993 | 0 | } |
4994 | | |
4995 | | #endif /* defined(HAVE_UNLOCKPT) */ |
4996 | | |
4997 | | #if (defined(HAVE_PTSNAME) || defined(HAVE_PTSNAME_R)) |
4998 | | |
4999 | | PyDoc_STRVAR(os_ptsname__doc__, |
5000 | | "ptsname($module, fd, /)\n" |
5001 | | "--\n" |
5002 | | "\n" |
5003 | | "Return the name of the slave pseudo-terminal device.\n" |
5004 | | "\n" |
5005 | | " fd\n" |
5006 | | " File descriptor of a master pseudo-terminal device.\n" |
5007 | | "\n" |
5008 | | "If the ptsname_r() C function is available, it is called;\n" |
5009 | | "otherwise, performs a ptsname() C function call."); |
5010 | | |
5011 | | #define OS_PTSNAME_METHODDEF \ |
5012 | | {"ptsname", (PyCFunction)os_ptsname, METH_O, os_ptsname__doc__}, |
5013 | | |
5014 | | static PyObject * |
5015 | | os_ptsname_impl(PyObject *module, int fd); |
5016 | | |
5017 | | static PyObject * |
5018 | | os_ptsname(PyObject *module, PyObject *arg) |
5019 | 0 | { |
5020 | 0 | PyObject *return_value = NULL; |
5021 | 0 | int fd; |
5022 | |
|
5023 | 0 | fd = PyObject_AsFileDescriptor(arg); |
5024 | 0 | if (fd < 0) { |
5025 | 0 | goto exit; |
5026 | 0 | } |
5027 | 0 | return_value = os_ptsname_impl(module, fd); |
5028 | |
|
5029 | 0 | exit: |
5030 | 0 | return return_value; |
5031 | 0 | } |
5032 | | |
5033 | | #endif /* (defined(HAVE_PTSNAME) || defined(HAVE_PTSNAME_R)) */ |
5034 | | |
5035 | | #if (defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX)) |
5036 | | |
5037 | | PyDoc_STRVAR(os_openpty__doc__, |
5038 | | "openpty($module, /)\n" |
5039 | | "--\n" |
5040 | | "\n" |
5041 | | "Open a pseudo-terminal.\n" |
5042 | | "\n" |
5043 | | "Return a tuple of (master_fd, slave_fd) containing open file descriptors\n" |
5044 | | "for both the master and slave ends."); |
5045 | | |
5046 | | #define OS_OPENPTY_METHODDEF \ |
5047 | | {"openpty", (PyCFunction)os_openpty, METH_NOARGS, os_openpty__doc__}, |
5048 | | |
5049 | | static PyObject * |
5050 | | os_openpty_impl(PyObject *module); |
5051 | | |
5052 | | static PyObject * |
5053 | | os_openpty(PyObject *module, PyObject *Py_UNUSED(ignored)) |
5054 | 0 | { |
5055 | 0 | return os_openpty_impl(module); |
5056 | 0 | } |
5057 | | |
5058 | | #endif /* (defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX)) */ |
5059 | | |
5060 | | #if (defined(HAVE_LOGIN_TTY) || defined(HAVE_FALLBACK_LOGIN_TTY)) |
5061 | | |
5062 | | PyDoc_STRVAR(os_login_tty__doc__, |
5063 | | "login_tty($module, fd, /)\n" |
5064 | | "--\n" |
5065 | | "\n" |
5066 | | "Prepare the tty of which fd is a file descriptor for a new login session.\n" |
5067 | | "\n" |
5068 | | "Make the calling process a session leader; make the tty the\n" |
5069 | | "controlling tty, the stdin, the stdout, and the stderr of the\n" |
5070 | | "calling process; close fd."); |
5071 | | |
5072 | | #define OS_LOGIN_TTY_METHODDEF \ |
5073 | | {"login_tty", (PyCFunction)os_login_tty, METH_O, os_login_tty__doc__}, |
5074 | | |
5075 | | static PyObject * |
5076 | | os_login_tty_impl(PyObject *module, int fd); |
5077 | | |
5078 | | static PyObject * |
5079 | | os_login_tty(PyObject *module, PyObject *arg) |
5080 | 0 | { |
5081 | 0 | PyObject *return_value = NULL; |
5082 | 0 | int fd; |
5083 | |
|
5084 | 0 | fd = PyObject_AsFileDescriptor(arg); |
5085 | 0 | if (fd < 0) { |
5086 | 0 | goto exit; |
5087 | 0 | } |
5088 | 0 | return_value = os_login_tty_impl(module, fd); |
5089 | |
|
5090 | 0 | exit: |
5091 | 0 | return return_value; |
5092 | 0 | } |
5093 | | |
5094 | | #endif /* (defined(HAVE_LOGIN_TTY) || defined(HAVE_FALLBACK_LOGIN_TTY)) */ |
5095 | | |
5096 | | #if defined(HAVE_FORKPTY) |
5097 | | |
5098 | | PyDoc_STRVAR(os_forkpty__doc__, |
5099 | | "forkpty($module, /)\n" |
5100 | | "--\n" |
5101 | | "\n" |
5102 | | "Fork a new process with a new pseudo-terminal as controlling tty.\n" |
5103 | | "\n" |
5104 | | "Returns a tuple of (pid, master_fd).\n" |
5105 | | "Like fork(), return pid of 0 to the child process,\n" |
5106 | | "and pid of child to the parent process.\n" |
5107 | | "To both, return fd of newly opened pseudo-terminal."); |
5108 | | |
5109 | | #define OS_FORKPTY_METHODDEF \ |
5110 | | {"forkpty", (PyCFunction)os_forkpty, METH_NOARGS, os_forkpty__doc__}, |
5111 | | |
5112 | | static PyObject * |
5113 | | os_forkpty_impl(PyObject *module); |
5114 | | |
5115 | | static PyObject * |
5116 | | os_forkpty(PyObject *module, PyObject *Py_UNUSED(ignored)) |
5117 | 0 | { |
5118 | 0 | return os_forkpty_impl(module); |
5119 | 0 | } |
5120 | | |
5121 | | #endif /* defined(HAVE_FORKPTY) */ |
5122 | | |
5123 | | #if defined(HAVE_GETEGID) |
5124 | | |
5125 | | PyDoc_STRVAR(os_getegid__doc__, |
5126 | | "getegid($module, /)\n" |
5127 | | "--\n" |
5128 | | "\n" |
5129 | | "Return the current process\'s effective group id."); |
5130 | | |
5131 | | #define OS_GETEGID_METHODDEF \ |
5132 | | {"getegid", (PyCFunction)os_getegid, METH_NOARGS, os_getegid__doc__}, |
5133 | | |
5134 | | static PyObject * |
5135 | | os_getegid_impl(PyObject *module); |
5136 | | |
5137 | | static PyObject * |
5138 | | os_getegid(PyObject *module, PyObject *Py_UNUSED(ignored)) |
5139 | 16 | { |
5140 | 16 | return os_getegid_impl(module); |
5141 | 16 | } |
5142 | | |
5143 | | #endif /* defined(HAVE_GETEGID) */ |
5144 | | |
5145 | | #if defined(HAVE_GETEUID) |
5146 | | |
5147 | | PyDoc_STRVAR(os_geteuid__doc__, |
5148 | | "geteuid($module, /)\n" |
5149 | | "--\n" |
5150 | | "\n" |
5151 | | "Return the current process\'s effective user id."); |
5152 | | |
5153 | | #define OS_GETEUID_METHODDEF \ |
5154 | | {"geteuid", (PyCFunction)os_geteuid, METH_NOARGS, os_geteuid__doc__}, |
5155 | | |
5156 | | static PyObject * |
5157 | | os_geteuid_impl(PyObject *module); |
5158 | | |
5159 | | static PyObject * |
5160 | | os_geteuid(PyObject *module, PyObject *Py_UNUSED(ignored)) |
5161 | 16 | { |
5162 | 16 | return os_geteuid_impl(module); |
5163 | 16 | } |
5164 | | |
5165 | | #endif /* defined(HAVE_GETEUID) */ |
5166 | | |
5167 | | #if defined(HAVE_GETGID) |
5168 | | |
5169 | | PyDoc_STRVAR(os_getgid__doc__, |
5170 | | "getgid($module, /)\n" |
5171 | | "--\n" |
5172 | | "\n" |
5173 | | "Return the current process\'s group id."); |
5174 | | |
5175 | | #define OS_GETGID_METHODDEF \ |
5176 | | {"getgid", (PyCFunction)os_getgid, METH_NOARGS, os_getgid__doc__}, |
5177 | | |
5178 | | static PyObject * |
5179 | | os_getgid_impl(PyObject *module); |
5180 | | |
5181 | | static PyObject * |
5182 | | os_getgid(PyObject *module, PyObject *Py_UNUSED(ignored)) |
5183 | 16 | { |
5184 | 16 | return os_getgid_impl(module); |
5185 | 16 | } |
5186 | | |
5187 | | #endif /* defined(HAVE_GETGID) */ |
5188 | | |
5189 | | #if defined(HAVE_GETPID) |
5190 | | |
5191 | | PyDoc_STRVAR(os_getpid__doc__, |
5192 | | "getpid($module, /)\n" |
5193 | | "--\n" |
5194 | | "\n" |
5195 | | "Return the current process id."); |
5196 | | |
5197 | | #define OS_GETPID_METHODDEF \ |
5198 | | {"getpid", (PyCFunction)os_getpid, METH_NOARGS, os_getpid__doc__}, |
5199 | | |
5200 | | static PyObject * |
5201 | | os_getpid_impl(PyObject *module); |
5202 | | |
5203 | | static PyObject * |
5204 | | os_getpid(PyObject *module, PyObject *Py_UNUSED(ignored)) |
5205 | 0 | { |
5206 | 0 | return os_getpid_impl(module); |
5207 | 0 | } |
5208 | | |
5209 | | #endif /* defined(HAVE_GETPID) */ |
5210 | | |
5211 | | #if defined(HAVE_GETGROUPLIST) && defined(__APPLE__) |
5212 | | |
5213 | | PyDoc_STRVAR(os_getgrouplist__doc__, |
5214 | | "getgrouplist($module, user, group, /)\n" |
5215 | | "--\n" |
5216 | | "\n" |
5217 | | "Returns a list of groups to which a user belongs.\n" |
5218 | | "\n" |
5219 | | " user\n" |
5220 | | " username to lookup\n" |
5221 | | " group\n" |
5222 | | " base group id of the user"); |
5223 | | |
5224 | | #define OS_GETGROUPLIST_METHODDEF \ |
5225 | | {"getgrouplist", _PyCFunction_CAST(os_getgrouplist), METH_FASTCALL, os_getgrouplist__doc__}, |
5226 | | |
5227 | | static PyObject * |
5228 | | os_getgrouplist_impl(PyObject *module, const char *user, int basegid); |
5229 | | |
5230 | | static PyObject * |
5231 | | os_getgrouplist(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
5232 | | { |
5233 | | PyObject *return_value = NULL; |
5234 | | const char *user; |
5235 | | int basegid; |
5236 | | |
5237 | | if (!_PyArg_CheckPositional("getgrouplist", nargs, 2, 2)) { |
5238 | | goto exit; |
5239 | | } |
5240 | | if (!PyUnicode_Check(args[0])) { |
5241 | | _PyArg_BadArgument("getgrouplist", "argument 1", "str", args[0]); |
5242 | | goto exit; |
5243 | | } |
5244 | | Py_ssize_t user_length; |
5245 | | user = PyUnicode_AsUTF8AndSize(args[0], &user_length); |
5246 | | if (user == NULL) { |
5247 | | goto exit; |
5248 | | } |
5249 | | if (strlen(user) != (size_t)user_length) { |
5250 | | PyErr_SetString(PyExc_ValueError, "embedded null character"); |
5251 | | goto exit; |
5252 | | } |
5253 | | basegid = PyLong_AsInt(args[1]); |
5254 | | if (basegid == -1 && PyErr_Occurred()) { |
5255 | | goto exit; |
5256 | | } |
5257 | | return_value = os_getgrouplist_impl(module, user, basegid); |
5258 | | |
5259 | | exit: |
5260 | | return return_value; |
5261 | | } |
5262 | | |
5263 | | #endif /* defined(HAVE_GETGROUPLIST) && defined(__APPLE__) */ |
5264 | | |
5265 | | #if defined(HAVE_GETGROUPLIST) && !defined(__APPLE__) |
5266 | | |
5267 | | PyDoc_STRVAR(os_getgrouplist__doc__, |
5268 | | "getgrouplist($module, user, group, /)\n" |
5269 | | "--\n" |
5270 | | "\n" |
5271 | | "Returns a list of groups to which a user belongs.\n" |
5272 | | "\n" |
5273 | | " user\n" |
5274 | | " username to lookup\n" |
5275 | | " group\n" |
5276 | | " base group id of the user"); |
5277 | | |
5278 | | #define OS_GETGROUPLIST_METHODDEF \ |
5279 | | {"getgrouplist", _PyCFunction_CAST(os_getgrouplist), METH_FASTCALL, os_getgrouplist__doc__}, |
5280 | | |
5281 | | static PyObject * |
5282 | | os_getgrouplist_impl(PyObject *module, const char *user, gid_t basegid); |
5283 | | |
5284 | | static PyObject * |
5285 | | os_getgrouplist(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
5286 | 0 | { |
5287 | 0 | PyObject *return_value = NULL; |
5288 | 0 | const char *user; |
5289 | 0 | gid_t basegid; |
5290 | |
|
5291 | 0 | if (!_PyArg_CheckPositional("getgrouplist", nargs, 2, 2)) { |
5292 | 0 | goto exit; |
5293 | 0 | } |
5294 | 0 | if (!PyUnicode_Check(args[0])) { |
5295 | 0 | _PyArg_BadArgument("getgrouplist", "argument 1", "str", args[0]); |
5296 | 0 | goto exit; |
5297 | 0 | } |
5298 | 0 | Py_ssize_t user_length; |
5299 | 0 | user = PyUnicode_AsUTF8AndSize(args[0], &user_length); |
5300 | 0 | if (user == NULL) { |
5301 | 0 | goto exit; |
5302 | 0 | } |
5303 | 0 | if (strlen(user) != (size_t)user_length) { |
5304 | 0 | PyErr_SetString(PyExc_ValueError, "embedded null character"); |
5305 | 0 | goto exit; |
5306 | 0 | } |
5307 | 0 | if (!_Py_Gid_Converter(args[1], &basegid)) { |
5308 | 0 | goto exit; |
5309 | 0 | } |
5310 | 0 | return_value = os_getgrouplist_impl(module, user, basegid); |
5311 | |
|
5312 | 0 | exit: |
5313 | 0 | return return_value; |
5314 | 0 | } |
5315 | | |
5316 | | #endif /* defined(HAVE_GETGROUPLIST) && !defined(__APPLE__) */ |
5317 | | |
5318 | | #if defined(HAVE_GETGROUPS) |
5319 | | |
5320 | | PyDoc_STRVAR(os_getgroups__doc__, |
5321 | | "getgroups($module, /)\n" |
5322 | | "--\n" |
5323 | | "\n" |
5324 | | "Return list of supplemental group IDs for the process."); |
5325 | | |
5326 | | #define OS_GETGROUPS_METHODDEF \ |
5327 | | {"getgroups", (PyCFunction)os_getgroups, METH_NOARGS, os_getgroups__doc__}, |
5328 | | |
5329 | | static PyObject * |
5330 | | os_getgroups_impl(PyObject *module); |
5331 | | |
5332 | | static PyObject * |
5333 | | os_getgroups(PyObject *module, PyObject *Py_UNUSED(ignored)) |
5334 | 0 | { |
5335 | 0 | return os_getgroups_impl(module); |
5336 | 0 | } |
5337 | | |
5338 | | #endif /* defined(HAVE_GETGROUPS) */ |
5339 | | |
5340 | | #if defined(HAVE_INITGROUPS) && defined(__APPLE__) |
5341 | | |
5342 | | PyDoc_STRVAR(os_initgroups__doc__, |
5343 | | "initgroups($module, username, gid, /)\n" |
5344 | | "--\n" |
5345 | | "\n" |
5346 | | "Initialize the group access list.\n" |
5347 | | "\n" |
5348 | | "Call the system initgroups() to initialize the group access list with all of\n" |
5349 | | "the groups of which the specified username is a member, plus the specified\n" |
5350 | | "group id."); |
5351 | | |
5352 | | #define OS_INITGROUPS_METHODDEF \ |
5353 | | {"initgroups", _PyCFunction_CAST(os_initgroups), METH_FASTCALL, os_initgroups__doc__}, |
5354 | | |
5355 | | static PyObject * |
5356 | | os_initgroups_impl(PyObject *module, PyObject *oname, int gid); |
5357 | | |
5358 | | static PyObject * |
5359 | | os_initgroups(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
5360 | | { |
5361 | | PyObject *return_value = NULL; |
5362 | | PyObject *oname = NULL; |
5363 | | int gid; |
5364 | | |
5365 | | if (!_PyArg_CheckPositional("initgroups", nargs, 2, 2)) { |
5366 | | goto exit; |
5367 | | } |
5368 | | if (!PyUnicode_FSConverter(args[0], &oname)) { |
5369 | | goto exit; |
5370 | | } |
5371 | | gid = PyLong_AsInt(args[1]); |
5372 | | if (gid == -1 && PyErr_Occurred()) { |
5373 | | goto exit; |
5374 | | } |
5375 | | return_value = os_initgroups_impl(module, oname, gid); |
5376 | | |
5377 | | exit: |
5378 | | /* Cleanup for oname */ |
5379 | | Py_XDECREF(oname); |
5380 | | |
5381 | | return return_value; |
5382 | | } |
5383 | | |
5384 | | #endif /* defined(HAVE_INITGROUPS) && defined(__APPLE__) */ |
5385 | | |
5386 | | #if defined(HAVE_INITGROUPS) && !defined(__APPLE__) |
5387 | | |
5388 | | PyDoc_STRVAR(os_initgroups__doc__, |
5389 | | "initgroups($module, username, gid, /)\n" |
5390 | | "--\n" |
5391 | | "\n" |
5392 | | "Initialize the group access list.\n" |
5393 | | "\n" |
5394 | | "Call the system initgroups() to initialize the group access list with all of\n" |
5395 | | "the groups of which the specified username is a member, plus the specified\n" |
5396 | | "group id."); |
5397 | | |
5398 | | #define OS_INITGROUPS_METHODDEF \ |
5399 | | {"initgroups", _PyCFunction_CAST(os_initgroups), METH_FASTCALL, os_initgroups__doc__}, |
5400 | | |
5401 | | static PyObject * |
5402 | | os_initgroups_impl(PyObject *module, PyObject *oname, gid_t gid); |
5403 | | |
5404 | | static PyObject * |
5405 | | os_initgroups(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
5406 | 0 | { |
5407 | 0 | PyObject *return_value = NULL; |
5408 | 0 | PyObject *oname = NULL; |
5409 | 0 | gid_t gid; |
5410 | |
|
5411 | 0 | if (!_PyArg_CheckPositional("initgroups", nargs, 2, 2)) { |
5412 | 0 | goto exit; |
5413 | 0 | } |
5414 | 0 | if (!PyUnicode_FSConverter(args[0], &oname)) { |
5415 | 0 | goto exit; |
5416 | 0 | } |
5417 | 0 | if (!_Py_Gid_Converter(args[1], &gid)) { |
5418 | 0 | goto exit; |
5419 | 0 | } |
5420 | 0 | return_value = os_initgroups_impl(module, oname, gid); |
5421 | |
|
5422 | 0 | exit: |
5423 | | /* Cleanup for oname */ |
5424 | 0 | Py_XDECREF(oname); |
5425 | |
|
5426 | 0 | return return_value; |
5427 | 0 | } |
5428 | | |
5429 | | #endif /* defined(HAVE_INITGROUPS) && !defined(__APPLE__) */ |
5430 | | |
5431 | | #if defined(HAVE_GETPGID) |
5432 | | |
5433 | | PyDoc_STRVAR(os_getpgid__doc__, |
5434 | | "getpgid($module, /, pid)\n" |
5435 | | "--\n" |
5436 | | "\n" |
5437 | | "Call the system call getpgid(), and return the result."); |
5438 | | |
5439 | | #define OS_GETPGID_METHODDEF \ |
5440 | | {"getpgid", _PyCFunction_CAST(os_getpgid), METH_FASTCALL|METH_KEYWORDS, os_getpgid__doc__}, |
5441 | | |
5442 | | static PyObject * |
5443 | | os_getpgid_impl(PyObject *module, pid_t pid); |
5444 | | |
5445 | | static PyObject * |
5446 | | os_getpgid(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
5447 | 0 | { |
5448 | 0 | PyObject *return_value = NULL; |
5449 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
5450 | |
|
5451 | 0 | #define NUM_KEYWORDS 1 |
5452 | 0 | static struct { |
5453 | 0 | PyGC_Head _this_is_not_used; |
5454 | 0 | PyObject_VAR_HEAD |
5455 | 0 | Py_hash_t ob_hash; |
5456 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
5457 | 0 | } _kwtuple = { |
5458 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
5459 | 0 | .ob_hash = -1, |
5460 | 0 | .ob_item = { &_Py_ID(pid), }, |
5461 | 0 | }; |
5462 | 0 | #undef NUM_KEYWORDS |
5463 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
5464 | |
|
5465 | | #else // !Py_BUILD_CORE |
5466 | | # define KWTUPLE NULL |
5467 | | #endif // !Py_BUILD_CORE |
5468 | |
|
5469 | 0 | static const char * const _keywords[] = {"pid", NULL}; |
5470 | 0 | static _PyArg_Parser _parser = { |
5471 | 0 | .keywords = _keywords, |
5472 | 0 | .fname = "getpgid", |
5473 | 0 | .kwtuple = KWTUPLE, |
5474 | 0 | }; |
5475 | 0 | #undef KWTUPLE |
5476 | 0 | PyObject *argsbuf[1]; |
5477 | 0 | pid_t pid; |
5478 | |
|
5479 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
5480 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
5481 | 0 | if (!args) { |
5482 | 0 | goto exit; |
5483 | 0 | } |
5484 | 0 | pid = PyLong_AsPid(args[0]); |
5485 | 0 | if (pid == (pid_t)(-1) && PyErr_Occurred()) { |
5486 | 0 | goto exit; |
5487 | 0 | } |
5488 | 0 | return_value = os_getpgid_impl(module, pid); |
5489 | |
|
5490 | 0 | exit: |
5491 | 0 | return return_value; |
5492 | 0 | } |
5493 | | |
5494 | | #endif /* defined(HAVE_GETPGID) */ |
5495 | | |
5496 | | #if defined(HAVE_GETPGRP) |
5497 | | |
5498 | | PyDoc_STRVAR(os_getpgrp__doc__, |
5499 | | "getpgrp($module, /)\n" |
5500 | | "--\n" |
5501 | | "\n" |
5502 | | "Return the current process group id."); |
5503 | | |
5504 | | #define OS_GETPGRP_METHODDEF \ |
5505 | | {"getpgrp", (PyCFunction)os_getpgrp, METH_NOARGS, os_getpgrp__doc__}, |
5506 | | |
5507 | | static PyObject * |
5508 | | os_getpgrp_impl(PyObject *module); |
5509 | | |
5510 | | static PyObject * |
5511 | | os_getpgrp(PyObject *module, PyObject *Py_UNUSED(ignored)) |
5512 | 0 | { |
5513 | 0 | return os_getpgrp_impl(module); |
5514 | 0 | } |
5515 | | |
5516 | | #endif /* defined(HAVE_GETPGRP) */ |
5517 | | |
5518 | | #if defined(HAVE_SETPGRP) |
5519 | | |
5520 | | PyDoc_STRVAR(os_setpgrp__doc__, |
5521 | | "setpgrp($module, /)\n" |
5522 | | "--\n" |
5523 | | "\n" |
5524 | | "Make the current process the leader of its process group."); |
5525 | | |
5526 | | #define OS_SETPGRP_METHODDEF \ |
5527 | | {"setpgrp", (PyCFunction)os_setpgrp, METH_NOARGS, os_setpgrp__doc__}, |
5528 | | |
5529 | | static PyObject * |
5530 | | os_setpgrp_impl(PyObject *module); |
5531 | | |
5532 | | static PyObject * |
5533 | | os_setpgrp(PyObject *module, PyObject *Py_UNUSED(ignored)) |
5534 | 0 | { |
5535 | 0 | return os_setpgrp_impl(module); |
5536 | 0 | } |
5537 | | |
5538 | | #endif /* defined(HAVE_SETPGRP) */ |
5539 | | |
5540 | | #if defined(HAVE_GETPPID) |
5541 | | |
5542 | | PyDoc_STRVAR(os_getppid__doc__, |
5543 | | "getppid($module, /)\n" |
5544 | | "--\n" |
5545 | | "\n" |
5546 | | "Return the parent\'s process id.\n" |
5547 | | "\n" |
5548 | | "If the parent process has already exited, Windows machines will still\n" |
5549 | | "return its id; others systems will return the id of the \'init\' process (1)."); |
5550 | | |
5551 | | #define OS_GETPPID_METHODDEF \ |
5552 | | {"getppid", (PyCFunction)os_getppid, METH_NOARGS, os_getppid__doc__}, |
5553 | | |
5554 | | static PyObject * |
5555 | | os_getppid_impl(PyObject *module); |
5556 | | |
5557 | | static PyObject * |
5558 | | os_getppid(PyObject *module, PyObject *Py_UNUSED(ignored)) |
5559 | 0 | { |
5560 | 0 | return os_getppid_impl(module); |
5561 | 0 | } |
5562 | | |
5563 | | #endif /* defined(HAVE_GETPPID) */ |
5564 | | |
5565 | | #if defined(HAVE_GETLOGIN) |
5566 | | |
5567 | | PyDoc_STRVAR(os_getlogin__doc__, |
5568 | | "getlogin($module, /)\n" |
5569 | | "--\n" |
5570 | | "\n" |
5571 | | "Return the actual login name."); |
5572 | | |
5573 | | #define OS_GETLOGIN_METHODDEF \ |
5574 | | {"getlogin", (PyCFunction)os_getlogin, METH_NOARGS, os_getlogin__doc__}, |
5575 | | |
5576 | | static PyObject * |
5577 | | os_getlogin_impl(PyObject *module); |
5578 | | |
5579 | | static PyObject * |
5580 | | os_getlogin(PyObject *module, PyObject *Py_UNUSED(ignored)) |
5581 | 0 | { |
5582 | 0 | return os_getlogin_impl(module); |
5583 | 0 | } |
5584 | | |
5585 | | #endif /* defined(HAVE_GETLOGIN) */ |
5586 | | |
5587 | | #if defined(HAVE_GETUID) |
5588 | | |
5589 | | PyDoc_STRVAR(os_getuid__doc__, |
5590 | | "getuid($module, /)\n" |
5591 | | "--\n" |
5592 | | "\n" |
5593 | | "Return the current process\'s user id."); |
5594 | | |
5595 | | #define OS_GETUID_METHODDEF \ |
5596 | | {"getuid", (PyCFunction)os_getuid, METH_NOARGS, os_getuid__doc__}, |
5597 | | |
5598 | | static PyObject * |
5599 | | os_getuid_impl(PyObject *module); |
5600 | | |
5601 | | static PyObject * |
5602 | | os_getuid(PyObject *module, PyObject *Py_UNUSED(ignored)) |
5603 | 16 | { |
5604 | 16 | return os_getuid_impl(module); |
5605 | 16 | } |
5606 | | |
5607 | | #endif /* defined(HAVE_GETUID) */ |
5608 | | |
5609 | | #if defined(HAVE_KILL) |
5610 | | |
5611 | | PyDoc_STRVAR(os_kill__doc__, |
5612 | | "kill($module, pid, signal, /)\n" |
5613 | | "--\n" |
5614 | | "\n" |
5615 | | "Kill a process with a signal."); |
5616 | | |
5617 | | #define OS_KILL_METHODDEF \ |
5618 | | {"kill", _PyCFunction_CAST(os_kill), METH_FASTCALL, os_kill__doc__}, |
5619 | | |
5620 | | static PyObject * |
5621 | | os_kill_impl(PyObject *module, pid_t pid, Py_ssize_t signal); |
5622 | | |
5623 | | static PyObject * |
5624 | | os_kill(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
5625 | 0 | { |
5626 | 0 | PyObject *return_value = NULL; |
5627 | 0 | pid_t pid; |
5628 | 0 | Py_ssize_t signal; |
5629 | |
|
5630 | 0 | if (!_PyArg_CheckPositional("kill", nargs, 2, 2)) { |
5631 | 0 | goto exit; |
5632 | 0 | } |
5633 | 0 | pid = PyLong_AsPid(args[0]); |
5634 | 0 | if (pid == (pid_t)(-1) && PyErr_Occurred()) { |
5635 | 0 | goto exit; |
5636 | 0 | } |
5637 | 0 | { |
5638 | 0 | Py_ssize_t ival = -1; |
5639 | 0 | PyObject *iobj = _PyNumber_Index(args[1]); |
5640 | 0 | if (iobj != NULL) { |
5641 | 0 | ival = PyLong_AsSsize_t(iobj); |
5642 | 0 | Py_DECREF(iobj); |
5643 | 0 | } |
5644 | 0 | if (ival == -1 && PyErr_Occurred()) { |
5645 | 0 | goto exit; |
5646 | 0 | } |
5647 | 0 | signal = ival; |
5648 | 0 | } |
5649 | 0 | return_value = os_kill_impl(module, pid, signal); |
5650 | |
|
5651 | 0 | exit: |
5652 | 0 | return return_value; |
5653 | 0 | } |
5654 | | |
5655 | | #endif /* defined(HAVE_KILL) */ |
5656 | | |
5657 | | #if defined(HAVE_KILLPG) |
5658 | | |
5659 | | PyDoc_STRVAR(os_killpg__doc__, |
5660 | | "killpg($module, pgid, signal, /)\n" |
5661 | | "--\n" |
5662 | | "\n" |
5663 | | "Kill a process group with a signal."); |
5664 | | |
5665 | | #define OS_KILLPG_METHODDEF \ |
5666 | | {"killpg", _PyCFunction_CAST(os_killpg), METH_FASTCALL, os_killpg__doc__}, |
5667 | | |
5668 | | static PyObject * |
5669 | | os_killpg_impl(PyObject *module, pid_t pgid, int signal); |
5670 | | |
5671 | | static PyObject * |
5672 | | os_killpg(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
5673 | 0 | { |
5674 | 0 | PyObject *return_value = NULL; |
5675 | 0 | pid_t pgid; |
5676 | 0 | int signal; |
5677 | |
|
5678 | 0 | if (!_PyArg_CheckPositional("killpg", nargs, 2, 2)) { |
5679 | 0 | goto exit; |
5680 | 0 | } |
5681 | 0 | pgid = PyLong_AsPid(args[0]); |
5682 | 0 | if (pgid == (pid_t)(-1) && PyErr_Occurred()) { |
5683 | 0 | goto exit; |
5684 | 0 | } |
5685 | 0 | signal = PyLong_AsInt(args[1]); |
5686 | 0 | if (signal == -1 && PyErr_Occurred()) { |
5687 | 0 | goto exit; |
5688 | 0 | } |
5689 | 0 | return_value = os_killpg_impl(module, pgid, signal); |
5690 | |
|
5691 | 0 | exit: |
5692 | 0 | return return_value; |
5693 | 0 | } |
5694 | | |
5695 | | #endif /* defined(HAVE_KILLPG) */ |
5696 | | |
5697 | | #if defined(HAVE_PLOCK) |
5698 | | |
5699 | | PyDoc_STRVAR(os_plock__doc__, |
5700 | | "plock($module, op, /)\n" |
5701 | | "--\n" |
5702 | | "\n" |
5703 | | "Lock program segments into memory.\");"); |
5704 | | |
5705 | | #define OS_PLOCK_METHODDEF \ |
5706 | | {"plock", (PyCFunction)os_plock, METH_O, os_plock__doc__}, |
5707 | | |
5708 | | static PyObject * |
5709 | | os_plock_impl(PyObject *module, int op); |
5710 | | |
5711 | | static PyObject * |
5712 | | os_plock(PyObject *module, PyObject *arg) |
5713 | | { |
5714 | | PyObject *return_value = NULL; |
5715 | | int op; |
5716 | | |
5717 | | op = PyLong_AsInt(arg); |
5718 | | if (op == -1 && PyErr_Occurred()) { |
5719 | | goto exit; |
5720 | | } |
5721 | | return_value = os_plock_impl(module, op); |
5722 | | |
5723 | | exit: |
5724 | | return return_value; |
5725 | | } |
5726 | | |
5727 | | #endif /* defined(HAVE_PLOCK) */ |
5728 | | |
5729 | | #if defined(HAVE_SETUID) |
5730 | | |
5731 | | PyDoc_STRVAR(os_setuid__doc__, |
5732 | | "setuid($module, uid, /)\n" |
5733 | | "--\n" |
5734 | | "\n" |
5735 | | "Set the current process\'s user id."); |
5736 | | |
5737 | | #define OS_SETUID_METHODDEF \ |
5738 | | {"setuid", (PyCFunction)os_setuid, METH_O, os_setuid__doc__}, |
5739 | | |
5740 | | static PyObject * |
5741 | | os_setuid_impl(PyObject *module, uid_t uid); |
5742 | | |
5743 | | static PyObject * |
5744 | | os_setuid(PyObject *module, PyObject *arg) |
5745 | 0 | { |
5746 | 0 | PyObject *return_value = NULL; |
5747 | 0 | uid_t uid; |
5748 | |
|
5749 | 0 | if (!_Py_Uid_Converter(arg, &uid)) { |
5750 | 0 | goto exit; |
5751 | 0 | } |
5752 | 0 | return_value = os_setuid_impl(module, uid); |
5753 | |
|
5754 | 0 | exit: |
5755 | 0 | return return_value; |
5756 | 0 | } |
5757 | | |
5758 | | #endif /* defined(HAVE_SETUID) */ |
5759 | | |
5760 | | #if defined(HAVE_SETEUID) |
5761 | | |
5762 | | PyDoc_STRVAR(os_seteuid__doc__, |
5763 | | "seteuid($module, euid, /)\n" |
5764 | | "--\n" |
5765 | | "\n" |
5766 | | "Set the current process\'s effective user id."); |
5767 | | |
5768 | | #define OS_SETEUID_METHODDEF \ |
5769 | | {"seteuid", (PyCFunction)os_seteuid, METH_O, os_seteuid__doc__}, |
5770 | | |
5771 | | static PyObject * |
5772 | | os_seteuid_impl(PyObject *module, uid_t euid); |
5773 | | |
5774 | | static PyObject * |
5775 | | os_seteuid(PyObject *module, PyObject *arg) |
5776 | 0 | { |
5777 | 0 | PyObject *return_value = NULL; |
5778 | 0 | uid_t euid; |
5779 | |
|
5780 | 0 | if (!_Py_Uid_Converter(arg, &euid)) { |
5781 | 0 | goto exit; |
5782 | 0 | } |
5783 | 0 | return_value = os_seteuid_impl(module, euid); |
5784 | |
|
5785 | 0 | exit: |
5786 | 0 | return return_value; |
5787 | 0 | } |
5788 | | |
5789 | | #endif /* defined(HAVE_SETEUID) */ |
5790 | | |
5791 | | #if defined(HAVE_SETEGID) |
5792 | | |
5793 | | PyDoc_STRVAR(os_setegid__doc__, |
5794 | | "setegid($module, egid, /)\n" |
5795 | | "--\n" |
5796 | | "\n" |
5797 | | "Set the current process\'s effective group id."); |
5798 | | |
5799 | | #define OS_SETEGID_METHODDEF \ |
5800 | | {"setegid", (PyCFunction)os_setegid, METH_O, os_setegid__doc__}, |
5801 | | |
5802 | | static PyObject * |
5803 | | os_setegid_impl(PyObject *module, gid_t egid); |
5804 | | |
5805 | | static PyObject * |
5806 | | os_setegid(PyObject *module, PyObject *arg) |
5807 | 0 | { |
5808 | 0 | PyObject *return_value = NULL; |
5809 | 0 | gid_t egid; |
5810 | |
|
5811 | 0 | if (!_Py_Gid_Converter(arg, &egid)) { |
5812 | 0 | goto exit; |
5813 | 0 | } |
5814 | 0 | return_value = os_setegid_impl(module, egid); |
5815 | |
|
5816 | 0 | exit: |
5817 | 0 | return return_value; |
5818 | 0 | } |
5819 | | |
5820 | | #endif /* defined(HAVE_SETEGID) */ |
5821 | | |
5822 | | #if defined(HAVE_SETREUID) |
5823 | | |
5824 | | PyDoc_STRVAR(os_setreuid__doc__, |
5825 | | "setreuid($module, ruid, euid, /)\n" |
5826 | | "--\n" |
5827 | | "\n" |
5828 | | "Set the current process\'s real and effective user ids."); |
5829 | | |
5830 | | #define OS_SETREUID_METHODDEF \ |
5831 | | {"setreuid", _PyCFunction_CAST(os_setreuid), METH_FASTCALL, os_setreuid__doc__}, |
5832 | | |
5833 | | static PyObject * |
5834 | | os_setreuid_impl(PyObject *module, uid_t ruid, uid_t euid); |
5835 | | |
5836 | | static PyObject * |
5837 | | os_setreuid(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
5838 | 0 | { |
5839 | 0 | PyObject *return_value = NULL; |
5840 | 0 | uid_t ruid; |
5841 | 0 | uid_t euid; |
5842 | |
|
5843 | 0 | if (!_PyArg_CheckPositional("setreuid", nargs, 2, 2)) { |
5844 | 0 | goto exit; |
5845 | 0 | } |
5846 | 0 | if (!_Py_Uid_Converter(args[0], &ruid)) { |
5847 | 0 | goto exit; |
5848 | 0 | } |
5849 | 0 | if (!_Py_Uid_Converter(args[1], &euid)) { |
5850 | 0 | goto exit; |
5851 | 0 | } |
5852 | 0 | return_value = os_setreuid_impl(module, ruid, euid); |
5853 | |
|
5854 | 0 | exit: |
5855 | 0 | return return_value; |
5856 | 0 | } |
5857 | | |
5858 | | #endif /* defined(HAVE_SETREUID) */ |
5859 | | |
5860 | | #if defined(HAVE_SETREGID) |
5861 | | |
5862 | | PyDoc_STRVAR(os_setregid__doc__, |
5863 | | "setregid($module, rgid, egid, /)\n" |
5864 | | "--\n" |
5865 | | "\n" |
5866 | | "Set the current process\'s real and effective group ids."); |
5867 | | |
5868 | | #define OS_SETREGID_METHODDEF \ |
5869 | | {"setregid", _PyCFunction_CAST(os_setregid), METH_FASTCALL, os_setregid__doc__}, |
5870 | | |
5871 | | static PyObject * |
5872 | | os_setregid_impl(PyObject *module, gid_t rgid, gid_t egid); |
5873 | | |
5874 | | static PyObject * |
5875 | | os_setregid(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
5876 | 0 | { |
5877 | 0 | PyObject *return_value = NULL; |
5878 | 0 | gid_t rgid; |
5879 | 0 | gid_t egid; |
5880 | |
|
5881 | 0 | if (!_PyArg_CheckPositional("setregid", nargs, 2, 2)) { |
5882 | 0 | goto exit; |
5883 | 0 | } |
5884 | 0 | if (!_Py_Gid_Converter(args[0], &rgid)) { |
5885 | 0 | goto exit; |
5886 | 0 | } |
5887 | 0 | if (!_Py_Gid_Converter(args[1], &egid)) { |
5888 | 0 | goto exit; |
5889 | 0 | } |
5890 | 0 | return_value = os_setregid_impl(module, rgid, egid); |
5891 | |
|
5892 | 0 | exit: |
5893 | 0 | return return_value; |
5894 | 0 | } |
5895 | | |
5896 | | #endif /* defined(HAVE_SETREGID) */ |
5897 | | |
5898 | | #if defined(HAVE_SETGID) |
5899 | | |
5900 | | PyDoc_STRVAR(os_setgid__doc__, |
5901 | | "setgid($module, gid, /)\n" |
5902 | | "--\n" |
5903 | | "\n" |
5904 | | "Set the current process\'s group id."); |
5905 | | |
5906 | | #define OS_SETGID_METHODDEF \ |
5907 | | {"setgid", (PyCFunction)os_setgid, METH_O, os_setgid__doc__}, |
5908 | | |
5909 | | static PyObject * |
5910 | | os_setgid_impl(PyObject *module, gid_t gid); |
5911 | | |
5912 | | static PyObject * |
5913 | | os_setgid(PyObject *module, PyObject *arg) |
5914 | 0 | { |
5915 | 0 | PyObject *return_value = NULL; |
5916 | 0 | gid_t gid; |
5917 | |
|
5918 | 0 | if (!_Py_Gid_Converter(arg, &gid)) { |
5919 | 0 | goto exit; |
5920 | 0 | } |
5921 | 0 | return_value = os_setgid_impl(module, gid); |
5922 | |
|
5923 | 0 | exit: |
5924 | 0 | return return_value; |
5925 | 0 | } |
5926 | | |
5927 | | #endif /* defined(HAVE_SETGID) */ |
5928 | | |
5929 | | #if defined(HAVE_SETGROUPS) |
5930 | | |
5931 | | PyDoc_STRVAR(os_setgroups__doc__, |
5932 | | "setgroups($module, groups, /)\n" |
5933 | | "--\n" |
5934 | | "\n" |
5935 | | "Set the groups of the current process to list."); |
5936 | | |
5937 | | #define OS_SETGROUPS_METHODDEF \ |
5938 | | {"setgroups", (PyCFunction)os_setgroups, METH_O, os_setgroups__doc__}, |
5939 | | |
5940 | | #endif /* defined(HAVE_SETGROUPS) */ |
5941 | | |
5942 | | #if defined(HAVE_WAIT3) |
5943 | | |
5944 | | PyDoc_STRVAR(os_wait3__doc__, |
5945 | | "wait3($module, /, options)\n" |
5946 | | "--\n" |
5947 | | "\n" |
5948 | | "Wait for completion of a child process.\n" |
5949 | | "\n" |
5950 | | "Returns a tuple of information about the child process:\n" |
5951 | | " (pid, status, rusage)"); |
5952 | | |
5953 | | #define OS_WAIT3_METHODDEF \ |
5954 | | {"wait3", _PyCFunction_CAST(os_wait3), METH_FASTCALL|METH_KEYWORDS, os_wait3__doc__}, |
5955 | | |
5956 | | static PyObject * |
5957 | | os_wait3_impl(PyObject *module, int options); |
5958 | | |
5959 | | static PyObject * |
5960 | | os_wait3(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
5961 | 0 | { |
5962 | 0 | PyObject *return_value = NULL; |
5963 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
5964 | |
|
5965 | 0 | #define NUM_KEYWORDS 1 |
5966 | 0 | static struct { |
5967 | 0 | PyGC_Head _this_is_not_used; |
5968 | 0 | PyObject_VAR_HEAD |
5969 | 0 | Py_hash_t ob_hash; |
5970 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
5971 | 0 | } _kwtuple = { |
5972 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
5973 | 0 | .ob_hash = -1, |
5974 | 0 | .ob_item = { &_Py_ID(options), }, |
5975 | 0 | }; |
5976 | 0 | #undef NUM_KEYWORDS |
5977 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
5978 | |
|
5979 | | #else // !Py_BUILD_CORE |
5980 | | # define KWTUPLE NULL |
5981 | | #endif // !Py_BUILD_CORE |
5982 | |
|
5983 | 0 | static const char * const _keywords[] = {"options", NULL}; |
5984 | 0 | static _PyArg_Parser _parser = { |
5985 | 0 | .keywords = _keywords, |
5986 | 0 | .fname = "wait3", |
5987 | 0 | .kwtuple = KWTUPLE, |
5988 | 0 | }; |
5989 | 0 | #undef KWTUPLE |
5990 | 0 | PyObject *argsbuf[1]; |
5991 | 0 | int options; |
5992 | |
|
5993 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
5994 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
5995 | 0 | if (!args) { |
5996 | 0 | goto exit; |
5997 | 0 | } |
5998 | 0 | options = PyLong_AsInt(args[0]); |
5999 | 0 | if (options == -1 && PyErr_Occurred()) { |
6000 | 0 | goto exit; |
6001 | 0 | } |
6002 | 0 | return_value = os_wait3_impl(module, options); |
6003 | |
|
6004 | 0 | exit: |
6005 | 0 | return return_value; |
6006 | 0 | } |
6007 | | |
6008 | | #endif /* defined(HAVE_WAIT3) */ |
6009 | | |
6010 | | #if defined(HAVE_WAIT4) |
6011 | | |
6012 | | PyDoc_STRVAR(os_wait4__doc__, |
6013 | | "wait4($module, /, pid, options)\n" |
6014 | | "--\n" |
6015 | | "\n" |
6016 | | "Wait for completion of a specific child process.\n" |
6017 | | "\n" |
6018 | | "Returns a tuple of information about the child process:\n" |
6019 | | " (pid, status, rusage)"); |
6020 | | |
6021 | | #define OS_WAIT4_METHODDEF \ |
6022 | | {"wait4", _PyCFunction_CAST(os_wait4), METH_FASTCALL|METH_KEYWORDS, os_wait4__doc__}, |
6023 | | |
6024 | | static PyObject * |
6025 | | os_wait4_impl(PyObject *module, pid_t pid, int options); |
6026 | | |
6027 | | static PyObject * |
6028 | | os_wait4(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
6029 | 0 | { |
6030 | 0 | PyObject *return_value = NULL; |
6031 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
6032 | |
|
6033 | 0 | #define NUM_KEYWORDS 2 |
6034 | 0 | static struct { |
6035 | 0 | PyGC_Head _this_is_not_used; |
6036 | 0 | PyObject_VAR_HEAD |
6037 | 0 | Py_hash_t ob_hash; |
6038 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
6039 | 0 | } _kwtuple = { |
6040 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
6041 | 0 | .ob_hash = -1, |
6042 | 0 | .ob_item = { &_Py_ID(pid), &_Py_ID(options), }, |
6043 | 0 | }; |
6044 | 0 | #undef NUM_KEYWORDS |
6045 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
6046 | |
|
6047 | | #else // !Py_BUILD_CORE |
6048 | | # define KWTUPLE NULL |
6049 | | #endif // !Py_BUILD_CORE |
6050 | |
|
6051 | 0 | static const char * const _keywords[] = {"pid", "options", NULL}; |
6052 | 0 | static _PyArg_Parser _parser = { |
6053 | 0 | .keywords = _keywords, |
6054 | 0 | .fname = "wait4", |
6055 | 0 | .kwtuple = KWTUPLE, |
6056 | 0 | }; |
6057 | 0 | #undef KWTUPLE |
6058 | 0 | PyObject *argsbuf[2]; |
6059 | 0 | pid_t pid; |
6060 | 0 | int options; |
6061 | |
|
6062 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
6063 | 0 | /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
6064 | 0 | if (!args) { |
6065 | 0 | goto exit; |
6066 | 0 | } |
6067 | 0 | pid = PyLong_AsPid(args[0]); |
6068 | 0 | if (pid == (pid_t)(-1) && PyErr_Occurred()) { |
6069 | 0 | goto exit; |
6070 | 0 | } |
6071 | 0 | options = PyLong_AsInt(args[1]); |
6072 | 0 | if (options == -1 && PyErr_Occurred()) { |
6073 | 0 | goto exit; |
6074 | 0 | } |
6075 | 0 | return_value = os_wait4_impl(module, pid, options); |
6076 | |
|
6077 | 0 | exit: |
6078 | 0 | return return_value; |
6079 | 0 | } |
6080 | | |
6081 | | #endif /* defined(HAVE_WAIT4) */ |
6082 | | |
6083 | | #if defined(HAVE_WAITID) |
6084 | | |
6085 | | PyDoc_STRVAR(os_waitid__doc__, |
6086 | | "waitid($module, idtype, id, options, /)\n" |
6087 | | "--\n" |
6088 | | "\n" |
6089 | | "Returns the result of waiting for a process or processes.\n" |
6090 | | "\n" |
6091 | | " idtype\n" |
6092 | | " Must be one of be P_PID, P_PGID or P_ALL.\n" |
6093 | | " id\n" |
6094 | | " The id to wait on.\n" |
6095 | | " options\n" |
6096 | | " Constructed from the ORing of one or more of WEXITED, WSTOPPED\n" |
6097 | | " or WCONTINUED and additionally may be ORed with WNOHANG or WNOWAIT.\n" |
6098 | | "\n" |
6099 | | "Returns either waitid_result or None if WNOHANG is specified and there are\n" |
6100 | | "no children in a waitable state."); |
6101 | | |
6102 | | #define OS_WAITID_METHODDEF \ |
6103 | | {"waitid", _PyCFunction_CAST(os_waitid), METH_FASTCALL, os_waitid__doc__}, |
6104 | | |
6105 | | static PyObject * |
6106 | | os_waitid_impl(PyObject *module, idtype_t idtype, id_t id, int options); |
6107 | | |
6108 | | static PyObject * |
6109 | | os_waitid(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
6110 | 0 | { |
6111 | 0 | PyObject *return_value = NULL; |
6112 | 0 | idtype_t idtype; |
6113 | 0 | id_t id; |
6114 | 0 | int options; |
6115 | |
|
6116 | 0 | if (!_PyArg_CheckPositional("waitid", nargs, 3, 3)) { |
6117 | 0 | goto exit; |
6118 | 0 | } |
6119 | 0 | if (!idtype_t_converter(args[0], &idtype)) { |
6120 | 0 | goto exit; |
6121 | 0 | } |
6122 | 0 | id = (id_t)PyLong_AsPid(args[1]); |
6123 | 0 | if (id == (id_t)(-1) && PyErr_Occurred()) { |
6124 | 0 | goto exit; |
6125 | 0 | } |
6126 | 0 | options = PyLong_AsInt(args[2]); |
6127 | 0 | if (options == -1 && PyErr_Occurred()) { |
6128 | 0 | goto exit; |
6129 | 0 | } |
6130 | 0 | return_value = os_waitid_impl(module, idtype, id, options); |
6131 | |
|
6132 | 0 | exit: |
6133 | 0 | return return_value; |
6134 | 0 | } |
6135 | | |
6136 | | #endif /* defined(HAVE_WAITID) */ |
6137 | | |
6138 | | #if defined(HAVE_WAITPID) |
6139 | | |
6140 | | PyDoc_STRVAR(os_waitpid__doc__, |
6141 | | "waitpid($module, pid, options, /)\n" |
6142 | | "--\n" |
6143 | | "\n" |
6144 | | "Wait for completion of a given child process.\n" |
6145 | | "\n" |
6146 | | "Returns a tuple of information regarding the child process:\n" |
6147 | | " (pid, status)\n" |
6148 | | "\n" |
6149 | | "The options argument is ignored on Windows."); |
6150 | | |
6151 | | #define OS_WAITPID_METHODDEF \ |
6152 | | {"waitpid", _PyCFunction_CAST(os_waitpid), METH_FASTCALL, os_waitpid__doc__}, |
6153 | | |
6154 | | static PyObject * |
6155 | | os_waitpid_impl(PyObject *module, pid_t pid, int options); |
6156 | | |
6157 | | static PyObject * |
6158 | | os_waitpid(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
6159 | 0 | { |
6160 | 0 | PyObject *return_value = NULL; |
6161 | 0 | pid_t pid; |
6162 | 0 | int options; |
6163 | |
|
6164 | 0 | if (!_PyArg_CheckPositional("waitpid", nargs, 2, 2)) { |
6165 | 0 | goto exit; |
6166 | 0 | } |
6167 | 0 | pid = PyLong_AsPid(args[0]); |
6168 | 0 | if (pid == (pid_t)(-1) && PyErr_Occurred()) { |
6169 | 0 | goto exit; |
6170 | 0 | } |
6171 | 0 | options = PyLong_AsInt(args[1]); |
6172 | 0 | if (options == -1 && PyErr_Occurred()) { |
6173 | 0 | goto exit; |
6174 | 0 | } |
6175 | 0 | return_value = os_waitpid_impl(module, pid, options); |
6176 | |
|
6177 | 0 | exit: |
6178 | 0 | return return_value; |
6179 | 0 | } |
6180 | | |
6181 | | #endif /* defined(HAVE_WAITPID) */ |
6182 | | |
6183 | | #if !defined(HAVE_WAITPID) && defined(HAVE_CWAIT) |
6184 | | |
6185 | | PyDoc_STRVAR(os_waitpid__doc__, |
6186 | | "waitpid($module, pid, options, /)\n" |
6187 | | "--\n" |
6188 | | "\n" |
6189 | | "Wait for completion of a given process.\n" |
6190 | | "\n" |
6191 | | "Returns a tuple of information regarding the process:\n" |
6192 | | " (pid, status << 8)\n" |
6193 | | "\n" |
6194 | | "The options argument is ignored on Windows."); |
6195 | | |
6196 | | #define OS_WAITPID_METHODDEF \ |
6197 | | {"waitpid", _PyCFunction_CAST(os_waitpid), METH_FASTCALL, os_waitpid__doc__}, |
6198 | | |
6199 | | static PyObject * |
6200 | | os_waitpid_impl(PyObject *module, intptr_t pid, int options); |
6201 | | |
6202 | | static PyObject * |
6203 | | os_waitpid(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
6204 | | { |
6205 | | PyObject *return_value = NULL; |
6206 | | intptr_t pid; |
6207 | | int options; |
6208 | | |
6209 | | if (!_PyArg_CheckPositional("waitpid", nargs, 2, 2)) { |
6210 | | goto exit; |
6211 | | } |
6212 | | pid = (intptr_t)PyLong_AsVoidPtr(args[0]); |
6213 | | if (!pid && PyErr_Occurred()) { |
6214 | | goto exit; |
6215 | | } |
6216 | | options = PyLong_AsInt(args[1]); |
6217 | | if (options == -1 && PyErr_Occurred()) { |
6218 | | goto exit; |
6219 | | } |
6220 | | return_value = os_waitpid_impl(module, pid, options); |
6221 | | |
6222 | | exit: |
6223 | | return return_value; |
6224 | | } |
6225 | | |
6226 | | #endif /* !defined(HAVE_WAITPID) && defined(HAVE_CWAIT) */ |
6227 | | |
6228 | | #if defined(HAVE_WAIT) |
6229 | | |
6230 | | PyDoc_STRVAR(os_wait__doc__, |
6231 | | "wait($module, /)\n" |
6232 | | "--\n" |
6233 | | "\n" |
6234 | | "Wait for completion of a child process.\n" |
6235 | | "\n" |
6236 | | "Returns a tuple of information about the child process:\n" |
6237 | | " (pid, status)"); |
6238 | | |
6239 | | #define OS_WAIT_METHODDEF \ |
6240 | | {"wait", (PyCFunction)os_wait, METH_NOARGS, os_wait__doc__}, |
6241 | | |
6242 | | static PyObject * |
6243 | | os_wait_impl(PyObject *module); |
6244 | | |
6245 | | static PyObject * |
6246 | | os_wait(PyObject *module, PyObject *Py_UNUSED(ignored)) |
6247 | 0 | { |
6248 | 0 | return os_wait_impl(module); |
6249 | 0 | } |
6250 | | |
6251 | | #endif /* defined(HAVE_WAIT) */ |
6252 | | |
6253 | | #if (defined(__linux__) && defined(__NR_pidfd_open) && !(defined(__ANDROID__) && __ANDROID_API__ < 31)) |
6254 | | |
6255 | | PyDoc_STRVAR(os_pidfd_open__doc__, |
6256 | | "pidfd_open($module, /, pid, flags=0)\n" |
6257 | | "--\n" |
6258 | | "\n" |
6259 | | "Return a file descriptor referring to the process *pid*.\n" |
6260 | | "\n" |
6261 | | "The descriptor can be used to perform process management without races and\n" |
6262 | | "signals."); |
6263 | | |
6264 | | #define OS_PIDFD_OPEN_METHODDEF \ |
6265 | | {"pidfd_open", _PyCFunction_CAST(os_pidfd_open), METH_FASTCALL|METH_KEYWORDS, os_pidfd_open__doc__}, |
6266 | | |
6267 | | static PyObject * |
6268 | | os_pidfd_open_impl(PyObject *module, pid_t pid, unsigned int flags); |
6269 | | |
6270 | | static PyObject * |
6271 | | os_pidfd_open(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
6272 | 0 | { |
6273 | 0 | PyObject *return_value = NULL; |
6274 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
6275 | |
|
6276 | 0 | #define NUM_KEYWORDS 2 |
6277 | 0 | static struct { |
6278 | 0 | PyGC_Head _this_is_not_used; |
6279 | 0 | PyObject_VAR_HEAD |
6280 | 0 | Py_hash_t ob_hash; |
6281 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
6282 | 0 | } _kwtuple = { |
6283 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
6284 | 0 | .ob_hash = -1, |
6285 | 0 | .ob_item = { &_Py_ID(pid), &_Py_ID(flags), }, |
6286 | 0 | }; |
6287 | 0 | #undef NUM_KEYWORDS |
6288 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
6289 | |
|
6290 | | #else // !Py_BUILD_CORE |
6291 | | # define KWTUPLE NULL |
6292 | | #endif // !Py_BUILD_CORE |
6293 | |
|
6294 | 0 | static const char * const _keywords[] = {"pid", "flags", NULL}; |
6295 | 0 | static _PyArg_Parser _parser = { |
6296 | 0 | .keywords = _keywords, |
6297 | 0 | .fname = "pidfd_open", |
6298 | 0 | .kwtuple = KWTUPLE, |
6299 | 0 | }; |
6300 | 0 | #undef KWTUPLE |
6301 | 0 | PyObject *argsbuf[2]; |
6302 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
6303 | 0 | pid_t pid; |
6304 | 0 | unsigned int flags = 0; |
6305 | |
|
6306 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
6307 | 0 | /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
6308 | 0 | if (!args) { |
6309 | 0 | goto exit; |
6310 | 0 | } |
6311 | 0 | pid = PyLong_AsPid(args[0]); |
6312 | 0 | if (pid == (pid_t)(-1) && PyErr_Occurred()) { |
6313 | 0 | goto exit; |
6314 | 0 | } |
6315 | 0 | if (!noptargs) { |
6316 | 0 | goto skip_optional_pos; |
6317 | 0 | } |
6318 | 0 | if (!_PyLong_UnsignedInt_Converter(args[1], &flags)) { |
6319 | 0 | goto exit; |
6320 | 0 | } |
6321 | 0 | skip_optional_pos: |
6322 | 0 | return_value = os_pidfd_open_impl(module, pid, flags); |
6323 | |
|
6324 | 0 | exit: |
6325 | 0 | return return_value; |
6326 | 0 | } |
6327 | | |
6328 | | #endif /* (defined(__linux__) && defined(__NR_pidfd_open) && !(defined(__ANDROID__) && __ANDROID_API__ < 31)) */ |
6329 | | |
6330 | | #if defined(HAVE_SETNS) |
6331 | | |
6332 | | PyDoc_STRVAR(os_setns__doc__, |
6333 | | "setns($module, /, fd, nstype=0)\n" |
6334 | | "--\n" |
6335 | | "\n" |
6336 | | "Move the calling thread into different namespaces.\n" |
6337 | | "\n" |
6338 | | " fd\n" |
6339 | | " A file descriptor to a namespace.\n" |
6340 | | " nstype\n" |
6341 | | " Type of namespace."); |
6342 | | |
6343 | | #define OS_SETNS_METHODDEF \ |
6344 | | {"setns", _PyCFunction_CAST(os_setns), METH_FASTCALL|METH_KEYWORDS, os_setns__doc__}, |
6345 | | |
6346 | | static PyObject * |
6347 | | os_setns_impl(PyObject *module, int fd, int nstype); |
6348 | | |
6349 | | static PyObject * |
6350 | | os_setns(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
6351 | 0 | { |
6352 | 0 | PyObject *return_value = NULL; |
6353 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
6354 | |
|
6355 | 0 | #define NUM_KEYWORDS 2 |
6356 | 0 | static struct { |
6357 | 0 | PyGC_Head _this_is_not_used; |
6358 | 0 | PyObject_VAR_HEAD |
6359 | 0 | Py_hash_t ob_hash; |
6360 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
6361 | 0 | } _kwtuple = { |
6362 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
6363 | 0 | .ob_hash = -1, |
6364 | 0 | .ob_item = { &_Py_ID(fd), &_Py_ID(nstype), }, |
6365 | 0 | }; |
6366 | 0 | #undef NUM_KEYWORDS |
6367 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
6368 | |
|
6369 | | #else // !Py_BUILD_CORE |
6370 | | # define KWTUPLE NULL |
6371 | | #endif // !Py_BUILD_CORE |
6372 | |
|
6373 | 0 | static const char * const _keywords[] = {"fd", "nstype", NULL}; |
6374 | 0 | static _PyArg_Parser _parser = { |
6375 | 0 | .keywords = _keywords, |
6376 | 0 | .fname = "setns", |
6377 | 0 | .kwtuple = KWTUPLE, |
6378 | 0 | }; |
6379 | 0 | #undef KWTUPLE |
6380 | 0 | PyObject *argsbuf[2]; |
6381 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
6382 | 0 | int fd; |
6383 | 0 | int nstype = 0; |
6384 | |
|
6385 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
6386 | 0 | /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
6387 | 0 | if (!args) { |
6388 | 0 | goto exit; |
6389 | 0 | } |
6390 | 0 | fd = PyObject_AsFileDescriptor(args[0]); |
6391 | 0 | if (fd < 0) { |
6392 | 0 | goto exit; |
6393 | 0 | } |
6394 | 0 | if (!noptargs) { |
6395 | 0 | goto skip_optional_pos; |
6396 | 0 | } |
6397 | 0 | nstype = PyLong_AsInt(args[1]); |
6398 | 0 | if (nstype == -1 && PyErr_Occurred()) { |
6399 | 0 | goto exit; |
6400 | 0 | } |
6401 | 0 | skip_optional_pos: |
6402 | 0 | return_value = os_setns_impl(module, fd, nstype); |
6403 | |
|
6404 | 0 | exit: |
6405 | 0 | return return_value; |
6406 | 0 | } |
6407 | | |
6408 | | #endif /* defined(HAVE_SETNS) */ |
6409 | | |
6410 | | #if defined(HAVE_UNSHARE) |
6411 | | |
6412 | | PyDoc_STRVAR(os_unshare__doc__, |
6413 | | "unshare($module, /, flags)\n" |
6414 | | "--\n" |
6415 | | "\n" |
6416 | | "Disassociate parts of a process (or thread) execution context.\n" |
6417 | | "\n" |
6418 | | " flags\n" |
6419 | | " Namespaces to be unshared."); |
6420 | | |
6421 | | #define OS_UNSHARE_METHODDEF \ |
6422 | | {"unshare", _PyCFunction_CAST(os_unshare), METH_FASTCALL|METH_KEYWORDS, os_unshare__doc__}, |
6423 | | |
6424 | | static PyObject * |
6425 | | os_unshare_impl(PyObject *module, int flags); |
6426 | | |
6427 | | static PyObject * |
6428 | | os_unshare(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
6429 | 0 | { |
6430 | 0 | PyObject *return_value = NULL; |
6431 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
6432 | |
|
6433 | 0 | #define NUM_KEYWORDS 1 |
6434 | 0 | static struct { |
6435 | 0 | PyGC_Head _this_is_not_used; |
6436 | 0 | PyObject_VAR_HEAD |
6437 | 0 | Py_hash_t ob_hash; |
6438 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
6439 | 0 | } _kwtuple = { |
6440 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
6441 | 0 | .ob_hash = -1, |
6442 | 0 | .ob_item = { &_Py_ID(flags), }, |
6443 | 0 | }; |
6444 | 0 | #undef NUM_KEYWORDS |
6445 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
6446 | |
|
6447 | | #else // !Py_BUILD_CORE |
6448 | | # define KWTUPLE NULL |
6449 | | #endif // !Py_BUILD_CORE |
6450 | |
|
6451 | 0 | static const char * const _keywords[] = {"flags", NULL}; |
6452 | 0 | static _PyArg_Parser _parser = { |
6453 | 0 | .keywords = _keywords, |
6454 | 0 | .fname = "unshare", |
6455 | 0 | .kwtuple = KWTUPLE, |
6456 | 0 | }; |
6457 | 0 | #undef KWTUPLE |
6458 | 0 | PyObject *argsbuf[1]; |
6459 | 0 | int flags; |
6460 | |
|
6461 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
6462 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
6463 | 0 | if (!args) { |
6464 | 0 | goto exit; |
6465 | 0 | } |
6466 | 0 | flags = PyLong_AsInt(args[0]); |
6467 | 0 | if (flags == -1 && PyErr_Occurred()) { |
6468 | 0 | goto exit; |
6469 | 0 | } |
6470 | 0 | return_value = os_unshare_impl(module, flags); |
6471 | |
|
6472 | 0 | exit: |
6473 | 0 | return return_value; |
6474 | 0 | } |
6475 | | |
6476 | | #endif /* defined(HAVE_UNSHARE) */ |
6477 | | |
6478 | | #if (defined(HAVE_READLINK) || defined(MS_WINDOWS)) |
6479 | | |
6480 | | PyDoc_STRVAR(os_readlink__doc__, |
6481 | | "readlink($module, /, path, *, dir_fd=None)\n" |
6482 | | "--\n" |
6483 | | "\n" |
6484 | | "Return a string representing the path to which the symbolic link points.\n" |
6485 | | "\n" |
6486 | | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
6487 | | "and path should be relative; path will then be relative to that directory.\n" |
6488 | | "\n" |
6489 | | "dir_fd may not be implemented on your platform. If it is unavailable,\n" |
6490 | | "using it will raise a NotImplementedError."); |
6491 | | |
6492 | | #define OS_READLINK_METHODDEF \ |
6493 | | {"readlink", _PyCFunction_CAST(os_readlink), METH_FASTCALL|METH_KEYWORDS, os_readlink__doc__}, |
6494 | | |
6495 | | static PyObject * |
6496 | | os_readlink_impl(PyObject *module, path_t *path, int dir_fd); |
6497 | | |
6498 | | static PyObject * |
6499 | | os_readlink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
6500 | 0 | { |
6501 | 0 | PyObject *return_value = NULL; |
6502 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
6503 | |
|
6504 | 0 | #define NUM_KEYWORDS 2 |
6505 | 0 | static struct { |
6506 | 0 | PyGC_Head _this_is_not_used; |
6507 | 0 | PyObject_VAR_HEAD |
6508 | 0 | Py_hash_t ob_hash; |
6509 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
6510 | 0 | } _kwtuple = { |
6511 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
6512 | 0 | .ob_hash = -1, |
6513 | 0 | .ob_item = { &_Py_ID(path), &_Py_ID(dir_fd), }, |
6514 | 0 | }; |
6515 | 0 | #undef NUM_KEYWORDS |
6516 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
6517 | |
|
6518 | | #else // !Py_BUILD_CORE |
6519 | | # define KWTUPLE NULL |
6520 | | #endif // !Py_BUILD_CORE |
6521 | |
|
6522 | 0 | static const char * const _keywords[] = {"path", "dir_fd", NULL}; |
6523 | 0 | static _PyArg_Parser _parser = { |
6524 | 0 | .keywords = _keywords, |
6525 | 0 | .fname = "readlink", |
6526 | 0 | .kwtuple = KWTUPLE, |
6527 | 0 | }; |
6528 | 0 | #undef KWTUPLE |
6529 | 0 | PyObject *argsbuf[2]; |
6530 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
6531 | 0 | path_t path = PATH_T_INITIALIZE_P("readlink", "path", 0, 0, 0, 0); |
6532 | 0 | int dir_fd = DEFAULT_DIR_FD; |
6533 | |
|
6534 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
6535 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
6536 | 0 | if (!args) { |
6537 | 0 | goto exit; |
6538 | 0 | } |
6539 | 0 | if (!path_converter(args[0], &path)) { |
6540 | 0 | goto exit; |
6541 | 0 | } |
6542 | 0 | if (!noptargs) { |
6543 | 0 | goto skip_optional_kwonly; |
6544 | 0 | } |
6545 | 0 | if (!READLINKAT_DIR_FD_CONVERTER(args[1], &dir_fd)) { |
6546 | 0 | goto exit; |
6547 | 0 | } |
6548 | 0 | skip_optional_kwonly: |
6549 | 0 | return_value = os_readlink_impl(module, &path, dir_fd); |
6550 | |
|
6551 | 0 | exit: |
6552 | | /* Cleanup for path */ |
6553 | 0 | path_cleanup(&path); |
6554 | |
|
6555 | 0 | return return_value; |
6556 | 0 | } |
6557 | | |
6558 | | #endif /* (defined(HAVE_READLINK) || defined(MS_WINDOWS)) */ |
6559 | | |
6560 | | #if defined(HAVE_SYMLINK) |
6561 | | |
6562 | | PyDoc_STRVAR(os_symlink__doc__, |
6563 | | "symlink($module, /, src, dst, target_is_directory=False, *, dir_fd=None)\n" |
6564 | | "--\n" |
6565 | | "\n" |
6566 | | "Create a symbolic link pointing to src named dst.\n" |
6567 | | "\n" |
6568 | | "target_is_directory is required on Windows if the target is to be\n" |
6569 | | " interpreted as a directory. (On Windows, symlink requires\n" |
6570 | | " Windows 6.0 or greater, and raises a NotImplementedError otherwise.)\n" |
6571 | | " target_is_directory is ignored on non-Windows platforms.\n" |
6572 | | "\n" |
6573 | | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
6574 | | " and path should be relative; path will then be relative to that directory.\n" |
6575 | | "dir_fd may not be implemented on your platform.\n" |
6576 | | " If it is unavailable, using it will raise a NotImplementedError."); |
6577 | | |
6578 | | #define OS_SYMLINK_METHODDEF \ |
6579 | | {"symlink", _PyCFunction_CAST(os_symlink), METH_FASTCALL|METH_KEYWORDS, os_symlink__doc__}, |
6580 | | |
6581 | | static PyObject * |
6582 | | os_symlink_impl(PyObject *module, path_t *src, path_t *dst, |
6583 | | int target_is_directory, int dir_fd); |
6584 | | |
6585 | | static PyObject * |
6586 | | os_symlink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
6587 | 0 | { |
6588 | 0 | PyObject *return_value = NULL; |
6589 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
6590 | |
|
6591 | 0 | #define NUM_KEYWORDS 4 |
6592 | 0 | static struct { |
6593 | 0 | PyGC_Head _this_is_not_used; |
6594 | 0 | PyObject_VAR_HEAD |
6595 | 0 | Py_hash_t ob_hash; |
6596 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
6597 | 0 | } _kwtuple = { |
6598 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
6599 | 0 | .ob_hash = -1, |
6600 | 0 | .ob_item = { &_Py_ID(src), &_Py_ID(dst), &_Py_ID(target_is_directory), &_Py_ID(dir_fd), }, |
6601 | 0 | }; |
6602 | 0 | #undef NUM_KEYWORDS |
6603 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
6604 | |
|
6605 | | #else // !Py_BUILD_CORE |
6606 | | # define KWTUPLE NULL |
6607 | | #endif // !Py_BUILD_CORE |
6608 | |
|
6609 | 0 | static const char * const _keywords[] = {"src", "dst", "target_is_directory", "dir_fd", NULL}; |
6610 | 0 | static _PyArg_Parser _parser = { |
6611 | 0 | .keywords = _keywords, |
6612 | 0 | .fname = "symlink", |
6613 | 0 | .kwtuple = KWTUPLE, |
6614 | 0 | }; |
6615 | 0 | #undef KWTUPLE |
6616 | 0 | PyObject *argsbuf[4]; |
6617 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2; |
6618 | 0 | path_t src = PATH_T_INITIALIZE_P("symlink", "src", 0, 0, 0, 0); |
6619 | 0 | path_t dst = PATH_T_INITIALIZE_P("symlink", "dst", 0, 0, 0, 0); |
6620 | 0 | int target_is_directory = 0; |
6621 | 0 | int dir_fd = DEFAULT_DIR_FD; |
6622 | |
|
6623 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
6624 | 0 | /*minpos*/ 2, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
6625 | 0 | if (!args) { |
6626 | 0 | goto exit; |
6627 | 0 | } |
6628 | 0 | if (!path_converter(args[0], &src)) { |
6629 | 0 | goto exit; |
6630 | 0 | } |
6631 | 0 | if (!path_converter(args[1], &dst)) { |
6632 | 0 | goto exit; |
6633 | 0 | } |
6634 | 0 | if (!noptargs) { |
6635 | 0 | goto skip_optional_pos; |
6636 | 0 | } |
6637 | 0 | if (args[2]) { |
6638 | 0 | target_is_directory = PyObject_IsTrue(args[2]); |
6639 | 0 | if (target_is_directory < 0) { |
6640 | 0 | goto exit; |
6641 | 0 | } |
6642 | 0 | if (!--noptargs) { |
6643 | 0 | goto skip_optional_pos; |
6644 | 0 | } |
6645 | 0 | } |
6646 | 0 | skip_optional_pos: |
6647 | 0 | if (!noptargs) { |
6648 | 0 | goto skip_optional_kwonly; |
6649 | 0 | } |
6650 | 0 | if (!SYMLINKAT_DIR_FD_CONVERTER(args[3], &dir_fd)) { |
6651 | 0 | goto exit; |
6652 | 0 | } |
6653 | 0 | skip_optional_kwonly: |
6654 | 0 | return_value = os_symlink_impl(module, &src, &dst, target_is_directory, dir_fd); |
6655 | |
|
6656 | 0 | exit: |
6657 | | /* Cleanup for src */ |
6658 | 0 | path_cleanup(&src); |
6659 | | /* Cleanup for dst */ |
6660 | 0 | path_cleanup(&dst); |
6661 | |
|
6662 | 0 | return return_value; |
6663 | 0 | } |
6664 | | |
6665 | | #endif /* defined(HAVE_SYMLINK) */ |
6666 | | |
6667 | | PyDoc_STRVAR(os_times__doc__, |
6668 | | "times($module, /)\n" |
6669 | | "--\n" |
6670 | | "\n" |
6671 | | "Return a collection containing process timing information.\n" |
6672 | | "\n" |
6673 | | "The object returned behaves like a named tuple with these fields:\n" |
6674 | | " (utime, stime, cutime, cstime, elapsed_time)\n" |
6675 | | "All fields are floating-point numbers."); |
6676 | | |
6677 | | #define OS_TIMES_METHODDEF \ |
6678 | | {"times", (PyCFunction)os_times, METH_NOARGS, os_times__doc__}, |
6679 | | |
6680 | | static PyObject * |
6681 | | os_times_impl(PyObject *module); |
6682 | | |
6683 | | static PyObject * |
6684 | | os_times(PyObject *module, PyObject *Py_UNUSED(ignored)) |
6685 | 0 | { |
6686 | 0 | return os_times_impl(module); |
6687 | 0 | } |
6688 | | |
6689 | | #if defined(HAVE_TIMERFD_CREATE) |
6690 | | |
6691 | | PyDoc_STRVAR(os_timerfd_create__doc__, |
6692 | | "timerfd_create($module, clockid, /, *, flags=0)\n" |
6693 | | "--\n" |
6694 | | "\n" |
6695 | | "Create and return a timer file descriptor.\n" |
6696 | | "\n" |
6697 | | " clockid\n" |
6698 | | " A valid clock ID constant as timer file descriptor.\n" |
6699 | | "\n" |
6700 | | " time.CLOCK_REALTIME\n" |
6701 | | " time.CLOCK_MONOTONIC\n" |
6702 | | " time.CLOCK_BOOTTIME\n" |
6703 | | " flags\n" |
6704 | | " 0 or a bit mask of os.TFD_NONBLOCK or os.TFD_CLOEXEC.\n" |
6705 | | "\n" |
6706 | | " os.TFD_NONBLOCK\n" |
6707 | | " If *TFD_NONBLOCK* is set as a flag, read doesn\'t blocks.\n" |
6708 | | " If *TFD_NONBLOCK* is not set as a flag, read block until the timer fires.\n" |
6709 | | "\n" |
6710 | | " os.TFD_CLOEXEC\n" |
6711 | | " If *TFD_CLOEXEC* is set as a flag, enable the close-on-exec flag"); |
6712 | | |
6713 | | #define OS_TIMERFD_CREATE_METHODDEF \ |
6714 | | {"timerfd_create", _PyCFunction_CAST(os_timerfd_create), METH_FASTCALL|METH_KEYWORDS, os_timerfd_create__doc__}, |
6715 | | |
6716 | | static PyObject * |
6717 | | os_timerfd_create_impl(PyObject *module, int clockid, int flags); |
6718 | | |
6719 | | static PyObject * |
6720 | | os_timerfd_create(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
6721 | 0 | { |
6722 | 0 | PyObject *return_value = NULL; |
6723 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
6724 | |
|
6725 | 0 | #define NUM_KEYWORDS 1 |
6726 | 0 | static struct { |
6727 | 0 | PyGC_Head _this_is_not_used; |
6728 | 0 | PyObject_VAR_HEAD |
6729 | 0 | Py_hash_t ob_hash; |
6730 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
6731 | 0 | } _kwtuple = { |
6732 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
6733 | 0 | .ob_hash = -1, |
6734 | 0 | .ob_item = { &_Py_ID(flags), }, |
6735 | 0 | }; |
6736 | 0 | #undef NUM_KEYWORDS |
6737 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
6738 | |
|
6739 | | #else // !Py_BUILD_CORE |
6740 | | # define KWTUPLE NULL |
6741 | | #endif // !Py_BUILD_CORE |
6742 | |
|
6743 | 0 | static const char * const _keywords[] = {"", "flags", NULL}; |
6744 | 0 | static _PyArg_Parser _parser = { |
6745 | 0 | .keywords = _keywords, |
6746 | 0 | .fname = "timerfd_create", |
6747 | 0 | .kwtuple = KWTUPLE, |
6748 | 0 | }; |
6749 | 0 | #undef KWTUPLE |
6750 | 0 | PyObject *argsbuf[2]; |
6751 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
6752 | 0 | int clockid; |
6753 | 0 | int flags = 0; |
6754 | |
|
6755 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
6756 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
6757 | 0 | if (!args) { |
6758 | 0 | goto exit; |
6759 | 0 | } |
6760 | 0 | clockid = PyLong_AsInt(args[0]); |
6761 | 0 | if (clockid == -1 && PyErr_Occurred()) { |
6762 | 0 | goto exit; |
6763 | 0 | } |
6764 | 0 | if (!noptargs) { |
6765 | 0 | goto skip_optional_kwonly; |
6766 | 0 | } |
6767 | 0 | flags = PyLong_AsInt(args[1]); |
6768 | 0 | if (flags == -1 && PyErr_Occurred()) { |
6769 | 0 | goto exit; |
6770 | 0 | } |
6771 | 0 | skip_optional_kwonly: |
6772 | 0 | return_value = os_timerfd_create_impl(module, clockid, flags); |
6773 | |
|
6774 | 0 | exit: |
6775 | 0 | return return_value; |
6776 | 0 | } |
6777 | | |
6778 | | #endif /* defined(HAVE_TIMERFD_CREATE) */ |
6779 | | |
6780 | | #if defined(HAVE_TIMERFD_CREATE) |
6781 | | |
6782 | | PyDoc_STRVAR(os_timerfd_settime__doc__, |
6783 | | "timerfd_settime($module, fd, /, *, flags=0, initial=0.0, interval=0.0)\n" |
6784 | | "--\n" |
6785 | | "\n" |
6786 | | "Alter a timer file descriptor\'s internal timer in seconds.\n" |
6787 | | "\n" |
6788 | | " fd\n" |
6789 | | " A timer file descriptor.\n" |
6790 | | " flags\n" |
6791 | | " 0 or a bit mask of TFD_TIMER_ABSTIME or TFD_TIMER_CANCEL_ON_SET.\n" |
6792 | | " initial\n" |
6793 | | " The initial expiration time, in seconds.\n" |
6794 | | " interval\n" |
6795 | | " The timer\'s interval, in seconds."); |
6796 | | |
6797 | | #define OS_TIMERFD_SETTIME_METHODDEF \ |
6798 | | {"timerfd_settime", _PyCFunction_CAST(os_timerfd_settime), METH_FASTCALL|METH_KEYWORDS, os_timerfd_settime__doc__}, |
6799 | | |
6800 | | static PyObject * |
6801 | | os_timerfd_settime_impl(PyObject *module, int fd, int flags, |
6802 | | double initial_double, double interval_double); |
6803 | | |
6804 | | static PyObject * |
6805 | | os_timerfd_settime(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
6806 | 0 | { |
6807 | 0 | PyObject *return_value = NULL; |
6808 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
6809 | |
|
6810 | 0 | #define NUM_KEYWORDS 3 |
6811 | 0 | static struct { |
6812 | 0 | PyGC_Head _this_is_not_used; |
6813 | 0 | PyObject_VAR_HEAD |
6814 | 0 | Py_hash_t ob_hash; |
6815 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
6816 | 0 | } _kwtuple = { |
6817 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
6818 | 0 | .ob_hash = -1, |
6819 | 0 | .ob_item = { &_Py_ID(flags), &_Py_ID(initial), &_Py_ID(interval), }, |
6820 | 0 | }; |
6821 | 0 | #undef NUM_KEYWORDS |
6822 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
6823 | |
|
6824 | | #else // !Py_BUILD_CORE |
6825 | | # define KWTUPLE NULL |
6826 | | #endif // !Py_BUILD_CORE |
6827 | |
|
6828 | 0 | static const char * const _keywords[] = {"", "flags", "initial", "interval", NULL}; |
6829 | 0 | static _PyArg_Parser _parser = { |
6830 | 0 | .keywords = _keywords, |
6831 | 0 | .fname = "timerfd_settime", |
6832 | 0 | .kwtuple = KWTUPLE, |
6833 | 0 | }; |
6834 | 0 | #undef KWTUPLE |
6835 | 0 | PyObject *argsbuf[4]; |
6836 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
6837 | 0 | int fd; |
6838 | 0 | int flags = 0; |
6839 | 0 | double initial_double = 0.0; |
6840 | 0 | double interval_double = 0.0; |
6841 | |
|
6842 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
6843 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
6844 | 0 | if (!args) { |
6845 | 0 | goto exit; |
6846 | 0 | } |
6847 | 0 | fd = PyObject_AsFileDescriptor(args[0]); |
6848 | 0 | if (fd < 0) { |
6849 | 0 | goto exit; |
6850 | 0 | } |
6851 | 0 | if (!noptargs) { |
6852 | 0 | goto skip_optional_kwonly; |
6853 | 0 | } |
6854 | 0 | if (args[1]) { |
6855 | 0 | flags = PyLong_AsInt(args[1]); |
6856 | 0 | if (flags == -1 && PyErr_Occurred()) { |
6857 | 0 | goto exit; |
6858 | 0 | } |
6859 | 0 | if (!--noptargs) { |
6860 | 0 | goto skip_optional_kwonly; |
6861 | 0 | } |
6862 | 0 | } |
6863 | 0 | if (args[2]) { |
6864 | 0 | if (PyFloat_CheckExact(args[2])) { |
6865 | 0 | initial_double = PyFloat_AS_DOUBLE(args[2]); |
6866 | 0 | } |
6867 | 0 | else |
6868 | 0 | { |
6869 | 0 | initial_double = PyFloat_AsDouble(args[2]); |
6870 | 0 | if (initial_double == -1.0 && PyErr_Occurred()) { |
6871 | 0 | goto exit; |
6872 | 0 | } |
6873 | 0 | } |
6874 | 0 | if (!--noptargs) { |
6875 | 0 | goto skip_optional_kwonly; |
6876 | 0 | } |
6877 | 0 | } |
6878 | 0 | if (PyFloat_CheckExact(args[3])) { |
6879 | 0 | interval_double = PyFloat_AS_DOUBLE(args[3]); |
6880 | 0 | } |
6881 | 0 | else |
6882 | 0 | { |
6883 | 0 | interval_double = PyFloat_AsDouble(args[3]); |
6884 | 0 | if (interval_double == -1.0 && PyErr_Occurred()) { |
6885 | 0 | goto exit; |
6886 | 0 | } |
6887 | 0 | } |
6888 | 0 | skip_optional_kwonly: |
6889 | 0 | return_value = os_timerfd_settime_impl(module, fd, flags, initial_double, interval_double); |
6890 | |
|
6891 | 0 | exit: |
6892 | 0 | return return_value; |
6893 | 0 | } |
6894 | | |
6895 | | #endif /* defined(HAVE_TIMERFD_CREATE) */ |
6896 | | |
6897 | | #if defined(HAVE_TIMERFD_CREATE) |
6898 | | |
6899 | | PyDoc_STRVAR(os_timerfd_settime_ns__doc__, |
6900 | | "timerfd_settime_ns($module, fd, /, *, flags=0, initial=0, interval=0)\n" |
6901 | | "--\n" |
6902 | | "\n" |
6903 | | "Alter a timer file descriptor\'s internal timer in nanoseconds.\n" |
6904 | | "\n" |
6905 | | " fd\n" |
6906 | | " A timer file descriptor.\n" |
6907 | | " flags\n" |
6908 | | " 0 or a bit mask of TFD_TIMER_ABSTIME or TFD_TIMER_CANCEL_ON_SET.\n" |
6909 | | " initial\n" |
6910 | | " initial expiration timing in seconds.\n" |
6911 | | " interval\n" |
6912 | | " interval for the timer in seconds."); |
6913 | | |
6914 | | #define OS_TIMERFD_SETTIME_NS_METHODDEF \ |
6915 | | {"timerfd_settime_ns", _PyCFunction_CAST(os_timerfd_settime_ns), METH_FASTCALL|METH_KEYWORDS, os_timerfd_settime_ns__doc__}, |
6916 | | |
6917 | | static PyObject * |
6918 | | os_timerfd_settime_ns_impl(PyObject *module, int fd, int flags, |
6919 | | long long initial, long long interval); |
6920 | | |
6921 | | static PyObject * |
6922 | | os_timerfd_settime_ns(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
6923 | 0 | { |
6924 | 0 | PyObject *return_value = NULL; |
6925 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
6926 | |
|
6927 | 0 | #define NUM_KEYWORDS 3 |
6928 | 0 | static struct { |
6929 | 0 | PyGC_Head _this_is_not_used; |
6930 | 0 | PyObject_VAR_HEAD |
6931 | 0 | Py_hash_t ob_hash; |
6932 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
6933 | 0 | } _kwtuple = { |
6934 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
6935 | 0 | .ob_hash = -1, |
6936 | 0 | .ob_item = { &_Py_ID(flags), &_Py_ID(initial), &_Py_ID(interval), }, |
6937 | 0 | }; |
6938 | 0 | #undef NUM_KEYWORDS |
6939 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
6940 | |
|
6941 | | #else // !Py_BUILD_CORE |
6942 | | # define KWTUPLE NULL |
6943 | | #endif // !Py_BUILD_CORE |
6944 | |
|
6945 | 0 | static const char * const _keywords[] = {"", "flags", "initial", "interval", NULL}; |
6946 | 0 | static _PyArg_Parser _parser = { |
6947 | 0 | .keywords = _keywords, |
6948 | 0 | .fname = "timerfd_settime_ns", |
6949 | 0 | .kwtuple = KWTUPLE, |
6950 | 0 | }; |
6951 | 0 | #undef KWTUPLE |
6952 | 0 | PyObject *argsbuf[4]; |
6953 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
6954 | 0 | int fd; |
6955 | 0 | int flags = 0; |
6956 | 0 | long long initial = 0; |
6957 | 0 | long long interval = 0; |
6958 | |
|
6959 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
6960 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
6961 | 0 | if (!args) { |
6962 | 0 | goto exit; |
6963 | 0 | } |
6964 | 0 | fd = PyObject_AsFileDescriptor(args[0]); |
6965 | 0 | if (fd < 0) { |
6966 | 0 | goto exit; |
6967 | 0 | } |
6968 | 0 | if (!noptargs) { |
6969 | 0 | goto skip_optional_kwonly; |
6970 | 0 | } |
6971 | 0 | if (args[1]) { |
6972 | 0 | flags = PyLong_AsInt(args[1]); |
6973 | 0 | if (flags == -1 && PyErr_Occurred()) { |
6974 | 0 | goto exit; |
6975 | 0 | } |
6976 | 0 | if (!--noptargs) { |
6977 | 0 | goto skip_optional_kwonly; |
6978 | 0 | } |
6979 | 0 | } |
6980 | 0 | if (args[2]) { |
6981 | 0 | initial = PyLong_AsLongLong(args[2]); |
6982 | 0 | if (initial == -1 && PyErr_Occurred()) { |
6983 | 0 | goto exit; |
6984 | 0 | } |
6985 | 0 | if (!--noptargs) { |
6986 | 0 | goto skip_optional_kwonly; |
6987 | 0 | } |
6988 | 0 | } |
6989 | 0 | interval = PyLong_AsLongLong(args[3]); |
6990 | 0 | if (interval == -1 && PyErr_Occurred()) { |
6991 | 0 | goto exit; |
6992 | 0 | } |
6993 | 0 | skip_optional_kwonly: |
6994 | 0 | return_value = os_timerfd_settime_ns_impl(module, fd, flags, initial, interval); |
6995 | |
|
6996 | 0 | exit: |
6997 | 0 | return return_value; |
6998 | 0 | } |
6999 | | |
7000 | | #endif /* defined(HAVE_TIMERFD_CREATE) */ |
7001 | | |
7002 | | #if defined(HAVE_TIMERFD_CREATE) |
7003 | | |
7004 | | PyDoc_STRVAR(os_timerfd_gettime__doc__, |
7005 | | "timerfd_gettime($module, fd, /)\n" |
7006 | | "--\n" |
7007 | | "\n" |
7008 | | "Return a tuple of a timer file descriptor\'s (interval, next expiration) in float seconds.\n" |
7009 | | "\n" |
7010 | | " fd\n" |
7011 | | " A timer file descriptor."); |
7012 | | |
7013 | | #define OS_TIMERFD_GETTIME_METHODDEF \ |
7014 | | {"timerfd_gettime", (PyCFunction)os_timerfd_gettime, METH_O, os_timerfd_gettime__doc__}, |
7015 | | |
7016 | | static PyObject * |
7017 | | os_timerfd_gettime_impl(PyObject *module, int fd); |
7018 | | |
7019 | | static PyObject * |
7020 | | os_timerfd_gettime(PyObject *module, PyObject *arg) |
7021 | 0 | { |
7022 | 0 | PyObject *return_value = NULL; |
7023 | 0 | int fd; |
7024 | |
|
7025 | 0 | fd = PyObject_AsFileDescriptor(arg); |
7026 | 0 | if (fd < 0) { |
7027 | 0 | goto exit; |
7028 | 0 | } |
7029 | 0 | return_value = os_timerfd_gettime_impl(module, fd); |
7030 | |
|
7031 | 0 | exit: |
7032 | 0 | return return_value; |
7033 | 0 | } |
7034 | | |
7035 | | #endif /* defined(HAVE_TIMERFD_CREATE) */ |
7036 | | |
7037 | | #if defined(HAVE_TIMERFD_CREATE) |
7038 | | |
7039 | | PyDoc_STRVAR(os_timerfd_gettime_ns__doc__, |
7040 | | "timerfd_gettime_ns($module, fd, /)\n" |
7041 | | "--\n" |
7042 | | "\n" |
7043 | | "Return a tuple of a timer file descriptor\'s (interval, next expiration) in nanoseconds.\n" |
7044 | | "\n" |
7045 | | " fd\n" |
7046 | | " A timer file descriptor."); |
7047 | | |
7048 | | #define OS_TIMERFD_GETTIME_NS_METHODDEF \ |
7049 | | {"timerfd_gettime_ns", (PyCFunction)os_timerfd_gettime_ns, METH_O, os_timerfd_gettime_ns__doc__}, |
7050 | | |
7051 | | static PyObject * |
7052 | | os_timerfd_gettime_ns_impl(PyObject *module, int fd); |
7053 | | |
7054 | | static PyObject * |
7055 | | os_timerfd_gettime_ns(PyObject *module, PyObject *arg) |
7056 | 0 | { |
7057 | 0 | PyObject *return_value = NULL; |
7058 | 0 | int fd; |
7059 | |
|
7060 | 0 | fd = PyObject_AsFileDescriptor(arg); |
7061 | 0 | if (fd < 0) { |
7062 | 0 | goto exit; |
7063 | 0 | } |
7064 | 0 | return_value = os_timerfd_gettime_ns_impl(module, fd); |
7065 | |
|
7066 | 0 | exit: |
7067 | 0 | return return_value; |
7068 | 0 | } |
7069 | | |
7070 | | #endif /* defined(HAVE_TIMERFD_CREATE) */ |
7071 | | |
7072 | | #if defined(HAVE_GETSID) |
7073 | | |
7074 | | PyDoc_STRVAR(os_getsid__doc__, |
7075 | | "getsid($module, pid, /)\n" |
7076 | | "--\n" |
7077 | | "\n" |
7078 | | "Call the system call getsid(pid) and return the result."); |
7079 | | |
7080 | | #define OS_GETSID_METHODDEF \ |
7081 | | {"getsid", (PyCFunction)os_getsid, METH_O, os_getsid__doc__}, |
7082 | | |
7083 | | static PyObject * |
7084 | | os_getsid_impl(PyObject *module, pid_t pid); |
7085 | | |
7086 | | static PyObject * |
7087 | | os_getsid(PyObject *module, PyObject *arg) |
7088 | 0 | { |
7089 | 0 | PyObject *return_value = NULL; |
7090 | 0 | pid_t pid; |
7091 | |
|
7092 | 0 | pid = PyLong_AsPid(arg); |
7093 | 0 | if (pid == (pid_t)(-1) && PyErr_Occurred()) { |
7094 | 0 | goto exit; |
7095 | 0 | } |
7096 | 0 | return_value = os_getsid_impl(module, pid); |
7097 | |
|
7098 | 0 | exit: |
7099 | 0 | return return_value; |
7100 | 0 | } |
7101 | | |
7102 | | #endif /* defined(HAVE_GETSID) */ |
7103 | | |
7104 | | #if defined(HAVE_SETSID) |
7105 | | |
7106 | | PyDoc_STRVAR(os_setsid__doc__, |
7107 | | "setsid($module, /)\n" |
7108 | | "--\n" |
7109 | | "\n" |
7110 | | "Call the system call setsid()."); |
7111 | | |
7112 | | #define OS_SETSID_METHODDEF \ |
7113 | | {"setsid", (PyCFunction)os_setsid, METH_NOARGS, os_setsid__doc__}, |
7114 | | |
7115 | | static PyObject * |
7116 | | os_setsid_impl(PyObject *module); |
7117 | | |
7118 | | static PyObject * |
7119 | | os_setsid(PyObject *module, PyObject *Py_UNUSED(ignored)) |
7120 | 0 | { |
7121 | 0 | return os_setsid_impl(module); |
7122 | 0 | } |
7123 | | |
7124 | | #endif /* defined(HAVE_SETSID) */ |
7125 | | |
7126 | | #if defined(HAVE_SETPGID) |
7127 | | |
7128 | | PyDoc_STRVAR(os_setpgid__doc__, |
7129 | | "setpgid($module, pid, pgrp, /)\n" |
7130 | | "--\n" |
7131 | | "\n" |
7132 | | "Call the system call setpgid(pid, pgrp)."); |
7133 | | |
7134 | | #define OS_SETPGID_METHODDEF \ |
7135 | | {"setpgid", _PyCFunction_CAST(os_setpgid), METH_FASTCALL, os_setpgid__doc__}, |
7136 | | |
7137 | | static PyObject * |
7138 | | os_setpgid_impl(PyObject *module, pid_t pid, pid_t pgrp); |
7139 | | |
7140 | | static PyObject * |
7141 | | os_setpgid(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
7142 | 0 | { |
7143 | 0 | PyObject *return_value = NULL; |
7144 | 0 | pid_t pid; |
7145 | 0 | pid_t pgrp; |
7146 | |
|
7147 | 0 | if (!_PyArg_CheckPositional("setpgid", nargs, 2, 2)) { |
7148 | 0 | goto exit; |
7149 | 0 | } |
7150 | 0 | pid = PyLong_AsPid(args[0]); |
7151 | 0 | if (pid == (pid_t)(-1) && PyErr_Occurred()) { |
7152 | 0 | goto exit; |
7153 | 0 | } |
7154 | 0 | pgrp = PyLong_AsPid(args[1]); |
7155 | 0 | if (pgrp == (pid_t)(-1) && PyErr_Occurred()) { |
7156 | 0 | goto exit; |
7157 | 0 | } |
7158 | 0 | return_value = os_setpgid_impl(module, pid, pgrp); |
7159 | |
|
7160 | 0 | exit: |
7161 | 0 | return return_value; |
7162 | 0 | } |
7163 | | |
7164 | | #endif /* defined(HAVE_SETPGID) */ |
7165 | | |
7166 | | #if defined(HAVE_TCGETPGRP) |
7167 | | |
7168 | | PyDoc_STRVAR(os_tcgetpgrp__doc__, |
7169 | | "tcgetpgrp($module, fd, /)\n" |
7170 | | "--\n" |
7171 | | "\n" |
7172 | | "Return the process group associated with the terminal specified by fd."); |
7173 | | |
7174 | | #define OS_TCGETPGRP_METHODDEF \ |
7175 | | {"tcgetpgrp", (PyCFunction)os_tcgetpgrp, METH_O, os_tcgetpgrp__doc__}, |
7176 | | |
7177 | | static PyObject * |
7178 | | os_tcgetpgrp_impl(PyObject *module, int fd); |
7179 | | |
7180 | | static PyObject * |
7181 | | os_tcgetpgrp(PyObject *module, PyObject *arg) |
7182 | 0 | { |
7183 | 0 | PyObject *return_value = NULL; |
7184 | 0 | int fd; |
7185 | |
|
7186 | 0 | fd = PyLong_AsInt(arg); |
7187 | 0 | if (fd == -1 && PyErr_Occurred()) { |
7188 | 0 | goto exit; |
7189 | 0 | } |
7190 | 0 | return_value = os_tcgetpgrp_impl(module, fd); |
7191 | |
|
7192 | 0 | exit: |
7193 | 0 | return return_value; |
7194 | 0 | } |
7195 | | |
7196 | | #endif /* defined(HAVE_TCGETPGRP) */ |
7197 | | |
7198 | | #if defined(HAVE_TCSETPGRP) |
7199 | | |
7200 | | PyDoc_STRVAR(os_tcsetpgrp__doc__, |
7201 | | "tcsetpgrp($module, fd, pgid, /)\n" |
7202 | | "--\n" |
7203 | | "\n" |
7204 | | "Set the process group associated with the terminal specified by fd."); |
7205 | | |
7206 | | #define OS_TCSETPGRP_METHODDEF \ |
7207 | | {"tcsetpgrp", _PyCFunction_CAST(os_tcsetpgrp), METH_FASTCALL, os_tcsetpgrp__doc__}, |
7208 | | |
7209 | | static PyObject * |
7210 | | os_tcsetpgrp_impl(PyObject *module, int fd, pid_t pgid); |
7211 | | |
7212 | | static PyObject * |
7213 | | os_tcsetpgrp(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
7214 | 0 | { |
7215 | 0 | PyObject *return_value = NULL; |
7216 | 0 | int fd; |
7217 | 0 | pid_t pgid; |
7218 | |
|
7219 | 0 | if (!_PyArg_CheckPositional("tcsetpgrp", nargs, 2, 2)) { |
7220 | 0 | goto exit; |
7221 | 0 | } |
7222 | 0 | fd = PyLong_AsInt(args[0]); |
7223 | 0 | if (fd == -1 && PyErr_Occurred()) { |
7224 | 0 | goto exit; |
7225 | 0 | } |
7226 | 0 | pgid = PyLong_AsPid(args[1]); |
7227 | 0 | if (pgid == (pid_t)(-1) && PyErr_Occurred()) { |
7228 | 0 | goto exit; |
7229 | 0 | } |
7230 | 0 | return_value = os_tcsetpgrp_impl(module, fd, pgid); |
7231 | |
|
7232 | 0 | exit: |
7233 | 0 | return return_value; |
7234 | 0 | } |
7235 | | |
7236 | | #endif /* defined(HAVE_TCSETPGRP) */ |
7237 | | |
7238 | | PyDoc_STRVAR(os_open__doc__, |
7239 | | "open($module, /, path, flags, mode=511, *, dir_fd=None)\n" |
7240 | | "--\n" |
7241 | | "\n" |
7242 | | "Open a file for low level IO. Returns a file descriptor (integer).\n" |
7243 | | "\n" |
7244 | | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
7245 | | " and path should be relative; path will then be relative to that directory.\n" |
7246 | | "dir_fd may not be implemented on your platform.\n" |
7247 | | " If it is unavailable, using it will raise a NotImplementedError."); |
7248 | | |
7249 | | #define OS_OPEN_METHODDEF \ |
7250 | | {"open", _PyCFunction_CAST(os_open), METH_FASTCALL|METH_KEYWORDS, os_open__doc__}, |
7251 | | |
7252 | | static int |
7253 | | os_open_impl(PyObject *module, path_t *path, int flags, int mode, int dir_fd); |
7254 | | |
7255 | | static PyObject * |
7256 | | os_open(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
7257 | 216 | { |
7258 | 216 | PyObject *return_value = NULL; |
7259 | 216 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
7260 | | |
7261 | 216 | #define NUM_KEYWORDS 4 |
7262 | 216 | static struct { |
7263 | 216 | PyGC_Head _this_is_not_used; |
7264 | 216 | PyObject_VAR_HEAD |
7265 | 216 | Py_hash_t ob_hash; |
7266 | 216 | PyObject *ob_item[NUM_KEYWORDS]; |
7267 | 216 | } _kwtuple = { |
7268 | 216 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
7269 | 216 | .ob_hash = -1, |
7270 | 216 | .ob_item = { &_Py_ID(path), &_Py_ID(flags), &_Py_ID(mode), &_Py_ID(dir_fd), }, |
7271 | 216 | }; |
7272 | 216 | #undef NUM_KEYWORDS |
7273 | 216 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
7274 | | |
7275 | | #else // !Py_BUILD_CORE |
7276 | | # define KWTUPLE NULL |
7277 | | #endif // !Py_BUILD_CORE |
7278 | | |
7279 | 216 | static const char * const _keywords[] = {"path", "flags", "mode", "dir_fd", NULL}; |
7280 | 216 | static _PyArg_Parser _parser = { |
7281 | 216 | .keywords = _keywords, |
7282 | 216 | .fname = "open", |
7283 | 216 | .kwtuple = KWTUPLE, |
7284 | 216 | }; |
7285 | 216 | #undef KWTUPLE |
7286 | 216 | PyObject *argsbuf[4]; |
7287 | 216 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2; |
7288 | 216 | path_t path = PATH_T_INITIALIZE_P("open", "path", 0, 0, 0, 0); |
7289 | 216 | int flags; |
7290 | 216 | int mode = 511; |
7291 | 216 | int dir_fd = DEFAULT_DIR_FD; |
7292 | 216 | int _return_value; |
7293 | | |
7294 | 216 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
7295 | 216 | /*minpos*/ 2, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
7296 | 216 | if (!args) { |
7297 | 0 | goto exit; |
7298 | 0 | } |
7299 | 216 | if (!path_converter(args[0], &path)) { |
7300 | 0 | goto exit; |
7301 | 0 | } |
7302 | 216 | flags = PyLong_AsInt(args[1]); |
7303 | 216 | if (flags == -1 && PyErr_Occurred()) { |
7304 | 0 | goto exit; |
7305 | 0 | } |
7306 | 216 | if (!noptargs) { |
7307 | 0 | goto skip_optional_pos; |
7308 | 0 | } |
7309 | 216 | if (args[2]) { |
7310 | 216 | mode = PyLong_AsInt(args[2]); |
7311 | 216 | if (mode == -1 && PyErr_Occurred()) { |
7312 | 0 | goto exit; |
7313 | 0 | } |
7314 | 216 | if (!--noptargs) { |
7315 | 216 | goto skip_optional_pos; |
7316 | 216 | } |
7317 | 216 | } |
7318 | 216 | skip_optional_pos: |
7319 | 216 | if (!noptargs) { |
7320 | 216 | goto skip_optional_kwonly; |
7321 | 216 | } |
7322 | 0 | if (!OPENAT_DIR_FD_CONVERTER(args[3], &dir_fd)) { |
7323 | 0 | goto exit; |
7324 | 0 | } |
7325 | 216 | skip_optional_kwonly: |
7326 | 216 | _return_value = os_open_impl(module, &path, flags, mode, dir_fd); |
7327 | 216 | if ((_return_value == -1) && PyErr_Occurred()) { |
7328 | 0 | goto exit; |
7329 | 0 | } |
7330 | 216 | return_value = PyLong_FromLong((long)_return_value); |
7331 | | |
7332 | 216 | exit: |
7333 | | /* Cleanup for path */ |
7334 | 216 | path_cleanup(&path); |
7335 | | |
7336 | 216 | return return_value; |
7337 | 216 | } |
7338 | | |
7339 | | PyDoc_STRVAR(os_close__doc__, |
7340 | | "close($module, /, fd)\n" |
7341 | | "--\n" |
7342 | | "\n" |
7343 | | "Close a file descriptor."); |
7344 | | |
7345 | | #define OS_CLOSE_METHODDEF \ |
7346 | | {"close", _PyCFunction_CAST(os_close), METH_FASTCALL|METH_KEYWORDS, os_close__doc__}, |
7347 | | |
7348 | | static PyObject * |
7349 | | os_close_impl(PyObject *module, int fd); |
7350 | | |
7351 | | static PyObject * |
7352 | | os_close(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
7353 | 0 | { |
7354 | 0 | PyObject *return_value = NULL; |
7355 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
7356 | |
|
7357 | 0 | #define NUM_KEYWORDS 1 |
7358 | 0 | static struct { |
7359 | 0 | PyGC_Head _this_is_not_used; |
7360 | 0 | PyObject_VAR_HEAD |
7361 | 0 | Py_hash_t ob_hash; |
7362 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
7363 | 0 | } _kwtuple = { |
7364 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
7365 | 0 | .ob_hash = -1, |
7366 | 0 | .ob_item = { &_Py_ID(fd), }, |
7367 | 0 | }; |
7368 | 0 | #undef NUM_KEYWORDS |
7369 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
7370 | |
|
7371 | | #else // !Py_BUILD_CORE |
7372 | | # define KWTUPLE NULL |
7373 | | #endif // !Py_BUILD_CORE |
7374 | |
|
7375 | 0 | static const char * const _keywords[] = {"fd", NULL}; |
7376 | 0 | static _PyArg_Parser _parser = { |
7377 | 0 | .keywords = _keywords, |
7378 | 0 | .fname = "close", |
7379 | 0 | .kwtuple = KWTUPLE, |
7380 | 0 | }; |
7381 | 0 | #undef KWTUPLE |
7382 | 0 | PyObject *argsbuf[1]; |
7383 | 0 | int fd; |
7384 | |
|
7385 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
7386 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
7387 | 0 | if (!args) { |
7388 | 0 | goto exit; |
7389 | 0 | } |
7390 | 0 | fd = PyLong_AsInt(args[0]); |
7391 | 0 | if (fd == -1 && PyErr_Occurred()) { |
7392 | 0 | goto exit; |
7393 | 0 | } |
7394 | 0 | return_value = os_close_impl(module, fd); |
7395 | |
|
7396 | 0 | exit: |
7397 | 0 | return return_value; |
7398 | 0 | } |
7399 | | |
7400 | | PyDoc_STRVAR(os_closerange__doc__, |
7401 | | "closerange($module, fd_low, fd_high, /)\n" |
7402 | | "--\n" |
7403 | | "\n" |
7404 | | "Closes all file descriptors in [fd_low, fd_high), ignoring errors."); |
7405 | | |
7406 | | #define OS_CLOSERANGE_METHODDEF \ |
7407 | | {"closerange", _PyCFunction_CAST(os_closerange), METH_FASTCALL, os_closerange__doc__}, |
7408 | | |
7409 | | static PyObject * |
7410 | | os_closerange_impl(PyObject *module, int fd_low, int fd_high); |
7411 | | |
7412 | | static PyObject * |
7413 | | os_closerange(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
7414 | 0 | { |
7415 | 0 | PyObject *return_value = NULL; |
7416 | 0 | int fd_low; |
7417 | 0 | int fd_high; |
7418 | |
|
7419 | 0 | if (!_PyArg_CheckPositional("closerange", nargs, 2, 2)) { |
7420 | 0 | goto exit; |
7421 | 0 | } |
7422 | 0 | fd_low = PyLong_AsInt(args[0]); |
7423 | 0 | if (fd_low == -1 && PyErr_Occurred()) { |
7424 | 0 | goto exit; |
7425 | 0 | } |
7426 | 0 | fd_high = PyLong_AsInt(args[1]); |
7427 | 0 | if (fd_high == -1 && PyErr_Occurred()) { |
7428 | 0 | goto exit; |
7429 | 0 | } |
7430 | 0 | return_value = os_closerange_impl(module, fd_low, fd_high); |
7431 | |
|
7432 | 0 | exit: |
7433 | 0 | return return_value; |
7434 | 0 | } |
7435 | | |
7436 | | PyDoc_STRVAR(os_dup__doc__, |
7437 | | "dup($module, fd, /)\n" |
7438 | | "--\n" |
7439 | | "\n" |
7440 | | "Return a duplicate of a file descriptor."); |
7441 | | |
7442 | | #define OS_DUP_METHODDEF \ |
7443 | | {"dup", (PyCFunction)os_dup, METH_O, os_dup__doc__}, |
7444 | | |
7445 | | static int |
7446 | | os_dup_impl(PyObject *module, int fd); |
7447 | | |
7448 | | static PyObject * |
7449 | | os_dup(PyObject *module, PyObject *arg) |
7450 | 0 | { |
7451 | 0 | PyObject *return_value = NULL; |
7452 | 0 | int fd; |
7453 | 0 | int _return_value; |
7454 | |
|
7455 | 0 | fd = PyLong_AsInt(arg); |
7456 | 0 | if (fd == -1 && PyErr_Occurred()) { |
7457 | 0 | goto exit; |
7458 | 0 | } |
7459 | 0 | _return_value = os_dup_impl(module, fd); |
7460 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
7461 | 0 | goto exit; |
7462 | 0 | } |
7463 | 0 | return_value = PyLong_FromLong((long)_return_value); |
7464 | |
|
7465 | 0 | exit: |
7466 | 0 | return return_value; |
7467 | 0 | } |
7468 | | |
7469 | | #if ((defined(HAVE_DUP3) || defined(F_DUPFD) || defined(MS_WINDOWS))) |
7470 | | |
7471 | | PyDoc_STRVAR(os_dup2__doc__, |
7472 | | "dup2($module, /, fd, fd2, inheritable=True)\n" |
7473 | | "--\n" |
7474 | | "\n" |
7475 | | "Duplicate file descriptor."); |
7476 | | |
7477 | | #define OS_DUP2_METHODDEF \ |
7478 | | {"dup2", _PyCFunction_CAST(os_dup2), METH_FASTCALL|METH_KEYWORDS, os_dup2__doc__}, |
7479 | | |
7480 | | static int |
7481 | | os_dup2_impl(PyObject *module, int fd, int fd2, int inheritable); |
7482 | | |
7483 | | static PyObject * |
7484 | | os_dup2(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
7485 | 0 | { |
7486 | 0 | PyObject *return_value = NULL; |
7487 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
7488 | |
|
7489 | 0 | #define NUM_KEYWORDS 3 |
7490 | 0 | static struct { |
7491 | 0 | PyGC_Head _this_is_not_used; |
7492 | 0 | PyObject_VAR_HEAD |
7493 | 0 | Py_hash_t ob_hash; |
7494 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
7495 | 0 | } _kwtuple = { |
7496 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
7497 | 0 | .ob_hash = -1, |
7498 | 0 | .ob_item = { &_Py_ID(fd), &_Py_ID(fd2), &_Py_ID(inheritable), }, |
7499 | 0 | }; |
7500 | 0 | #undef NUM_KEYWORDS |
7501 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
7502 | |
|
7503 | | #else // !Py_BUILD_CORE |
7504 | | # define KWTUPLE NULL |
7505 | | #endif // !Py_BUILD_CORE |
7506 | |
|
7507 | 0 | static const char * const _keywords[] = {"fd", "fd2", "inheritable", NULL}; |
7508 | 0 | static _PyArg_Parser _parser = { |
7509 | 0 | .keywords = _keywords, |
7510 | 0 | .fname = "dup2", |
7511 | 0 | .kwtuple = KWTUPLE, |
7512 | 0 | }; |
7513 | 0 | #undef KWTUPLE |
7514 | 0 | PyObject *argsbuf[3]; |
7515 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2; |
7516 | 0 | int fd; |
7517 | 0 | int fd2; |
7518 | 0 | int inheritable = 1; |
7519 | 0 | int _return_value; |
7520 | |
|
7521 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
7522 | 0 | /*minpos*/ 2, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
7523 | 0 | if (!args) { |
7524 | 0 | goto exit; |
7525 | 0 | } |
7526 | 0 | fd = PyLong_AsInt(args[0]); |
7527 | 0 | if (fd == -1 && PyErr_Occurred()) { |
7528 | 0 | goto exit; |
7529 | 0 | } |
7530 | 0 | fd2 = PyLong_AsInt(args[1]); |
7531 | 0 | if (fd2 == -1 && PyErr_Occurred()) { |
7532 | 0 | goto exit; |
7533 | 0 | } |
7534 | 0 | if (!noptargs) { |
7535 | 0 | goto skip_optional_pos; |
7536 | 0 | } |
7537 | 0 | inheritable = PyObject_IsTrue(args[2]); |
7538 | 0 | if (inheritable < 0) { |
7539 | 0 | goto exit; |
7540 | 0 | } |
7541 | 0 | skip_optional_pos: |
7542 | 0 | _return_value = os_dup2_impl(module, fd, fd2, inheritable); |
7543 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
7544 | 0 | goto exit; |
7545 | 0 | } |
7546 | 0 | return_value = PyLong_FromLong((long)_return_value); |
7547 | |
|
7548 | 0 | exit: |
7549 | 0 | return return_value; |
7550 | 0 | } |
7551 | | |
7552 | | #endif /* ((defined(HAVE_DUP3) || defined(F_DUPFD) || defined(MS_WINDOWS))) */ |
7553 | | |
7554 | | #if defined(HAVE_LOCKF) |
7555 | | |
7556 | | PyDoc_STRVAR(os_lockf__doc__, |
7557 | | "lockf($module, fd, command, length, /)\n" |
7558 | | "--\n" |
7559 | | "\n" |
7560 | | "Apply, test or remove a POSIX lock on an open file descriptor.\n" |
7561 | | "\n" |
7562 | | " fd\n" |
7563 | | " An open file descriptor.\n" |
7564 | | " command\n" |
7565 | | " One of F_LOCK, F_TLOCK, F_ULOCK or F_TEST.\n" |
7566 | | " length\n" |
7567 | | " The number of bytes to lock, starting at the current position."); |
7568 | | |
7569 | | #define OS_LOCKF_METHODDEF \ |
7570 | | {"lockf", _PyCFunction_CAST(os_lockf), METH_FASTCALL, os_lockf__doc__}, |
7571 | | |
7572 | | static PyObject * |
7573 | | os_lockf_impl(PyObject *module, int fd, int command, Py_off_t length); |
7574 | | |
7575 | | static PyObject * |
7576 | | os_lockf(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
7577 | 0 | { |
7578 | 0 | PyObject *return_value = NULL; |
7579 | 0 | int fd; |
7580 | 0 | int command; |
7581 | 0 | Py_off_t length; |
7582 | |
|
7583 | 0 | if (!_PyArg_CheckPositional("lockf", nargs, 3, 3)) { |
7584 | 0 | goto exit; |
7585 | 0 | } |
7586 | 0 | fd = PyLong_AsInt(args[0]); |
7587 | 0 | if (fd == -1 && PyErr_Occurred()) { |
7588 | 0 | goto exit; |
7589 | 0 | } |
7590 | 0 | command = PyLong_AsInt(args[1]); |
7591 | 0 | if (command == -1 && PyErr_Occurred()) { |
7592 | 0 | goto exit; |
7593 | 0 | } |
7594 | 0 | if (!Py_off_t_converter(args[2], &length)) { |
7595 | 0 | goto exit; |
7596 | 0 | } |
7597 | 0 | return_value = os_lockf_impl(module, fd, command, length); |
7598 | |
|
7599 | 0 | exit: |
7600 | 0 | return return_value; |
7601 | 0 | } |
7602 | | |
7603 | | #endif /* defined(HAVE_LOCKF) */ |
7604 | | |
7605 | | PyDoc_STRVAR(os_lseek__doc__, |
7606 | | "lseek($module, fd, position, whence, /)\n" |
7607 | | "--\n" |
7608 | | "\n" |
7609 | | "Set the position of a file descriptor. Return the new position.\n" |
7610 | | "\n" |
7611 | | " fd\n" |
7612 | | " An open file descriptor, as returned by os.open().\n" |
7613 | | " position\n" |
7614 | | " Position, interpreted relative to \'whence\'.\n" |
7615 | | " whence\n" |
7616 | | " The relative position to seek from. Valid values are:\n" |
7617 | | " - SEEK_SET: seek from the start of the file.\n" |
7618 | | " - SEEK_CUR: seek from the current file position.\n" |
7619 | | " - SEEK_END: seek from the end of the file.\n" |
7620 | | "\n" |
7621 | | "The return value is the number of bytes relative to the beginning of the file."); |
7622 | | |
7623 | | #define OS_LSEEK_METHODDEF \ |
7624 | | {"lseek", _PyCFunction_CAST(os_lseek), METH_FASTCALL, os_lseek__doc__}, |
7625 | | |
7626 | | static Py_off_t |
7627 | | os_lseek_impl(PyObject *module, int fd, Py_off_t position, int how); |
7628 | | |
7629 | | static PyObject * |
7630 | | os_lseek(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
7631 | 0 | { |
7632 | 0 | PyObject *return_value = NULL; |
7633 | 0 | int fd; |
7634 | 0 | Py_off_t position; |
7635 | 0 | int how; |
7636 | 0 | Py_off_t _return_value; |
7637 | |
|
7638 | 0 | if (!_PyArg_CheckPositional("lseek", nargs, 3, 3)) { |
7639 | 0 | goto exit; |
7640 | 0 | } |
7641 | 0 | fd = PyLong_AsInt(args[0]); |
7642 | 0 | if (fd == -1 && PyErr_Occurred()) { |
7643 | 0 | goto exit; |
7644 | 0 | } |
7645 | 0 | if (!Py_off_t_converter(args[1], &position)) { |
7646 | 0 | goto exit; |
7647 | 0 | } |
7648 | 0 | how = PyLong_AsInt(args[2]); |
7649 | 0 | if (how == -1 && PyErr_Occurred()) { |
7650 | 0 | goto exit; |
7651 | 0 | } |
7652 | 0 | _return_value = os_lseek_impl(module, fd, position, how); |
7653 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
7654 | 0 | goto exit; |
7655 | 0 | } |
7656 | 0 | return_value = PyLong_FromPy_off_t(_return_value); |
7657 | |
|
7658 | 0 | exit: |
7659 | 0 | return return_value; |
7660 | 0 | } |
7661 | | |
7662 | | PyDoc_STRVAR(os_read__doc__, |
7663 | | "read($module, fd, length, /)\n" |
7664 | | "--\n" |
7665 | | "\n" |
7666 | | "Read from a file descriptor. Returns a bytes object."); |
7667 | | |
7668 | | #define OS_READ_METHODDEF \ |
7669 | | {"read", _PyCFunction_CAST(os_read), METH_FASTCALL, os_read__doc__}, |
7670 | | |
7671 | | static PyObject * |
7672 | | os_read_impl(PyObject *module, int fd, Py_ssize_t length); |
7673 | | |
7674 | | static PyObject * |
7675 | | os_read(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
7676 | 0 | { |
7677 | 0 | PyObject *return_value = NULL; |
7678 | 0 | int fd; |
7679 | 0 | Py_ssize_t length; |
7680 | |
|
7681 | 0 | if (!_PyArg_CheckPositional("read", nargs, 2, 2)) { |
7682 | 0 | goto exit; |
7683 | 0 | } |
7684 | 0 | fd = PyLong_AsInt(args[0]); |
7685 | 0 | if (fd == -1 && PyErr_Occurred()) { |
7686 | 0 | goto exit; |
7687 | 0 | } |
7688 | 0 | { |
7689 | 0 | Py_ssize_t ival = -1; |
7690 | 0 | PyObject *iobj = _PyNumber_Index(args[1]); |
7691 | 0 | if (iobj != NULL) { |
7692 | 0 | ival = PyLong_AsSsize_t(iobj); |
7693 | 0 | Py_DECREF(iobj); |
7694 | 0 | } |
7695 | 0 | if (ival == -1 && PyErr_Occurred()) { |
7696 | 0 | goto exit; |
7697 | 0 | } |
7698 | 0 | length = ival; |
7699 | 0 | } |
7700 | 0 | return_value = os_read_impl(module, fd, length); |
7701 | |
|
7702 | 0 | exit: |
7703 | 0 | return return_value; |
7704 | 0 | } |
7705 | | |
7706 | | PyDoc_STRVAR(os_readinto__doc__, |
7707 | | "readinto($module, fd, buffer, /)\n" |
7708 | | "--\n" |
7709 | | "\n" |
7710 | | "Read into a buffer object from a file descriptor.\n" |
7711 | | "\n" |
7712 | | "The buffer should be mutable and bytes-like. On success, returns the number of\n" |
7713 | | "bytes read. Less bytes may be read than the size of the buffer. The underlying\n" |
7714 | | "system call will be retried when interrupted by a signal, unless the signal\n" |
7715 | | "handler raises an exception. Other errors will not be retried and an error will\n" |
7716 | | "be raised.\n" |
7717 | | "\n" |
7718 | | "Returns 0 if *fd* is at end of file or if the provided *buffer* has length 0\n" |
7719 | | "(which can be used to check for errors without reading data). Never returns\n" |
7720 | | "negative."); |
7721 | | |
7722 | | #define OS_READINTO_METHODDEF \ |
7723 | | {"readinto", _PyCFunction_CAST(os_readinto), METH_FASTCALL, os_readinto__doc__}, |
7724 | | |
7725 | | static Py_ssize_t |
7726 | | os_readinto_impl(PyObject *module, int fd, Py_buffer *buffer); |
7727 | | |
7728 | | static PyObject * |
7729 | | os_readinto(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
7730 | 0 | { |
7731 | 0 | PyObject *return_value = NULL; |
7732 | 0 | int fd; |
7733 | 0 | Py_buffer buffer = {NULL, NULL}; |
7734 | 0 | Py_ssize_t _return_value; |
7735 | |
|
7736 | 0 | if (!_PyArg_CheckPositional("readinto", nargs, 2, 2)) { |
7737 | 0 | goto exit; |
7738 | 0 | } |
7739 | 0 | fd = PyLong_AsInt(args[0]); |
7740 | 0 | if (fd == -1 && PyErr_Occurred()) { |
7741 | 0 | goto exit; |
7742 | 0 | } |
7743 | 0 | if (PyObject_GetBuffer(args[1], &buffer, PyBUF_WRITABLE) < 0) { |
7744 | 0 | _PyArg_BadArgument("readinto", "argument 2", "read-write bytes-like object", args[1]); |
7745 | 0 | goto exit; |
7746 | 0 | } |
7747 | 0 | _return_value = os_readinto_impl(module, fd, &buffer); |
7748 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
7749 | 0 | goto exit; |
7750 | 0 | } |
7751 | 0 | return_value = PyLong_FromSsize_t(_return_value); |
7752 | |
|
7753 | 0 | exit: |
7754 | | /* Cleanup for buffer */ |
7755 | 0 | if (buffer.obj) { |
7756 | 0 | PyBuffer_Release(&buffer); |
7757 | 0 | } |
7758 | |
|
7759 | 0 | return return_value; |
7760 | 0 | } |
7761 | | |
7762 | | #if defined(HAVE_READV) |
7763 | | |
7764 | | PyDoc_STRVAR(os_readv__doc__, |
7765 | | "readv($module, fd, buffers, /)\n" |
7766 | | "--\n" |
7767 | | "\n" |
7768 | | "Read from a file descriptor fd into an iterable of buffers.\n" |
7769 | | "\n" |
7770 | | "The buffers should be mutable buffers accepting bytes.\n" |
7771 | | "readv will transfer data into each buffer until it is full\n" |
7772 | | "and then move on to the next buffer in the sequence to hold\n" |
7773 | | "the rest of the data.\n" |
7774 | | "\n" |
7775 | | "readv returns the total number of bytes read,\n" |
7776 | | "which may be less than the total capacity of all the buffers."); |
7777 | | |
7778 | | #define OS_READV_METHODDEF \ |
7779 | | {"readv", _PyCFunction_CAST(os_readv), METH_FASTCALL, os_readv__doc__}, |
7780 | | |
7781 | | static Py_ssize_t |
7782 | | os_readv_impl(PyObject *module, int fd, PyObject *buffers); |
7783 | | |
7784 | | static PyObject * |
7785 | | os_readv(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
7786 | 0 | { |
7787 | 0 | PyObject *return_value = NULL; |
7788 | 0 | int fd; |
7789 | 0 | PyObject *buffers; |
7790 | 0 | Py_ssize_t _return_value; |
7791 | |
|
7792 | 0 | if (!_PyArg_CheckPositional("readv", nargs, 2, 2)) { |
7793 | 0 | goto exit; |
7794 | 0 | } |
7795 | 0 | fd = PyLong_AsInt(args[0]); |
7796 | 0 | if (fd == -1 && PyErr_Occurred()) { |
7797 | 0 | goto exit; |
7798 | 0 | } |
7799 | 0 | buffers = args[1]; |
7800 | 0 | _return_value = os_readv_impl(module, fd, buffers); |
7801 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
7802 | 0 | goto exit; |
7803 | 0 | } |
7804 | 0 | return_value = PyLong_FromSsize_t(_return_value); |
7805 | |
|
7806 | 0 | exit: |
7807 | 0 | return return_value; |
7808 | 0 | } |
7809 | | |
7810 | | #endif /* defined(HAVE_READV) */ |
7811 | | |
7812 | | #if defined(HAVE_PREAD) |
7813 | | |
7814 | | PyDoc_STRVAR(os_pread__doc__, |
7815 | | "pread($module, fd, length, offset, /)\n" |
7816 | | "--\n" |
7817 | | "\n" |
7818 | | "Read a number of bytes from a file descriptor starting at a particular offset.\n" |
7819 | | "\n" |
7820 | | "Read length bytes from file descriptor fd, starting at offset bytes from\n" |
7821 | | "the beginning of the file. The file offset remains unchanged."); |
7822 | | |
7823 | | #define OS_PREAD_METHODDEF \ |
7824 | | {"pread", _PyCFunction_CAST(os_pread), METH_FASTCALL, os_pread__doc__}, |
7825 | | |
7826 | | static PyObject * |
7827 | | os_pread_impl(PyObject *module, int fd, Py_ssize_t length, Py_off_t offset); |
7828 | | |
7829 | | static PyObject * |
7830 | | os_pread(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
7831 | 0 | { |
7832 | 0 | PyObject *return_value = NULL; |
7833 | 0 | int fd; |
7834 | 0 | Py_ssize_t length; |
7835 | 0 | Py_off_t offset; |
7836 | |
|
7837 | 0 | if (!_PyArg_CheckPositional("pread", nargs, 3, 3)) { |
7838 | 0 | goto exit; |
7839 | 0 | } |
7840 | 0 | fd = PyLong_AsInt(args[0]); |
7841 | 0 | if (fd == -1 && PyErr_Occurred()) { |
7842 | 0 | goto exit; |
7843 | 0 | } |
7844 | 0 | { |
7845 | 0 | Py_ssize_t ival = -1; |
7846 | 0 | PyObject *iobj = _PyNumber_Index(args[1]); |
7847 | 0 | if (iobj != NULL) { |
7848 | 0 | ival = PyLong_AsSsize_t(iobj); |
7849 | 0 | Py_DECREF(iobj); |
7850 | 0 | } |
7851 | 0 | if (ival == -1 && PyErr_Occurred()) { |
7852 | 0 | goto exit; |
7853 | 0 | } |
7854 | 0 | length = ival; |
7855 | 0 | } |
7856 | 0 | if (!Py_off_t_converter(args[2], &offset)) { |
7857 | 0 | goto exit; |
7858 | 0 | } |
7859 | 0 | return_value = os_pread_impl(module, fd, length, offset); |
7860 | |
|
7861 | 0 | exit: |
7862 | 0 | return return_value; |
7863 | 0 | } |
7864 | | |
7865 | | #endif /* defined(HAVE_PREAD) */ |
7866 | | |
7867 | | #if (defined(HAVE_PREADV) || defined (HAVE_PREADV2)) |
7868 | | |
7869 | | PyDoc_STRVAR(os_preadv__doc__, |
7870 | | "preadv($module, fd, buffers, offset, flags=0, /)\n" |
7871 | | "--\n" |
7872 | | "\n" |
7873 | | "Reads from a file descriptor into a number of mutable bytes-like objects.\n" |
7874 | | "\n" |
7875 | | "Combines the functionality of readv() and pread(). As readv(), it will\n" |
7876 | | "transfer data into each buffer until it is full and then move on to the next\n" |
7877 | | "buffer in the sequence to hold the rest of the data. Its fourth argument,\n" |
7878 | | "specifies the file offset at which the input operation is to be performed. It\n" |
7879 | | "will return the total number of bytes read (which can be less than the total\n" |
7880 | | "capacity of all the objects).\n" |
7881 | | "\n" |
7882 | | "The flags argument contains a bitwise OR of zero or more of the following flags:\n" |
7883 | | "\n" |
7884 | | "- RWF_HIPRI\n" |
7885 | | "- RWF_NOWAIT\n" |
7886 | | "\n" |
7887 | | "Using non-zero flags requires Linux 4.6 or newer."); |
7888 | | |
7889 | | #define OS_PREADV_METHODDEF \ |
7890 | | {"preadv", _PyCFunction_CAST(os_preadv), METH_FASTCALL, os_preadv__doc__}, |
7891 | | |
7892 | | static Py_ssize_t |
7893 | | os_preadv_impl(PyObject *module, int fd, PyObject *buffers, Py_off_t offset, |
7894 | | int flags); |
7895 | | |
7896 | | static PyObject * |
7897 | | os_preadv(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
7898 | 0 | { |
7899 | 0 | PyObject *return_value = NULL; |
7900 | 0 | int fd; |
7901 | 0 | PyObject *buffers; |
7902 | 0 | Py_off_t offset; |
7903 | 0 | int flags = 0; |
7904 | 0 | Py_ssize_t _return_value; |
7905 | |
|
7906 | 0 | if (!_PyArg_CheckPositional("preadv", nargs, 3, 4)) { |
7907 | 0 | goto exit; |
7908 | 0 | } |
7909 | 0 | fd = PyLong_AsInt(args[0]); |
7910 | 0 | if (fd == -1 && PyErr_Occurred()) { |
7911 | 0 | goto exit; |
7912 | 0 | } |
7913 | 0 | buffers = args[1]; |
7914 | 0 | if (!Py_off_t_converter(args[2], &offset)) { |
7915 | 0 | goto exit; |
7916 | 0 | } |
7917 | 0 | if (nargs < 4) { |
7918 | 0 | goto skip_optional; |
7919 | 0 | } |
7920 | 0 | flags = PyLong_AsInt(args[3]); |
7921 | 0 | if (flags == -1 && PyErr_Occurred()) { |
7922 | 0 | goto exit; |
7923 | 0 | } |
7924 | 0 | skip_optional: |
7925 | 0 | _return_value = os_preadv_impl(module, fd, buffers, offset, flags); |
7926 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
7927 | 0 | goto exit; |
7928 | 0 | } |
7929 | 0 | return_value = PyLong_FromSsize_t(_return_value); |
7930 | |
|
7931 | 0 | exit: |
7932 | 0 | return return_value; |
7933 | 0 | } |
7934 | | |
7935 | | #endif /* (defined(HAVE_PREADV) || defined (HAVE_PREADV2)) */ |
7936 | | |
7937 | | PyDoc_STRVAR(os_write__doc__, |
7938 | | "write($module, fd, data, /)\n" |
7939 | | "--\n" |
7940 | | "\n" |
7941 | | "Write a bytes object to a file descriptor."); |
7942 | | |
7943 | | #define OS_WRITE_METHODDEF \ |
7944 | | {"write", _PyCFunction_CAST(os_write), METH_FASTCALL, os_write__doc__}, |
7945 | | |
7946 | | static Py_ssize_t |
7947 | | os_write_impl(PyObject *module, int fd, Py_buffer *data); |
7948 | | |
7949 | | static PyObject * |
7950 | | os_write(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
7951 | 0 | { |
7952 | 0 | PyObject *return_value = NULL; |
7953 | 0 | int fd; |
7954 | 0 | Py_buffer data = {NULL, NULL}; |
7955 | 0 | Py_ssize_t _return_value; |
7956 | |
|
7957 | 0 | if (!_PyArg_CheckPositional("write", nargs, 2, 2)) { |
7958 | 0 | goto exit; |
7959 | 0 | } |
7960 | 0 | fd = PyLong_AsInt(args[0]); |
7961 | 0 | if (fd == -1 && PyErr_Occurred()) { |
7962 | 0 | goto exit; |
7963 | 0 | } |
7964 | 0 | if (PyObject_GetBuffer(args[1], &data, PyBUF_SIMPLE) != 0) { |
7965 | 0 | goto exit; |
7966 | 0 | } |
7967 | 0 | _return_value = os_write_impl(module, fd, &data); |
7968 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
7969 | 0 | goto exit; |
7970 | 0 | } |
7971 | 0 | return_value = PyLong_FromSsize_t(_return_value); |
7972 | |
|
7973 | 0 | exit: |
7974 | | /* Cleanup for data */ |
7975 | 0 | if (data.obj) { |
7976 | 0 | PyBuffer_Release(&data); |
7977 | 0 | } |
7978 | |
|
7979 | 0 | return return_value; |
7980 | 0 | } |
7981 | | |
7982 | | #if defined(HAVE_SENDFILE) && defined(__APPLE__) |
7983 | | |
7984 | | PyDoc_STRVAR(os_sendfile__doc__, |
7985 | | "sendfile($module, /, out_fd, in_fd, offset, count, headers=(),\n" |
7986 | | " trailers=(), flags=0)\n" |
7987 | | "--\n" |
7988 | | "\n" |
7989 | | "Copy count bytes from file descriptor in_fd to file descriptor out_fd."); |
7990 | | |
7991 | | #define OS_SENDFILE_METHODDEF \ |
7992 | | {"sendfile", _PyCFunction_CAST(os_sendfile), METH_FASTCALL|METH_KEYWORDS, os_sendfile__doc__}, |
7993 | | |
7994 | | static PyObject * |
7995 | | os_sendfile_impl(PyObject *module, int out_fd, int in_fd, Py_off_t offset, |
7996 | | Py_off_t sbytes, PyObject *headers, PyObject *trailers, |
7997 | | int flags); |
7998 | | |
7999 | | static PyObject * |
8000 | | os_sendfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
8001 | | { |
8002 | | PyObject *return_value = NULL; |
8003 | | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
8004 | | |
8005 | | #define NUM_KEYWORDS 7 |
8006 | | static struct { |
8007 | | PyGC_Head _this_is_not_used; |
8008 | | PyObject_VAR_HEAD |
8009 | | Py_hash_t ob_hash; |
8010 | | PyObject *ob_item[NUM_KEYWORDS]; |
8011 | | } _kwtuple = { |
8012 | | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
8013 | | .ob_hash = -1, |
8014 | | .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), }, |
8015 | | }; |
8016 | | #undef NUM_KEYWORDS |
8017 | | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
8018 | | |
8019 | | #else // !Py_BUILD_CORE |
8020 | | # define KWTUPLE NULL |
8021 | | #endif // !Py_BUILD_CORE |
8022 | | |
8023 | | static const char * const _keywords[] = {"out_fd", "in_fd", "offset", "count", "headers", "trailers", "flags", NULL}; |
8024 | | static _PyArg_Parser _parser = { |
8025 | | .keywords = _keywords, |
8026 | | .fname = "sendfile", |
8027 | | .kwtuple = KWTUPLE, |
8028 | | }; |
8029 | | #undef KWTUPLE |
8030 | | PyObject *argsbuf[7]; |
8031 | | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 4; |
8032 | | int out_fd; |
8033 | | int in_fd; |
8034 | | Py_off_t offset; |
8035 | | Py_off_t sbytes; |
8036 | | PyObject *headers = NULL; |
8037 | | PyObject *trailers = NULL; |
8038 | | int flags = 0; |
8039 | | |
8040 | | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
8041 | | /*minpos*/ 4, /*maxpos*/ 7, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
8042 | | if (!args) { |
8043 | | goto exit; |
8044 | | } |
8045 | | out_fd = PyLong_AsInt(args[0]); |
8046 | | if (out_fd == -1 && PyErr_Occurred()) { |
8047 | | goto exit; |
8048 | | } |
8049 | | in_fd = PyLong_AsInt(args[1]); |
8050 | | if (in_fd == -1 && PyErr_Occurred()) { |
8051 | | goto exit; |
8052 | | } |
8053 | | if (!Py_off_t_converter(args[2], &offset)) { |
8054 | | goto exit; |
8055 | | } |
8056 | | if (!Py_off_t_converter(args[3], &sbytes)) { |
8057 | | goto exit; |
8058 | | } |
8059 | | if (!noptargs) { |
8060 | | goto skip_optional_pos; |
8061 | | } |
8062 | | if (args[4]) { |
8063 | | headers = args[4]; |
8064 | | if (!--noptargs) { |
8065 | | goto skip_optional_pos; |
8066 | | } |
8067 | | } |
8068 | | if (args[5]) { |
8069 | | trailers = args[5]; |
8070 | | if (!--noptargs) { |
8071 | | goto skip_optional_pos; |
8072 | | } |
8073 | | } |
8074 | | flags = PyLong_AsInt(args[6]); |
8075 | | if (flags == -1 && PyErr_Occurred()) { |
8076 | | goto exit; |
8077 | | } |
8078 | | skip_optional_pos: |
8079 | | return_value = os_sendfile_impl(module, out_fd, in_fd, offset, sbytes, headers, trailers, flags); |
8080 | | |
8081 | | exit: |
8082 | | return return_value; |
8083 | | } |
8084 | | |
8085 | | #endif /* defined(HAVE_SENDFILE) && defined(__APPLE__) */ |
8086 | | |
8087 | | #if defined(HAVE_SENDFILE) && !defined(__APPLE__) && (defined(__FreeBSD__) || defined(__DragonFly__)) |
8088 | | |
8089 | | PyDoc_STRVAR(os_sendfile__doc__, |
8090 | | "sendfile($module, /, out_fd, in_fd, offset, count, headers=(),\n" |
8091 | | " trailers=(), flags=0)\n" |
8092 | | "--\n" |
8093 | | "\n" |
8094 | | "Copy count bytes from file descriptor in_fd to file descriptor out_fd."); |
8095 | | |
8096 | | #define OS_SENDFILE_METHODDEF \ |
8097 | | {"sendfile", _PyCFunction_CAST(os_sendfile), METH_FASTCALL|METH_KEYWORDS, os_sendfile__doc__}, |
8098 | | |
8099 | | static PyObject * |
8100 | | os_sendfile_impl(PyObject *module, int out_fd, int in_fd, Py_off_t offset, |
8101 | | Py_ssize_t count, PyObject *headers, PyObject *trailers, |
8102 | | int flags); |
8103 | | |
8104 | | static PyObject * |
8105 | | os_sendfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
8106 | | { |
8107 | | PyObject *return_value = NULL; |
8108 | | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
8109 | | |
8110 | | #define NUM_KEYWORDS 7 |
8111 | | static struct { |
8112 | | PyGC_Head _this_is_not_used; |
8113 | | PyObject_VAR_HEAD |
8114 | | Py_hash_t ob_hash; |
8115 | | PyObject *ob_item[NUM_KEYWORDS]; |
8116 | | } _kwtuple = { |
8117 | | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
8118 | | .ob_hash = -1, |
8119 | | .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), }, |
8120 | | }; |
8121 | | #undef NUM_KEYWORDS |
8122 | | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
8123 | | |
8124 | | #else // !Py_BUILD_CORE |
8125 | | # define KWTUPLE NULL |
8126 | | #endif // !Py_BUILD_CORE |
8127 | | |
8128 | | static const char * const _keywords[] = {"out_fd", "in_fd", "offset", "count", "headers", "trailers", "flags", NULL}; |
8129 | | static _PyArg_Parser _parser = { |
8130 | | .keywords = _keywords, |
8131 | | .fname = "sendfile", |
8132 | | .kwtuple = KWTUPLE, |
8133 | | }; |
8134 | | #undef KWTUPLE |
8135 | | PyObject *argsbuf[7]; |
8136 | | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 4; |
8137 | | int out_fd; |
8138 | | int in_fd; |
8139 | | Py_off_t offset; |
8140 | | Py_ssize_t count; |
8141 | | PyObject *headers = NULL; |
8142 | | PyObject *trailers = NULL; |
8143 | | int flags = 0; |
8144 | | |
8145 | | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
8146 | | /*minpos*/ 4, /*maxpos*/ 7, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
8147 | | if (!args) { |
8148 | | goto exit; |
8149 | | } |
8150 | | out_fd = PyLong_AsInt(args[0]); |
8151 | | if (out_fd == -1 && PyErr_Occurred()) { |
8152 | | goto exit; |
8153 | | } |
8154 | | in_fd = PyLong_AsInt(args[1]); |
8155 | | if (in_fd == -1 && PyErr_Occurred()) { |
8156 | | goto exit; |
8157 | | } |
8158 | | if (!Py_off_t_converter(args[2], &offset)) { |
8159 | | goto exit; |
8160 | | } |
8161 | | { |
8162 | | Py_ssize_t ival = -1; |
8163 | | PyObject *iobj = _PyNumber_Index(args[3]); |
8164 | | if (iobj != NULL) { |
8165 | | ival = PyLong_AsSsize_t(iobj); |
8166 | | Py_DECREF(iobj); |
8167 | | } |
8168 | | if (ival == -1 && PyErr_Occurred()) { |
8169 | | goto exit; |
8170 | | } |
8171 | | count = ival; |
8172 | | } |
8173 | | if (!noptargs) { |
8174 | | goto skip_optional_pos; |
8175 | | } |
8176 | | if (args[4]) { |
8177 | | headers = args[4]; |
8178 | | if (!--noptargs) { |
8179 | | goto skip_optional_pos; |
8180 | | } |
8181 | | } |
8182 | | if (args[5]) { |
8183 | | trailers = args[5]; |
8184 | | if (!--noptargs) { |
8185 | | goto skip_optional_pos; |
8186 | | } |
8187 | | } |
8188 | | flags = PyLong_AsInt(args[6]); |
8189 | | if (flags == -1 && PyErr_Occurred()) { |
8190 | | goto exit; |
8191 | | } |
8192 | | skip_optional_pos: |
8193 | | return_value = os_sendfile_impl(module, out_fd, in_fd, offset, count, headers, trailers, flags); |
8194 | | |
8195 | | exit: |
8196 | | return return_value; |
8197 | | } |
8198 | | |
8199 | | #endif /* defined(HAVE_SENDFILE) && !defined(__APPLE__) && (defined(__FreeBSD__) || defined(__DragonFly__)) */ |
8200 | | |
8201 | | #if defined(HAVE_SENDFILE) && !defined(__APPLE__) && !(defined(__FreeBSD__) || defined(__DragonFly__)) |
8202 | | |
8203 | | PyDoc_STRVAR(os_sendfile__doc__, |
8204 | | "sendfile($module, /, out_fd, in_fd, offset, count)\n" |
8205 | | "--\n" |
8206 | | "\n" |
8207 | | "Copy count bytes from file descriptor in_fd to file descriptor out_fd."); |
8208 | | |
8209 | | #define OS_SENDFILE_METHODDEF \ |
8210 | | {"sendfile", _PyCFunction_CAST(os_sendfile), METH_FASTCALL|METH_KEYWORDS, os_sendfile__doc__}, |
8211 | | |
8212 | | static PyObject * |
8213 | | os_sendfile_impl(PyObject *module, int out_fd, int in_fd, PyObject *offobj, |
8214 | | Py_ssize_t count); |
8215 | | |
8216 | | static PyObject * |
8217 | | os_sendfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
8218 | 0 | { |
8219 | 0 | PyObject *return_value = NULL; |
8220 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
8221 | |
|
8222 | 0 | #define NUM_KEYWORDS 4 |
8223 | 0 | static struct { |
8224 | 0 | PyGC_Head _this_is_not_used; |
8225 | 0 | PyObject_VAR_HEAD |
8226 | 0 | Py_hash_t ob_hash; |
8227 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
8228 | 0 | } _kwtuple = { |
8229 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
8230 | 0 | .ob_hash = -1, |
8231 | 0 | .ob_item = { &_Py_ID(out_fd), &_Py_ID(in_fd), &_Py_ID(offset), &_Py_ID(count), }, |
8232 | 0 | }; |
8233 | 0 | #undef NUM_KEYWORDS |
8234 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
8235 | |
|
8236 | | #else // !Py_BUILD_CORE |
8237 | | # define KWTUPLE NULL |
8238 | | #endif // !Py_BUILD_CORE |
8239 | |
|
8240 | 0 | static const char * const _keywords[] = {"out_fd", "in_fd", "offset", "count", NULL}; |
8241 | 0 | static _PyArg_Parser _parser = { |
8242 | 0 | .keywords = _keywords, |
8243 | 0 | .fname = "sendfile", |
8244 | 0 | .kwtuple = KWTUPLE, |
8245 | 0 | }; |
8246 | 0 | #undef KWTUPLE |
8247 | 0 | PyObject *argsbuf[4]; |
8248 | 0 | int out_fd; |
8249 | 0 | int in_fd; |
8250 | 0 | PyObject *offobj; |
8251 | 0 | Py_ssize_t count; |
8252 | |
|
8253 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
8254 | 0 | /*minpos*/ 4, /*maxpos*/ 4, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
8255 | 0 | if (!args) { |
8256 | 0 | goto exit; |
8257 | 0 | } |
8258 | 0 | out_fd = PyLong_AsInt(args[0]); |
8259 | 0 | if (out_fd == -1 && PyErr_Occurred()) { |
8260 | 0 | goto exit; |
8261 | 0 | } |
8262 | 0 | in_fd = PyLong_AsInt(args[1]); |
8263 | 0 | if (in_fd == -1 && PyErr_Occurred()) { |
8264 | 0 | goto exit; |
8265 | 0 | } |
8266 | 0 | offobj = args[2]; |
8267 | 0 | { |
8268 | 0 | Py_ssize_t ival = -1; |
8269 | 0 | PyObject *iobj = _PyNumber_Index(args[3]); |
8270 | 0 | if (iobj != NULL) { |
8271 | 0 | ival = PyLong_AsSsize_t(iobj); |
8272 | 0 | Py_DECREF(iobj); |
8273 | 0 | } |
8274 | 0 | if (ival == -1 && PyErr_Occurred()) { |
8275 | 0 | goto exit; |
8276 | 0 | } |
8277 | 0 | count = ival; |
8278 | 0 | } |
8279 | 0 | return_value = os_sendfile_impl(module, out_fd, in_fd, offobj, count); |
8280 | |
|
8281 | 0 | exit: |
8282 | 0 | return return_value; |
8283 | 0 | } |
8284 | | |
8285 | | #endif /* defined(HAVE_SENDFILE) && !defined(__APPLE__) && !(defined(__FreeBSD__) || defined(__DragonFly__)) */ |
8286 | | |
8287 | | #if defined(__APPLE__) |
8288 | | |
8289 | | PyDoc_STRVAR(os__fcopyfile__doc__, |
8290 | | "_fcopyfile($module, in_fd, out_fd, flags, /)\n" |
8291 | | "--\n" |
8292 | | "\n" |
8293 | | "Efficiently copy content or metadata of 2 regular file descriptors (macOS)."); |
8294 | | |
8295 | | #define OS__FCOPYFILE_METHODDEF \ |
8296 | | {"_fcopyfile", _PyCFunction_CAST(os__fcopyfile), METH_FASTCALL, os__fcopyfile__doc__}, |
8297 | | |
8298 | | static PyObject * |
8299 | | os__fcopyfile_impl(PyObject *module, int in_fd, int out_fd, int flags); |
8300 | | |
8301 | | static PyObject * |
8302 | | os__fcopyfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
8303 | | { |
8304 | | PyObject *return_value = NULL; |
8305 | | int in_fd; |
8306 | | int out_fd; |
8307 | | int flags; |
8308 | | |
8309 | | if (!_PyArg_CheckPositional("_fcopyfile", nargs, 3, 3)) { |
8310 | | goto exit; |
8311 | | } |
8312 | | in_fd = PyLong_AsInt(args[0]); |
8313 | | if (in_fd == -1 && PyErr_Occurred()) { |
8314 | | goto exit; |
8315 | | } |
8316 | | out_fd = PyLong_AsInt(args[1]); |
8317 | | if (out_fd == -1 && PyErr_Occurred()) { |
8318 | | goto exit; |
8319 | | } |
8320 | | flags = PyLong_AsInt(args[2]); |
8321 | | if (flags == -1 && PyErr_Occurred()) { |
8322 | | goto exit; |
8323 | | } |
8324 | | return_value = os__fcopyfile_impl(module, in_fd, out_fd, flags); |
8325 | | |
8326 | | exit: |
8327 | | return return_value; |
8328 | | } |
8329 | | |
8330 | | #endif /* defined(__APPLE__) */ |
8331 | | |
8332 | | PyDoc_STRVAR(os_fstat__doc__, |
8333 | | "fstat($module, /, fd)\n" |
8334 | | "--\n" |
8335 | | "\n" |
8336 | | "Perform a stat system call on the given file descriptor.\n" |
8337 | | "\n" |
8338 | | "Like stat(), but for an open file descriptor.\n" |
8339 | | "Equivalent to os.stat(fd)."); |
8340 | | |
8341 | | #define OS_FSTAT_METHODDEF \ |
8342 | | {"fstat", _PyCFunction_CAST(os_fstat), METH_FASTCALL|METH_KEYWORDS, os_fstat__doc__}, |
8343 | | |
8344 | | static PyObject * |
8345 | | os_fstat_impl(PyObject *module, int fd); |
8346 | | |
8347 | | static PyObject * |
8348 | | os_fstat(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
8349 | 0 | { |
8350 | 0 | PyObject *return_value = NULL; |
8351 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
8352 | |
|
8353 | 0 | #define NUM_KEYWORDS 1 |
8354 | 0 | static struct { |
8355 | 0 | PyGC_Head _this_is_not_used; |
8356 | 0 | PyObject_VAR_HEAD |
8357 | 0 | Py_hash_t ob_hash; |
8358 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
8359 | 0 | } _kwtuple = { |
8360 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
8361 | 0 | .ob_hash = -1, |
8362 | 0 | .ob_item = { &_Py_ID(fd), }, |
8363 | 0 | }; |
8364 | 0 | #undef NUM_KEYWORDS |
8365 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
8366 | |
|
8367 | | #else // !Py_BUILD_CORE |
8368 | | # define KWTUPLE NULL |
8369 | | #endif // !Py_BUILD_CORE |
8370 | |
|
8371 | 0 | static const char * const _keywords[] = {"fd", NULL}; |
8372 | 0 | static _PyArg_Parser _parser = { |
8373 | 0 | .keywords = _keywords, |
8374 | 0 | .fname = "fstat", |
8375 | 0 | .kwtuple = KWTUPLE, |
8376 | 0 | }; |
8377 | 0 | #undef KWTUPLE |
8378 | 0 | PyObject *argsbuf[1]; |
8379 | 0 | int fd; |
8380 | |
|
8381 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
8382 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
8383 | 0 | if (!args) { |
8384 | 0 | goto exit; |
8385 | 0 | } |
8386 | 0 | fd = PyLong_AsInt(args[0]); |
8387 | 0 | if (fd == -1 && PyErr_Occurred()) { |
8388 | 0 | goto exit; |
8389 | 0 | } |
8390 | 0 | return_value = os_fstat_impl(module, fd); |
8391 | |
|
8392 | 0 | exit: |
8393 | 0 | return return_value; |
8394 | 0 | } |
8395 | | |
8396 | | PyDoc_STRVAR(os_isatty__doc__, |
8397 | | "isatty($module, fd, /)\n" |
8398 | | "--\n" |
8399 | | "\n" |
8400 | | "Return True if the fd is connected to a terminal.\n" |
8401 | | "\n" |
8402 | | "Return True if the file descriptor is an open file descriptor\n" |
8403 | | "connected to the slave end of a terminal."); |
8404 | | |
8405 | | #define OS_ISATTY_METHODDEF \ |
8406 | | {"isatty", (PyCFunction)os_isatty, METH_O, os_isatty__doc__}, |
8407 | | |
8408 | | static int |
8409 | | os_isatty_impl(PyObject *module, int fd); |
8410 | | |
8411 | | static PyObject * |
8412 | | os_isatty(PyObject *module, PyObject *arg) |
8413 | 0 | { |
8414 | 0 | PyObject *return_value = NULL; |
8415 | 0 | int fd; |
8416 | 0 | int _return_value; |
8417 | |
|
8418 | 0 | fd = PyLong_AsInt(arg); |
8419 | 0 | if (fd == -1 && PyErr_Occurred()) { |
8420 | 0 | goto exit; |
8421 | 0 | } |
8422 | 0 | _return_value = os_isatty_impl(module, fd); |
8423 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
8424 | 0 | goto exit; |
8425 | 0 | } |
8426 | 0 | return_value = PyBool_FromLong((long)_return_value); |
8427 | |
|
8428 | 0 | exit: |
8429 | 0 | return return_value; |
8430 | 0 | } |
8431 | | |
8432 | | #if defined(HAVE_PIPE) |
8433 | | |
8434 | | PyDoc_STRVAR(os_pipe__doc__, |
8435 | | "pipe($module, /)\n" |
8436 | | "--\n" |
8437 | | "\n" |
8438 | | "Create a pipe.\n" |
8439 | | "\n" |
8440 | | "Returns a tuple of two file descriptors:\n" |
8441 | | " (read_fd, write_fd)"); |
8442 | | |
8443 | | #define OS_PIPE_METHODDEF \ |
8444 | | {"pipe", (PyCFunction)os_pipe, METH_NOARGS, os_pipe__doc__}, |
8445 | | |
8446 | | static PyObject * |
8447 | | os_pipe_impl(PyObject *module); |
8448 | | |
8449 | | static PyObject * |
8450 | | os_pipe(PyObject *module, PyObject *Py_UNUSED(ignored)) |
8451 | 0 | { |
8452 | 0 | return os_pipe_impl(module); |
8453 | 0 | } |
8454 | | |
8455 | | #endif /* defined(HAVE_PIPE) */ |
8456 | | |
8457 | | #if defined(HAVE_PIPE2) |
8458 | | |
8459 | | PyDoc_STRVAR(os_pipe2__doc__, |
8460 | | "pipe2($module, flags, /)\n" |
8461 | | "--\n" |
8462 | | "\n" |
8463 | | "Create a pipe with flags set atomically.\n" |
8464 | | "\n" |
8465 | | "Returns a tuple of two file descriptors:\n" |
8466 | | " (read_fd, write_fd)\n" |
8467 | | "\n" |
8468 | | "flags can be constructed by ORing together one or more of these values:\n" |
8469 | | "O_NONBLOCK, O_CLOEXEC."); |
8470 | | |
8471 | | #define OS_PIPE2_METHODDEF \ |
8472 | | {"pipe2", (PyCFunction)os_pipe2, METH_O, os_pipe2__doc__}, |
8473 | | |
8474 | | static PyObject * |
8475 | | os_pipe2_impl(PyObject *module, int flags); |
8476 | | |
8477 | | static PyObject * |
8478 | | os_pipe2(PyObject *module, PyObject *arg) |
8479 | 0 | { |
8480 | 0 | PyObject *return_value = NULL; |
8481 | 0 | int flags; |
8482 | |
|
8483 | 0 | flags = PyLong_AsInt(arg); |
8484 | 0 | if (flags == -1 && PyErr_Occurred()) { |
8485 | 0 | goto exit; |
8486 | 0 | } |
8487 | 0 | return_value = os_pipe2_impl(module, flags); |
8488 | |
|
8489 | 0 | exit: |
8490 | 0 | return return_value; |
8491 | 0 | } |
8492 | | |
8493 | | #endif /* defined(HAVE_PIPE2) */ |
8494 | | |
8495 | | #if defined(HAVE_WRITEV) |
8496 | | |
8497 | | PyDoc_STRVAR(os_writev__doc__, |
8498 | | "writev($module, fd, buffers, /)\n" |
8499 | | "--\n" |
8500 | | "\n" |
8501 | | "Iterate over buffers, and write the contents of each to a file descriptor.\n" |
8502 | | "\n" |
8503 | | "Returns the total number of bytes written.\n" |
8504 | | "buffers must be a sequence of bytes-like objects."); |
8505 | | |
8506 | | #define OS_WRITEV_METHODDEF \ |
8507 | | {"writev", _PyCFunction_CAST(os_writev), METH_FASTCALL, os_writev__doc__}, |
8508 | | |
8509 | | static Py_ssize_t |
8510 | | os_writev_impl(PyObject *module, int fd, PyObject *buffers); |
8511 | | |
8512 | | static PyObject * |
8513 | | os_writev(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
8514 | 0 | { |
8515 | 0 | PyObject *return_value = NULL; |
8516 | 0 | int fd; |
8517 | 0 | PyObject *buffers; |
8518 | 0 | Py_ssize_t _return_value; |
8519 | |
|
8520 | 0 | if (!_PyArg_CheckPositional("writev", nargs, 2, 2)) { |
8521 | 0 | goto exit; |
8522 | 0 | } |
8523 | 0 | fd = PyLong_AsInt(args[0]); |
8524 | 0 | if (fd == -1 && PyErr_Occurred()) { |
8525 | 0 | goto exit; |
8526 | 0 | } |
8527 | 0 | buffers = args[1]; |
8528 | 0 | _return_value = os_writev_impl(module, fd, buffers); |
8529 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
8530 | 0 | goto exit; |
8531 | 0 | } |
8532 | 0 | return_value = PyLong_FromSsize_t(_return_value); |
8533 | |
|
8534 | 0 | exit: |
8535 | 0 | return return_value; |
8536 | 0 | } |
8537 | | |
8538 | | #endif /* defined(HAVE_WRITEV) */ |
8539 | | |
8540 | | #if defined(HAVE_PWRITE) |
8541 | | |
8542 | | PyDoc_STRVAR(os_pwrite__doc__, |
8543 | | "pwrite($module, fd, buffer, offset, /)\n" |
8544 | | "--\n" |
8545 | | "\n" |
8546 | | "Write bytes to a file descriptor starting at a particular offset.\n" |
8547 | | "\n" |
8548 | | "Write buffer to fd, starting at offset bytes from the beginning of\n" |
8549 | | "the file. Returns the number of bytes written. Does not change the\n" |
8550 | | "current file offset."); |
8551 | | |
8552 | | #define OS_PWRITE_METHODDEF \ |
8553 | | {"pwrite", _PyCFunction_CAST(os_pwrite), METH_FASTCALL, os_pwrite__doc__}, |
8554 | | |
8555 | | static Py_ssize_t |
8556 | | os_pwrite_impl(PyObject *module, int fd, Py_buffer *buffer, Py_off_t offset); |
8557 | | |
8558 | | static PyObject * |
8559 | | os_pwrite(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
8560 | 0 | { |
8561 | 0 | PyObject *return_value = NULL; |
8562 | 0 | int fd; |
8563 | 0 | Py_buffer buffer = {NULL, NULL}; |
8564 | 0 | Py_off_t offset; |
8565 | 0 | Py_ssize_t _return_value; |
8566 | |
|
8567 | 0 | if (!_PyArg_CheckPositional("pwrite", nargs, 3, 3)) { |
8568 | 0 | goto exit; |
8569 | 0 | } |
8570 | 0 | fd = PyLong_AsInt(args[0]); |
8571 | 0 | if (fd == -1 && PyErr_Occurred()) { |
8572 | 0 | goto exit; |
8573 | 0 | } |
8574 | 0 | if (PyObject_GetBuffer(args[1], &buffer, PyBUF_SIMPLE) != 0) { |
8575 | 0 | goto exit; |
8576 | 0 | } |
8577 | 0 | if (!Py_off_t_converter(args[2], &offset)) { |
8578 | 0 | goto exit; |
8579 | 0 | } |
8580 | 0 | _return_value = os_pwrite_impl(module, fd, &buffer, offset); |
8581 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
8582 | 0 | goto exit; |
8583 | 0 | } |
8584 | 0 | return_value = PyLong_FromSsize_t(_return_value); |
8585 | |
|
8586 | 0 | exit: |
8587 | | /* Cleanup for buffer */ |
8588 | 0 | if (buffer.obj) { |
8589 | 0 | PyBuffer_Release(&buffer); |
8590 | 0 | } |
8591 | |
|
8592 | 0 | return return_value; |
8593 | 0 | } |
8594 | | |
8595 | | #endif /* defined(HAVE_PWRITE) */ |
8596 | | |
8597 | | #if (defined(HAVE_PWRITEV) || defined (HAVE_PWRITEV2)) |
8598 | | |
8599 | | PyDoc_STRVAR(os_pwritev__doc__, |
8600 | | "pwritev($module, fd, buffers, offset, flags=0, /)\n" |
8601 | | "--\n" |
8602 | | "\n" |
8603 | | "Writes the contents of bytes-like objects to a file descriptor at a given offset.\n" |
8604 | | "\n" |
8605 | | "Combines the functionality of writev() and pwrite(). All buffers must be a sequence\n" |
8606 | | "of bytes-like objects. Buffers are processed in array order. Entire contents of first\n" |
8607 | | "buffer is written before proceeding to second, and so on. The operating system may\n" |
8608 | | "set a limit (sysconf() value SC_IOV_MAX) on the number of buffers that can be used.\n" |
8609 | | "This function writes the contents of each object to the file descriptor and returns\n" |
8610 | | "the total number of bytes written.\n" |
8611 | | "\n" |
8612 | | "The flags argument contains a bitwise OR of zero or more of the following flags:\n" |
8613 | | "\n" |
8614 | | "- RWF_DSYNC\n" |
8615 | | "- RWF_SYNC\n" |
8616 | | "- RWF_APPEND\n" |
8617 | | "\n" |
8618 | | "Using non-zero flags requires Linux 4.7 or newer."); |
8619 | | |
8620 | | #define OS_PWRITEV_METHODDEF \ |
8621 | | {"pwritev", _PyCFunction_CAST(os_pwritev), METH_FASTCALL, os_pwritev__doc__}, |
8622 | | |
8623 | | static Py_ssize_t |
8624 | | os_pwritev_impl(PyObject *module, int fd, PyObject *buffers, Py_off_t offset, |
8625 | | int flags); |
8626 | | |
8627 | | static PyObject * |
8628 | | os_pwritev(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
8629 | 0 | { |
8630 | 0 | PyObject *return_value = NULL; |
8631 | 0 | int fd; |
8632 | 0 | PyObject *buffers; |
8633 | 0 | Py_off_t offset; |
8634 | 0 | int flags = 0; |
8635 | 0 | Py_ssize_t _return_value; |
8636 | |
|
8637 | 0 | if (!_PyArg_CheckPositional("pwritev", nargs, 3, 4)) { |
8638 | 0 | goto exit; |
8639 | 0 | } |
8640 | 0 | fd = PyLong_AsInt(args[0]); |
8641 | 0 | if (fd == -1 && PyErr_Occurred()) { |
8642 | 0 | goto exit; |
8643 | 0 | } |
8644 | 0 | buffers = args[1]; |
8645 | 0 | if (!Py_off_t_converter(args[2], &offset)) { |
8646 | 0 | goto exit; |
8647 | 0 | } |
8648 | 0 | if (nargs < 4) { |
8649 | 0 | goto skip_optional; |
8650 | 0 | } |
8651 | 0 | flags = PyLong_AsInt(args[3]); |
8652 | 0 | if (flags == -1 && PyErr_Occurred()) { |
8653 | 0 | goto exit; |
8654 | 0 | } |
8655 | 0 | skip_optional: |
8656 | 0 | _return_value = os_pwritev_impl(module, fd, buffers, offset, flags); |
8657 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
8658 | 0 | goto exit; |
8659 | 0 | } |
8660 | 0 | return_value = PyLong_FromSsize_t(_return_value); |
8661 | |
|
8662 | 0 | exit: |
8663 | 0 | return return_value; |
8664 | 0 | } |
8665 | | |
8666 | | #endif /* (defined(HAVE_PWRITEV) || defined (HAVE_PWRITEV2)) */ |
8667 | | |
8668 | | #if defined(HAVE_COPY_FILE_RANGE) |
8669 | | |
8670 | | PyDoc_STRVAR(os_copy_file_range__doc__, |
8671 | | "copy_file_range($module, /, src, dst, count, offset_src=None,\n" |
8672 | | " offset_dst=None)\n" |
8673 | | "--\n" |
8674 | | "\n" |
8675 | | "Copy count bytes from one file descriptor to another.\n" |
8676 | | "\n" |
8677 | | " src\n" |
8678 | | " Source file descriptor.\n" |
8679 | | " dst\n" |
8680 | | " Destination file descriptor.\n" |
8681 | | " count\n" |
8682 | | " Number of bytes to copy.\n" |
8683 | | " offset_src\n" |
8684 | | " Starting offset in src.\n" |
8685 | | " offset_dst\n" |
8686 | | " Starting offset in dst.\n" |
8687 | | "\n" |
8688 | | "If offset_src is None, then src is read from the current position;\n" |
8689 | | "respectively for offset_dst."); |
8690 | | |
8691 | | #define OS_COPY_FILE_RANGE_METHODDEF \ |
8692 | | {"copy_file_range", _PyCFunction_CAST(os_copy_file_range), METH_FASTCALL|METH_KEYWORDS, os_copy_file_range__doc__}, |
8693 | | |
8694 | | static PyObject * |
8695 | | os_copy_file_range_impl(PyObject *module, int src, int dst, Py_ssize_t count, |
8696 | | PyObject *offset_src, PyObject *offset_dst); |
8697 | | |
8698 | | static PyObject * |
8699 | | os_copy_file_range(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
8700 | 0 | { |
8701 | 0 | PyObject *return_value = NULL; |
8702 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
8703 | |
|
8704 | 0 | #define NUM_KEYWORDS 5 |
8705 | 0 | static struct { |
8706 | 0 | PyGC_Head _this_is_not_used; |
8707 | 0 | PyObject_VAR_HEAD |
8708 | 0 | Py_hash_t ob_hash; |
8709 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
8710 | 0 | } _kwtuple = { |
8711 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
8712 | 0 | .ob_hash = -1, |
8713 | 0 | .ob_item = { &_Py_ID(src), &_Py_ID(dst), &_Py_ID(count), &_Py_ID(offset_src), &_Py_ID(offset_dst), }, |
8714 | 0 | }; |
8715 | 0 | #undef NUM_KEYWORDS |
8716 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
8717 | |
|
8718 | | #else // !Py_BUILD_CORE |
8719 | | # define KWTUPLE NULL |
8720 | | #endif // !Py_BUILD_CORE |
8721 | |
|
8722 | 0 | static const char * const _keywords[] = {"src", "dst", "count", "offset_src", "offset_dst", NULL}; |
8723 | 0 | static _PyArg_Parser _parser = { |
8724 | 0 | .keywords = _keywords, |
8725 | 0 | .fname = "copy_file_range", |
8726 | 0 | .kwtuple = KWTUPLE, |
8727 | 0 | }; |
8728 | 0 | #undef KWTUPLE |
8729 | 0 | PyObject *argsbuf[5]; |
8730 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3; |
8731 | 0 | int src; |
8732 | 0 | int dst; |
8733 | 0 | Py_ssize_t count; |
8734 | 0 | PyObject *offset_src = Py_None; |
8735 | 0 | PyObject *offset_dst = Py_None; |
8736 | |
|
8737 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
8738 | 0 | /*minpos*/ 3, /*maxpos*/ 5, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
8739 | 0 | if (!args) { |
8740 | 0 | goto exit; |
8741 | 0 | } |
8742 | 0 | src = PyLong_AsInt(args[0]); |
8743 | 0 | if (src == -1 && PyErr_Occurred()) { |
8744 | 0 | goto exit; |
8745 | 0 | } |
8746 | 0 | dst = PyLong_AsInt(args[1]); |
8747 | 0 | if (dst == -1 && PyErr_Occurred()) { |
8748 | 0 | goto exit; |
8749 | 0 | } |
8750 | 0 | { |
8751 | 0 | Py_ssize_t ival = -1; |
8752 | 0 | PyObject *iobj = _PyNumber_Index(args[2]); |
8753 | 0 | if (iobj != NULL) { |
8754 | 0 | ival = PyLong_AsSsize_t(iobj); |
8755 | 0 | Py_DECREF(iobj); |
8756 | 0 | } |
8757 | 0 | if (ival == -1 && PyErr_Occurred()) { |
8758 | 0 | goto exit; |
8759 | 0 | } |
8760 | 0 | count = ival; |
8761 | 0 | } |
8762 | 0 | if (!noptargs) { |
8763 | 0 | goto skip_optional_pos; |
8764 | 0 | } |
8765 | 0 | if (args[3]) { |
8766 | 0 | offset_src = args[3]; |
8767 | 0 | if (!--noptargs) { |
8768 | 0 | goto skip_optional_pos; |
8769 | 0 | } |
8770 | 0 | } |
8771 | 0 | offset_dst = args[4]; |
8772 | 0 | skip_optional_pos: |
8773 | 0 | return_value = os_copy_file_range_impl(module, src, dst, count, offset_src, offset_dst); |
8774 | |
|
8775 | 0 | exit: |
8776 | 0 | return return_value; |
8777 | 0 | } |
8778 | | |
8779 | | #endif /* defined(HAVE_COPY_FILE_RANGE) */ |
8780 | | |
8781 | | #if ((defined(HAVE_SPLICE) && !defined(_AIX))) |
8782 | | |
8783 | | PyDoc_STRVAR(os_splice__doc__, |
8784 | | "splice($module, /, src, dst, count, offset_src=None, offset_dst=None,\n" |
8785 | | " flags=0)\n" |
8786 | | "--\n" |
8787 | | "\n" |
8788 | | "Transfer count bytes from one pipe to a descriptor or vice versa.\n" |
8789 | | "\n" |
8790 | | " src\n" |
8791 | | " Source file descriptor.\n" |
8792 | | " dst\n" |
8793 | | " Destination file descriptor.\n" |
8794 | | " count\n" |
8795 | | " Number of bytes to copy.\n" |
8796 | | " offset_src\n" |
8797 | | " Starting offset in src.\n" |
8798 | | " offset_dst\n" |
8799 | | " Starting offset in dst.\n" |
8800 | | " flags\n" |
8801 | | " Flags to modify the semantics of the call.\n" |
8802 | | "\n" |
8803 | | "If offset_src is None, then src is read from the current position;\n" |
8804 | | "respectively for offset_dst. The offset associated to the file\n" |
8805 | | "descriptor that refers to a pipe must be None."); |
8806 | | |
8807 | | #define OS_SPLICE_METHODDEF \ |
8808 | | {"splice", _PyCFunction_CAST(os_splice), METH_FASTCALL|METH_KEYWORDS, os_splice__doc__}, |
8809 | | |
8810 | | static PyObject * |
8811 | | os_splice_impl(PyObject *module, int src, int dst, Py_ssize_t count, |
8812 | | PyObject *offset_src, PyObject *offset_dst, |
8813 | | unsigned int flags); |
8814 | | |
8815 | | static PyObject * |
8816 | | os_splice(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
8817 | 0 | { |
8818 | 0 | PyObject *return_value = NULL; |
8819 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
8820 | |
|
8821 | 0 | #define NUM_KEYWORDS 6 |
8822 | 0 | static struct { |
8823 | 0 | PyGC_Head _this_is_not_used; |
8824 | 0 | PyObject_VAR_HEAD |
8825 | 0 | Py_hash_t ob_hash; |
8826 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
8827 | 0 | } _kwtuple = { |
8828 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
8829 | 0 | .ob_hash = -1, |
8830 | 0 | .ob_item = { &_Py_ID(src), &_Py_ID(dst), &_Py_ID(count), &_Py_ID(offset_src), &_Py_ID(offset_dst), &_Py_ID(flags), }, |
8831 | 0 | }; |
8832 | 0 | #undef NUM_KEYWORDS |
8833 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
8834 | |
|
8835 | | #else // !Py_BUILD_CORE |
8836 | | # define KWTUPLE NULL |
8837 | | #endif // !Py_BUILD_CORE |
8838 | |
|
8839 | 0 | static const char * const _keywords[] = {"src", "dst", "count", "offset_src", "offset_dst", "flags", NULL}; |
8840 | 0 | static _PyArg_Parser _parser = { |
8841 | 0 | .keywords = _keywords, |
8842 | 0 | .fname = "splice", |
8843 | 0 | .kwtuple = KWTUPLE, |
8844 | 0 | }; |
8845 | 0 | #undef KWTUPLE |
8846 | 0 | PyObject *argsbuf[6]; |
8847 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3; |
8848 | 0 | int src; |
8849 | 0 | int dst; |
8850 | 0 | Py_ssize_t count; |
8851 | 0 | PyObject *offset_src = Py_None; |
8852 | 0 | PyObject *offset_dst = Py_None; |
8853 | 0 | unsigned int flags = 0; |
8854 | |
|
8855 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
8856 | 0 | /*minpos*/ 3, /*maxpos*/ 6, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
8857 | 0 | if (!args) { |
8858 | 0 | goto exit; |
8859 | 0 | } |
8860 | 0 | src = PyLong_AsInt(args[0]); |
8861 | 0 | if (src == -1 && PyErr_Occurred()) { |
8862 | 0 | goto exit; |
8863 | 0 | } |
8864 | 0 | dst = PyLong_AsInt(args[1]); |
8865 | 0 | if (dst == -1 && PyErr_Occurred()) { |
8866 | 0 | goto exit; |
8867 | 0 | } |
8868 | 0 | { |
8869 | 0 | Py_ssize_t ival = -1; |
8870 | 0 | PyObject *iobj = _PyNumber_Index(args[2]); |
8871 | 0 | if (iobj != NULL) { |
8872 | 0 | ival = PyLong_AsSsize_t(iobj); |
8873 | 0 | Py_DECREF(iobj); |
8874 | 0 | } |
8875 | 0 | if (ival == -1 && PyErr_Occurred()) { |
8876 | 0 | goto exit; |
8877 | 0 | } |
8878 | 0 | count = ival; |
8879 | 0 | } |
8880 | 0 | if (!noptargs) { |
8881 | 0 | goto skip_optional_pos; |
8882 | 0 | } |
8883 | 0 | if (args[3]) { |
8884 | 0 | offset_src = args[3]; |
8885 | 0 | if (!--noptargs) { |
8886 | 0 | goto skip_optional_pos; |
8887 | 0 | } |
8888 | 0 | } |
8889 | 0 | if (args[4]) { |
8890 | 0 | offset_dst = args[4]; |
8891 | 0 | if (!--noptargs) { |
8892 | 0 | goto skip_optional_pos; |
8893 | 0 | } |
8894 | 0 | } |
8895 | 0 | if (!_PyLong_UnsignedInt_Converter(args[5], &flags)) { |
8896 | 0 | goto exit; |
8897 | 0 | } |
8898 | 0 | skip_optional_pos: |
8899 | 0 | return_value = os_splice_impl(module, src, dst, count, offset_src, offset_dst, flags); |
8900 | |
|
8901 | 0 | exit: |
8902 | 0 | return return_value; |
8903 | 0 | } |
8904 | | |
8905 | | #endif /* ((defined(HAVE_SPLICE) && !defined(_AIX))) */ |
8906 | | |
8907 | | #if defined(HAVE_MKFIFO) |
8908 | | |
8909 | | PyDoc_STRVAR(os_mkfifo__doc__, |
8910 | | "mkfifo($module, /, path, mode=438, *, dir_fd=None)\n" |
8911 | | "--\n" |
8912 | | "\n" |
8913 | | "Create a \"fifo\" (a POSIX named pipe).\n" |
8914 | | "\n" |
8915 | | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
8916 | | " and path should be relative; path will then be relative to that directory.\n" |
8917 | | "dir_fd may not be implemented on your platform.\n" |
8918 | | " If it is unavailable, using it will raise a NotImplementedError."); |
8919 | | |
8920 | | #define OS_MKFIFO_METHODDEF \ |
8921 | | {"mkfifo", _PyCFunction_CAST(os_mkfifo), METH_FASTCALL|METH_KEYWORDS, os_mkfifo__doc__}, |
8922 | | |
8923 | | static PyObject * |
8924 | | os_mkfifo_impl(PyObject *module, path_t *path, int mode, int dir_fd); |
8925 | | |
8926 | | static PyObject * |
8927 | | os_mkfifo(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
8928 | 0 | { |
8929 | 0 | PyObject *return_value = NULL; |
8930 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
8931 | |
|
8932 | 0 | #define NUM_KEYWORDS 3 |
8933 | 0 | static struct { |
8934 | 0 | PyGC_Head _this_is_not_used; |
8935 | 0 | PyObject_VAR_HEAD |
8936 | 0 | Py_hash_t ob_hash; |
8937 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
8938 | 0 | } _kwtuple = { |
8939 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
8940 | 0 | .ob_hash = -1, |
8941 | 0 | .ob_item = { &_Py_ID(path), &_Py_ID(mode), &_Py_ID(dir_fd), }, |
8942 | 0 | }; |
8943 | 0 | #undef NUM_KEYWORDS |
8944 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
8945 | |
|
8946 | | #else // !Py_BUILD_CORE |
8947 | | # define KWTUPLE NULL |
8948 | | #endif // !Py_BUILD_CORE |
8949 | |
|
8950 | 0 | static const char * const _keywords[] = {"path", "mode", "dir_fd", NULL}; |
8951 | 0 | static _PyArg_Parser _parser = { |
8952 | 0 | .keywords = _keywords, |
8953 | 0 | .fname = "mkfifo", |
8954 | 0 | .kwtuple = KWTUPLE, |
8955 | 0 | }; |
8956 | 0 | #undef KWTUPLE |
8957 | 0 | PyObject *argsbuf[3]; |
8958 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
8959 | 0 | path_t path = PATH_T_INITIALIZE_P("mkfifo", "path", 0, 0, 0, 0); |
8960 | 0 | int mode = 438; |
8961 | 0 | int dir_fd = DEFAULT_DIR_FD; |
8962 | |
|
8963 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
8964 | 0 | /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
8965 | 0 | if (!args) { |
8966 | 0 | goto exit; |
8967 | 0 | } |
8968 | 0 | if (!path_converter(args[0], &path)) { |
8969 | 0 | goto exit; |
8970 | 0 | } |
8971 | 0 | if (!noptargs) { |
8972 | 0 | goto skip_optional_pos; |
8973 | 0 | } |
8974 | 0 | if (args[1]) { |
8975 | 0 | mode = PyLong_AsInt(args[1]); |
8976 | 0 | if (mode == -1 && PyErr_Occurred()) { |
8977 | 0 | goto exit; |
8978 | 0 | } |
8979 | 0 | if (!--noptargs) { |
8980 | 0 | goto skip_optional_pos; |
8981 | 0 | } |
8982 | 0 | } |
8983 | 0 | skip_optional_pos: |
8984 | 0 | if (!noptargs) { |
8985 | 0 | goto skip_optional_kwonly; |
8986 | 0 | } |
8987 | 0 | if (!MKFIFOAT_DIR_FD_CONVERTER(args[2], &dir_fd)) { |
8988 | 0 | goto exit; |
8989 | 0 | } |
8990 | 0 | skip_optional_kwonly: |
8991 | 0 | return_value = os_mkfifo_impl(module, &path, mode, dir_fd); |
8992 | |
|
8993 | 0 | exit: |
8994 | | /* Cleanup for path */ |
8995 | 0 | path_cleanup(&path); |
8996 | |
|
8997 | 0 | return return_value; |
8998 | 0 | } |
8999 | | |
9000 | | #endif /* defined(HAVE_MKFIFO) */ |
9001 | | |
9002 | | #if (defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV)) |
9003 | | |
9004 | | PyDoc_STRVAR(os_mknod__doc__, |
9005 | | "mknod($module, /, path, mode=384, device=0, *, dir_fd=None)\n" |
9006 | | "--\n" |
9007 | | "\n" |
9008 | | "Create a node in the file system.\n" |
9009 | | "\n" |
9010 | | "Create a node in the file system (file, device special file or named pipe)\n" |
9011 | | "at path. mode specifies both the permissions to use and the\n" |
9012 | | "type of node to be created, being combined (bitwise OR) with one of\n" |
9013 | | "S_IFREG, S_IFCHR, S_IFBLK, and S_IFIFO. If S_IFCHR or S_IFBLK is set on mode,\n" |
9014 | | "device defines the newly created device special file (probably using\n" |
9015 | | "os.makedev()). Otherwise device is ignored.\n" |
9016 | | "\n" |
9017 | | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
9018 | | " and path should be relative; path will then be relative to that directory.\n" |
9019 | | "dir_fd may not be implemented on your platform.\n" |
9020 | | " If it is unavailable, using it will raise a NotImplementedError."); |
9021 | | |
9022 | | #define OS_MKNOD_METHODDEF \ |
9023 | | {"mknod", _PyCFunction_CAST(os_mknod), METH_FASTCALL|METH_KEYWORDS, os_mknod__doc__}, |
9024 | | |
9025 | | static PyObject * |
9026 | | os_mknod_impl(PyObject *module, path_t *path, int mode, dev_t device, |
9027 | | int dir_fd); |
9028 | | |
9029 | | static PyObject * |
9030 | | os_mknod(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
9031 | 0 | { |
9032 | 0 | PyObject *return_value = NULL; |
9033 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
9034 | |
|
9035 | 0 | #define NUM_KEYWORDS 4 |
9036 | 0 | static struct { |
9037 | 0 | PyGC_Head _this_is_not_used; |
9038 | 0 | PyObject_VAR_HEAD |
9039 | 0 | Py_hash_t ob_hash; |
9040 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
9041 | 0 | } _kwtuple = { |
9042 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
9043 | 0 | .ob_hash = -1, |
9044 | 0 | .ob_item = { &_Py_ID(path), &_Py_ID(mode), &_Py_ID(device), &_Py_ID(dir_fd), }, |
9045 | 0 | }; |
9046 | 0 | #undef NUM_KEYWORDS |
9047 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
9048 | |
|
9049 | | #else // !Py_BUILD_CORE |
9050 | | # define KWTUPLE NULL |
9051 | | #endif // !Py_BUILD_CORE |
9052 | |
|
9053 | 0 | static const char * const _keywords[] = {"path", "mode", "device", "dir_fd", NULL}; |
9054 | 0 | static _PyArg_Parser _parser = { |
9055 | 0 | .keywords = _keywords, |
9056 | 0 | .fname = "mknod", |
9057 | 0 | .kwtuple = KWTUPLE, |
9058 | 0 | }; |
9059 | 0 | #undef KWTUPLE |
9060 | 0 | PyObject *argsbuf[4]; |
9061 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
9062 | 0 | path_t path = PATH_T_INITIALIZE_P("mknod", "path", 0, 0, 0, 0); |
9063 | 0 | int mode = 384; |
9064 | 0 | dev_t device = 0; |
9065 | 0 | int dir_fd = DEFAULT_DIR_FD; |
9066 | |
|
9067 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
9068 | 0 | /*minpos*/ 1, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
9069 | 0 | if (!args) { |
9070 | 0 | goto exit; |
9071 | 0 | } |
9072 | 0 | if (!path_converter(args[0], &path)) { |
9073 | 0 | goto exit; |
9074 | 0 | } |
9075 | 0 | if (!noptargs) { |
9076 | 0 | goto skip_optional_pos; |
9077 | 0 | } |
9078 | 0 | if (args[1]) { |
9079 | 0 | mode = PyLong_AsInt(args[1]); |
9080 | 0 | if (mode == -1 && PyErr_Occurred()) { |
9081 | 0 | goto exit; |
9082 | 0 | } |
9083 | 0 | if (!--noptargs) { |
9084 | 0 | goto skip_optional_pos; |
9085 | 0 | } |
9086 | 0 | } |
9087 | 0 | if (args[2]) { |
9088 | 0 | if (!_Py_Dev_Converter(args[2], &device)) { |
9089 | 0 | goto exit; |
9090 | 0 | } |
9091 | 0 | if (!--noptargs) { |
9092 | 0 | goto skip_optional_pos; |
9093 | 0 | } |
9094 | 0 | } |
9095 | 0 | skip_optional_pos: |
9096 | 0 | if (!noptargs) { |
9097 | 0 | goto skip_optional_kwonly; |
9098 | 0 | } |
9099 | 0 | if (!MKNODAT_DIR_FD_CONVERTER(args[3], &dir_fd)) { |
9100 | 0 | goto exit; |
9101 | 0 | } |
9102 | 0 | skip_optional_kwonly: |
9103 | 0 | return_value = os_mknod_impl(module, &path, mode, device, dir_fd); |
9104 | |
|
9105 | 0 | exit: |
9106 | | /* Cleanup for path */ |
9107 | 0 | path_cleanup(&path); |
9108 | |
|
9109 | 0 | return return_value; |
9110 | 0 | } |
9111 | | |
9112 | | #endif /* (defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV)) */ |
9113 | | |
9114 | | #if defined(HAVE_DEVICE_MACROS) |
9115 | | |
9116 | | PyDoc_STRVAR(os_major__doc__, |
9117 | | "major($module, device, /)\n" |
9118 | | "--\n" |
9119 | | "\n" |
9120 | | "Extracts a device major number from a raw device number."); |
9121 | | |
9122 | | #define OS_MAJOR_METHODDEF \ |
9123 | | {"major", (PyCFunction)os_major, METH_O, os_major__doc__}, |
9124 | | |
9125 | | static PyObject * |
9126 | | os_major_impl(PyObject *module, dev_t device); |
9127 | | |
9128 | | static PyObject * |
9129 | | os_major(PyObject *module, PyObject *arg) |
9130 | 0 | { |
9131 | 0 | PyObject *return_value = NULL; |
9132 | 0 | dev_t device; |
9133 | |
|
9134 | 0 | if (!_Py_Dev_Converter(arg, &device)) { |
9135 | 0 | goto exit; |
9136 | 0 | } |
9137 | 0 | return_value = os_major_impl(module, device); |
9138 | |
|
9139 | 0 | exit: |
9140 | 0 | return return_value; |
9141 | 0 | } |
9142 | | |
9143 | | #endif /* defined(HAVE_DEVICE_MACROS) */ |
9144 | | |
9145 | | #if defined(HAVE_DEVICE_MACROS) |
9146 | | |
9147 | | PyDoc_STRVAR(os_minor__doc__, |
9148 | | "minor($module, device, /)\n" |
9149 | | "--\n" |
9150 | | "\n" |
9151 | | "Extracts a device minor number from a raw device number."); |
9152 | | |
9153 | | #define OS_MINOR_METHODDEF \ |
9154 | | {"minor", (PyCFunction)os_minor, METH_O, os_minor__doc__}, |
9155 | | |
9156 | | static PyObject * |
9157 | | os_minor_impl(PyObject *module, dev_t device); |
9158 | | |
9159 | | static PyObject * |
9160 | | os_minor(PyObject *module, PyObject *arg) |
9161 | 0 | { |
9162 | 0 | PyObject *return_value = NULL; |
9163 | 0 | dev_t device; |
9164 | |
|
9165 | 0 | if (!_Py_Dev_Converter(arg, &device)) { |
9166 | 0 | goto exit; |
9167 | 0 | } |
9168 | 0 | return_value = os_minor_impl(module, device); |
9169 | |
|
9170 | 0 | exit: |
9171 | 0 | return return_value; |
9172 | 0 | } |
9173 | | |
9174 | | #endif /* defined(HAVE_DEVICE_MACROS) */ |
9175 | | |
9176 | | #if defined(HAVE_DEVICE_MACROS) |
9177 | | |
9178 | | PyDoc_STRVAR(os_makedev__doc__, |
9179 | | "makedev($module, major, minor, /)\n" |
9180 | | "--\n" |
9181 | | "\n" |
9182 | | "Composes a raw device number from the major and minor device numbers."); |
9183 | | |
9184 | | #define OS_MAKEDEV_METHODDEF \ |
9185 | | {"makedev", _PyCFunction_CAST(os_makedev), METH_FASTCALL, os_makedev__doc__}, |
9186 | | |
9187 | | static dev_t |
9188 | | os_makedev_impl(PyObject *module, dev_t major, dev_t minor); |
9189 | | |
9190 | | static PyObject * |
9191 | | os_makedev(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
9192 | 0 | { |
9193 | 0 | PyObject *return_value = NULL; |
9194 | 0 | dev_t major; |
9195 | 0 | dev_t minor; |
9196 | 0 | dev_t _return_value; |
9197 | |
|
9198 | 0 | if (!_PyArg_CheckPositional("makedev", nargs, 2, 2)) { |
9199 | 0 | goto exit; |
9200 | 0 | } |
9201 | 0 | if (!_Py_Dev_Converter(args[0], &major)) { |
9202 | 0 | goto exit; |
9203 | 0 | } |
9204 | 0 | if (!_Py_Dev_Converter(args[1], &minor)) { |
9205 | 0 | goto exit; |
9206 | 0 | } |
9207 | 0 | _return_value = os_makedev_impl(module, major, minor); |
9208 | 0 | if ((_return_value == (dev_t)-1) && PyErr_Occurred()) { |
9209 | 0 | goto exit; |
9210 | 0 | } |
9211 | 0 | return_value = _PyLong_FromDev(_return_value); |
9212 | |
|
9213 | 0 | exit: |
9214 | 0 | return return_value; |
9215 | 0 | } |
9216 | | |
9217 | | #endif /* defined(HAVE_DEVICE_MACROS) */ |
9218 | | |
9219 | | #if (defined HAVE_FTRUNCATE || defined MS_WINDOWS) |
9220 | | |
9221 | | PyDoc_STRVAR(os_ftruncate__doc__, |
9222 | | "ftruncate($module, fd, length, /)\n" |
9223 | | "--\n" |
9224 | | "\n" |
9225 | | "Truncate a file, specified by file descriptor, to a specific length."); |
9226 | | |
9227 | | #define OS_FTRUNCATE_METHODDEF \ |
9228 | | {"ftruncate", _PyCFunction_CAST(os_ftruncate), METH_FASTCALL, os_ftruncate__doc__}, |
9229 | | |
9230 | | static PyObject * |
9231 | | os_ftruncate_impl(PyObject *module, int fd, Py_off_t length); |
9232 | | |
9233 | | static PyObject * |
9234 | | os_ftruncate(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
9235 | 0 | { |
9236 | 0 | PyObject *return_value = NULL; |
9237 | 0 | int fd; |
9238 | 0 | Py_off_t length; |
9239 | |
|
9240 | 0 | if (!_PyArg_CheckPositional("ftruncate", nargs, 2, 2)) { |
9241 | 0 | goto exit; |
9242 | 0 | } |
9243 | 0 | fd = PyLong_AsInt(args[0]); |
9244 | 0 | if (fd == -1 && PyErr_Occurred()) { |
9245 | 0 | goto exit; |
9246 | 0 | } |
9247 | 0 | if (!Py_off_t_converter(args[1], &length)) { |
9248 | 0 | goto exit; |
9249 | 0 | } |
9250 | 0 | return_value = os_ftruncate_impl(module, fd, length); |
9251 | |
|
9252 | 0 | exit: |
9253 | 0 | return return_value; |
9254 | 0 | } |
9255 | | |
9256 | | #endif /* (defined HAVE_FTRUNCATE || defined MS_WINDOWS) */ |
9257 | | |
9258 | | #if (defined HAVE_TRUNCATE || defined MS_WINDOWS) |
9259 | | |
9260 | | PyDoc_STRVAR(os_truncate__doc__, |
9261 | | "truncate($module, /, path, length)\n" |
9262 | | "--\n" |
9263 | | "\n" |
9264 | | "Truncate a file, specified by path, to a specific length.\n" |
9265 | | "\n" |
9266 | | "On some platforms, path may also be specified as an open file descriptor.\n" |
9267 | | " If this functionality is unavailable, using it raises an exception."); |
9268 | | |
9269 | | #define OS_TRUNCATE_METHODDEF \ |
9270 | | {"truncate", _PyCFunction_CAST(os_truncate), METH_FASTCALL|METH_KEYWORDS, os_truncate__doc__}, |
9271 | | |
9272 | | static PyObject * |
9273 | | os_truncate_impl(PyObject *module, path_t *path, Py_off_t length); |
9274 | | |
9275 | | static PyObject * |
9276 | | os_truncate(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
9277 | 0 | { |
9278 | 0 | PyObject *return_value = NULL; |
9279 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
9280 | |
|
9281 | 0 | #define NUM_KEYWORDS 2 |
9282 | 0 | static struct { |
9283 | 0 | PyGC_Head _this_is_not_used; |
9284 | 0 | PyObject_VAR_HEAD |
9285 | 0 | Py_hash_t ob_hash; |
9286 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
9287 | 0 | } _kwtuple = { |
9288 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
9289 | 0 | .ob_hash = -1, |
9290 | 0 | .ob_item = { &_Py_ID(path), &_Py_ID(length), }, |
9291 | 0 | }; |
9292 | 0 | #undef NUM_KEYWORDS |
9293 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
9294 | |
|
9295 | | #else // !Py_BUILD_CORE |
9296 | | # define KWTUPLE NULL |
9297 | | #endif // !Py_BUILD_CORE |
9298 | |
|
9299 | 0 | static const char * const _keywords[] = {"path", "length", NULL}; |
9300 | 0 | static _PyArg_Parser _parser = { |
9301 | 0 | .keywords = _keywords, |
9302 | 0 | .fname = "truncate", |
9303 | 0 | .kwtuple = KWTUPLE, |
9304 | 0 | }; |
9305 | 0 | #undef KWTUPLE |
9306 | 0 | PyObject *argsbuf[2]; |
9307 | 0 | path_t path = PATH_T_INITIALIZE_P("truncate", "path", 0, 0, 0, PATH_HAVE_FTRUNCATE); |
9308 | 0 | Py_off_t length; |
9309 | |
|
9310 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
9311 | 0 | /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
9312 | 0 | if (!args) { |
9313 | 0 | goto exit; |
9314 | 0 | } |
9315 | 0 | if (!path_converter(args[0], &path)) { |
9316 | 0 | goto exit; |
9317 | 0 | } |
9318 | 0 | if (!Py_off_t_converter(args[1], &length)) { |
9319 | 0 | goto exit; |
9320 | 0 | } |
9321 | 0 | return_value = os_truncate_impl(module, &path, length); |
9322 | |
|
9323 | 0 | exit: |
9324 | | /* Cleanup for path */ |
9325 | 0 | path_cleanup(&path); |
9326 | |
|
9327 | 0 | return return_value; |
9328 | 0 | } |
9329 | | |
9330 | | #endif /* (defined HAVE_TRUNCATE || defined MS_WINDOWS) */ |
9331 | | |
9332 | | #if (defined(HAVE_POSIX_FALLOCATE) && !defined(POSIX_FADVISE_AIX_BUG) && !defined(__wasi__)) |
9333 | | |
9334 | | PyDoc_STRVAR(os_posix_fallocate__doc__, |
9335 | | "posix_fallocate($module, fd, offset, length, /)\n" |
9336 | | "--\n" |
9337 | | "\n" |
9338 | | "Ensure a file has allocated at least a particular number of bytes on disk.\n" |
9339 | | "\n" |
9340 | | "Ensure that the file specified by fd encompasses a range of bytes\n" |
9341 | | "starting at offset bytes from the beginning and continuing for length bytes."); |
9342 | | |
9343 | | #define OS_POSIX_FALLOCATE_METHODDEF \ |
9344 | | {"posix_fallocate", _PyCFunction_CAST(os_posix_fallocate), METH_FASTCALL, os_posix_fallocate__doc__}, |
9345 | | |
9346 | | static PyObject * |
9347 | | os_posix_fallocate_impl(PyObject *module, int fd, Py_off_t offset, |
9348 | | Py_off_t length); |
9349 | | |
9350 | | static PyObject * |
9351 | | os_posix_fallocate(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
9352 | 0 | { |
9353 | 0 | PyObject *return_value = NULL; |
9354 | 0 | int fd; |
9355 | 0 | Py_off_t offset; |
9356 | 0 | Py_off_t length; |
9357 | |
|
9358 | 0 | if (!_PyArg_CheckPositional("posix_fallocate", nargs, 3, 3)) { |
9359 | 0 | goto exit; |
9360 | 0 | } |
9361 | 0 | fd = PyLong_AsInt(args[0]); |
9362 | 0 | if (fd == -1 && PyErr_Occurred()) { |
9363 | 0 | goto exit; |
9364 | 0 | } |
9365 | 0 | if (!Py_off_t_converter(args[1], &offset)) { |
9366 | 0 | goto exit; |
9367 | 0 | } |
9368 | 0 | if (!Py_off_t_converter(args[2], &length)) { |
9369 | 0 | goto exit; |
9370 | 0 | } |
9371 | 0 | return_value = os_posix_fallocate_impl(module, fd, offset, length); |
9372 | |
|
9373 | 0 | exit: |
9374 | 0 | return return_value; |
9375 | 0 | } |
9376 | | |
9377 | | #endif /* (defined(HAVE_POSIX_FALLOCATE) && !defined(POSIX_FADVISE_AIX_BUG) && !defined(__wasi__)) */ |
9378 | | |
9379 | | #if (defined(HAVE_POSIX_FADVISE) && !defined(POSIX_FADVISE_AIX_BUG)) |
9380 | | |
9381 | | PyDoc_STRVAR(os_posix_fadvise__doc__, |
9382 | | "posix_fadvise($module, fd, offset, length, advice, /)\n" |
9383 | | "--\n" |
9384 | | "\n" |
9385 | | "Announce an intention to access data in a specific pattern.\n" |
9386 | | "\n" |
9387 | | "Announce an intention to access data in a specific pattern, thus allowing\n" |
9388 | | "the kernel to make optimizations.\n" |
9389 | | "The advice applies to the region of the file specified by fd starting at\n" |
9390 | | "offset and continuing for length bytes.\n" |
9391 | | "advice is one of POSIX_FADV_NORMAL, POSIX_FADV_SEQUENTIAL,\n" |
9392 | | "POSIX_FADV_RANDOM, POSIX_FADV_NOREUSE, POSIX_FADV_WILLNEED, or\n" |
9393 | | "POSIX_FADV_DONTNEED."); |
9394 | | |
9395 | | #define OS_POSIX_FADVISE_METHODDEF \ |
9396 | | {"posix_fadvise", _PyCFunction_CAST(os_posix_fadvise), METH_FASTCALL, os_posix_fadvise__doc__}, |
9397 | | |
9398 | | static PyObject * |
9399 | | os_posix_fadvise_impl(PyObject *module, int fd, Py_off_t offset, |
9400 | | Py_off_t length, int advice); |
9401 | | |
9402 | | static PyObject * |
9403 | | os_posix_fadvise(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
9404 | 0 | { |
9405 | 0 | PyObject *return_value = NULL; |
9406 | 0 | int fd; |
9407 | 0 | Py_off_t offset; |
9408 | 0 | Py_off_t length; |
9409 | 0 | int advice; |
9410 | |
|
9411 | 0 | if (!_PyArg_CheckPositional("posix_fadvise", nargs, 4, 4)) { |
9412 | 0 | goto exit; |
9413 | 0 | } |
9414 | 0 | fd = PyLong_AsInt(args[0]); |
9415 | 0 | if (fd == -1 && PyErr_Occurred()) { |
9416 | 0 | goto exit; |
9417 | 0 | } |
9418 | 0 | if (!Py_off_t_converter(args[1], &offset)) { |
9419 | 0 | goto exit; |
9420 | 0 | } |
9421 | 0 | if (!Py_off_t_converter(args[2], &length)) { |
9422 | 0 | goto exit; |
9423 | 0 | } |
9424 | 0 | advice = PyLong_AsInt(args[3]); |
9425 | 0 | if (advice == -1 && PyErr_Occurred()) { |
9426 | 0 | goto exit; |
9427 | 0 | } |
9428 | 0 | return_value = os_posix_fadvise_impl(module, fd, offset, length, advice); |
9429 | |
|
9430 | 0 | exit: |
9431 | 0 | return return_value; |
9432 | 0 | } |
9433 | | |
9434 | | #endif /* (defined(HAVE_POSIX_FADVISE) && !defined(POSIX_FADVISE_AIX_BUG)) */ |
9435 | | |
9436 | | #if defined(MS_WINDOWS) |
9437 | | |
9438 | | PyDoc_STRVAR(os_putenv__doc__, |
9439 | | "putenv($module, name, value, /)\n" |
9440 | | "--\n" |
9441 | | "\n" |
9442 | | "Change or add an environment variable."); |
9443 | | |
9444 | | #define OS_PUTENV_METHODDEF \ |
9445 | | {"putenv", _PyCFunction_CAST(os_putenv), METH_FASTCALL, os_putenv__doc__}, |
9446 | | |
9447 | | static PyObject * |
9448 | | os_putenv_impl(PyObject *module, PyObject *name, PyObject *value); |
9449 | | |
9450 | | static PyObject * |
9451 | | os_putenv(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
9452 | | { |
9453 | | PyObject *return_value = NULL; |
9454 | | PyObject *name; |
9455 | | PyObject *value; |
9456 | | |
9457 | | if (!_PyArg_CheckPositional("putenv", nargs, 2, 2)) { |
9458 | | goto exit; |
9459 | | } |
9460 | | if (!PyUnicode_Check(args[0])) { |
9461 | | _PyArg_BadArgument("putenv", "argument 1", "str", args[0]); |
9462 | | goto exit; |
9463 | | } |
9464 | | name = args[0]; |
9465 | | if (!PyUnicode_Check(args[1])) { |
9466 | | _PyArg_BadArgument("putenv", "argument 2", "str", args[1]); |
9467 | | goto exit; |
9468 | | } |
9469 | | value = args[1]; |
9470 | | return_value = os_putenv_impl(module, name, value); |
9471 | | |
9472 | | exit: |
9473 | | return return_value; |
9474 | | } |
9475 | | |
9476 | | #endif /* defined(MS_WINDOWS) */ |
9477 | | |
9478 | | #if !defined(MS_WINDOWS) |
9479 | | |
9480 | | PyDoc_STRVAR(os_putenv__doc__, |
9481 | | "putenv($module, name, value, /)\n" |
9482 | | "--\n" |
9483 | | "\n" |
9484 | | "Change or add an environment variable."); |
9485 | | |
9486 | | #define OS_PUTENV_METHODDEF \ |
9487 | | {"putenv", _PyCFunction_CAST(os_putenv), METH_FASTCALL, os_putenv__doc__}, |
9488 | | |
9489 | | static PyObject * |
9490 | | os_putenv_impl(PyObject *module, PyObject *name, PyObject *value); |
9491 | | |
9492 | | static PyObject * |
9493 | | os_putenv(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
9494 | 0 | { |
9495 | 0 | PyObject *return_value = NULL; |
9496 | 0 | PyObject *name = NULL; |
9497 | 0 | PyObject *value = NULL; |
9498 | |
|
9499 | 0 | if (!_PyArg_CheckPositional("putenv", nargs, 2, 2)) { |
9500 | 0 | goto exit; |
9501 | 0 | } |
9502 | 0 | if (!PyUnicode_FSConverter(args[0], &name)) { |
9503 | 0 | goto exit; |
9504 | 0 | } |
9505 | 0 | if (!PyUnicode_FSConverter(args[1], &value)) { |
9506 | 0 | goto exit; |
9507 | 0 | } |
9508 | 0 | return_value = os_putenv_impl(module, name, value); |
9509 | |
|
9510 | 0 | exit: |
9511 | | /* Cleanup for name */ |
9512 | 0 | Py_XDECREF(name); |
9513 | | /* Cleanup for value */ |
9514 | 0 | Py_XDECREF(value); |
9515 | |
|
9516 | 0 | return return_value; |
9517 | 0 | } |
9518 | | |
9519 | | #endif /* !defined(MS_WINDOWS) */ |
9520 | | |
9521 | | #if defined(MS_WINDOWS) |
9522 | | |
9523 | | PyDoc_STRVAR(os_unsetenv__doc__, |
9524 | | "unsetenv($module, name, /)\n" |
9525 | | "--\n" |
9526 | | "\n" |
9527 | | "Delete an environment variable."); |
9528 | | |
9529 | | #define OS_UNSETENV_METHODDEF \ |
9530 | | {"unsetenv", (PyCFunction)os_unsetenv, METH_O, os_unsetenv__doc__}, |
9531 | | |
9532 | | static PyObject * |
9533 | | os_unsetenv_impl(PyObject *module, PyObject *name); |
9534 | | |
9535 | | static PyObject * |
9536 | | os_unsetenv(PyObject *module, PyObject *arg) |
9537 | | { |
9538 | | PyObject *return_value = NULL; |
9539 | | PyObject *name; |
9540 | | |
9541 | | if (!PyUnicode_Check(arg)) { |
9542 | | _PyArg_BadArgument("unsetenv", "argument", "str", arg); |
9543 | | goto exit; |
9544 | | } |
9545 | | name = arg; |
9546 | | return_value = os_unsetenv_impl(module, name); |
9547 | | |
9548 | | exit: |
9549 | | return return_value; |
9550 | | } |
9551 | | |
9552 | | #endif /* defined(MS_WINDOWS) */ |
9553 | | |
9554 | | #if !defined(MS_WINDOWS) |
9555 | | |
9556 | | PyDoc_STRVAR(os_unsetenv__doc__, |
9557 | | "unsetenv($module, name, /)\n" |
9558 | | "--\n" |
9559 | | "\n" |
9560 | | "Delete an environment variable."); |
9561 | | |
9562 | | #define OS_UNSETENV_METHODDEF \ |
9563 | | {"unsetenv", (PyCFunction)os_unsetenv, METH_O, os_unsetenv__doc__}, |
9564 | | |
9565 | | static PyObject * |
9566 | | os_unsetenv_impl(PyObject *module, PyObject *name); |
9567 | | |
9568 | | static PyObject * |
9569 | | os_unsetenv(PyObject *module, PyObject *arg) |
9570 | 0 | { |
9571 | 0 | PyObject *return_value = NULL; |
9572 | 0 | PyObject *name = NULL; |
9573 | |
|
9574 | 0 | if (!PyUnicode_FSConverter(arg, &name)) { |
9575 | 0 | goto exit; |
9576 | 0 | } |
9577 | 0 | return_value = os_unsetenv_impl(module, name); |
9578 | |
|
9579 | 0 | exit: |
9580 | | /* Cleanup for name */ |
9581 | 0 | Py_XDECREF(name); |
9582 | |
|
9583 | 0 | return return_value; |
9584 | 0 | } |
9585 | | |
9586 | | #endif /* !defined(MS_WINDOWS) */ |
9587 | | |
9588 | | PyDoc_STRVAR(os_strerror__doc__, |
9589 | | "strerror($module, code, /)\n" |
9590 | | "--\n" |
9591 | | "\n" |
9592 | | "Translate an error code to a message string."); |
9593 | | |
9594 | | #define OS_STRERROR_METHODDEF \ |
9595 | | {"strerror", (PyCFunction)os_strerror, METH_O, os_strerror__doc__}, |
9596 | | |
9597 | | static PyObject * |
9598 | | os_strerror_impl(PyObject *module, int code); |
9599 | | |
9600 | | static PyObject * |
9601 | | os_strerror(PyObject *module, PyObject *arg) |
9602 | 0 | { |
9603 | 0 | PyObject *return_value = NULL; |
9604 | 0 | int code; |
9605 | |
|
9606 | 0 | code = PyLong_AsInt(arg); |
9607 | 0 | if (code == -1 && PyErr_Occurred()) { |
9608 | 0 | goto exit; |
9609 | 0 | } |
9610 | 0 | return_value = os_strerror_impl(module, code); |
9611 | |
|
9612 | 0 | exit: |
9613 | 0 | return return_value; |
9614 | 0 | } |
9615 | | |
9616 | | #if defined(HAVE_SYS_WAIT_H) && defined(WCOREDUMP) |
9617 | | |
9618 | | PyDoc_STRVAR(os_WCOREDUMP__doc__, |
9619 | | "WCOREDUMP($module, status, /)\n" |
9620 | | "--\n" |
9621 | | "\n" |
9622 | | "Return True if the process returning status was dumped to a core file."); |
9623 | | |
9624 | | #define OS_WCOREDUMP_METHODDEF \ |
9625 | | {"WCOREDUMP", (PyCFunction)os_WCOREDUMP, METH_O, os_WCOREDUMP__doc__}, |
9626 | | |
9627 | | static int |
9628 | | os_WCOREDUMP_impl(PyObject *module, int status); |
9629 | | |
9630 | | static PyObject * |
9631 | | os_WCOREDUMP(PyObject *module, PyObject *arg) |
9632 | 0 | { |
9633 | 0 | PyObject *return_value = NULL; |
9634 | 0 | int status; |
9635 | 0 | int _return_value; |
9636 | |
|
9637 | 0 | status = PyLong_AsInt(arg); |
9638 | 0 | if (status == -1 && PyErr_Occurred()) { |
9639 | 0 | goto exit; |
9640 | 0 | } |
9641 | 0 | _return_value = os_WCOREDUMP_impl(module, status); |
9642 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
9643 | 0 | goto exit; |
9644 | 0 | } |
9645 | 0 | return_value = PyBool_FromLong((long)_return_value); |
9646 | |
|
9647 | 0 | exit: |
9648 | 0 | return return_value; |
9649 | 0 | } |
9650 | | |
9651 | | #endif /* defined(HAVE_SYS_WAIT_H) && defined(WCOREDUMP) */ |
9652 | | |
9653 | | #if defined(HAVE_SYS_WAIT_H) && defined(WIFCONTINUED) |
9654 | | |
9655 | | PyDoc_STRVAR(os_WIFCONTINUED__doc__, |
9656 | | "WIFCONTINUED($module, /, status)\n" |
9657 | | "--\n" |
9658 | | "\n" |
9659 | | "Return True if a particular process was continued from a job control stop.\n" |
9660 | | "\n" |
9661 | | "Return True if the process returning status was continued from a\n" |
9662 | | "job control stop."); |
9663 | | |
9664 | | #define OS_WIFCONTINUED_METHODDEF \ |
9665 | | {"WIFCONTINUED", _PyCFunction_CAST(os_WIFCONTINUED), METH_FASTCALL|METH_KEYWORDS, os_WIFCONTINUED__doc__}, |
9666 | | |
9667 | | static int |
9668 | | os_WIFCONTINUED_impl(PyObject *module, int status); |
9669 | | |
9670 | | static PyObject * |
9671 | | os_WIFCONTINUED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
9672 | 0 | { |
9673 | 0 | PyObject *return_value = NULL; |
9674 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
9675 | |
|
9676 | 0 | #define NUM_KEYWORDS 1 |
9677 | 0 | static struct { |
9678 | 0 | PyGC_Head _this_is_not_used; |
9679 | 0 | PyObject_VAR_HEAD |
9680 | 0 | Py_hash_t ob_hash; |
9681 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
9682 | 0 | } _kwtuple = { |
9683 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
9684 | 0 | .ob_hash = -1, |
9685 | 0 | .ob_item = { &_Py_ID(status), }, |
9686 | 0 | }; |
9687 | 0 | #undef NUM_KEYWORDS |
9688 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
9689 | |
|
9690 | | #else // !Py_BUILD_CORE |
9691 | | # define KWTUPLE NULL |
9692 | | #endif // !Py_BUILD_CORE |
9693 | |
|
9694 | 0 | static const char * const _keywords[] = {"status", NULL}; |
9695 | 0 | static _PyArg_Parser _parser = { |
9696 | 0 | .keywords = _keywords, |
9697 | 0 | .fname = "WIFCONTINUED", |
9698 | 0 | .kwtuple = KWTUPLE, |
9699 | 0 | }; |
9700 | 0 | #undef KWTUPLE |
9701 | 0 | PyObject *argsbuf[1]; |
9702 | 0 | int status; |
9703 | 0 | int _return_value; |
9704 | |
|
9705 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
9706 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
9707 | 0 | if (!args) { |
9708 | 0 | goto exit; |
9709 | 0 | } |
9710 | 0 | status = PyLong_AsInt(args[0]); |
9711 | 0 | if (status == -1 && PyErr_Occurred()) { |
9712 | 0 | goto exit; |
9713 | 0 | } |
9714 | 0 | _return_value = os_WIFCONTINUED_impl(module, status); |
9715 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
9716 | 0 | goto exit; |
9717 | 0 | } |
9718 | 0 | return_value = PyBool_FromLong((long)_return_value); |
9719 | |
|
9720 | 0 | exit: |
9721 | 0 | return return_value; |
9722 | 0 | } |
9723 | | |
9724 | | #endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFCONTINUED) */ |
9725 | | |
9726 | | #if defined(HAVE_SYS_WAIT_H) && defined(WIFSTOPPED) |
9727 | | |
9728 | | PyDoc_STRVAR(os_WIFSTOPPED__doc__, |
9729 | | "WIFSTOPPED($module, /, status)\n" |
9730 | | "--\n" |
9731 | | "\n" |
9732 | | "Return True if the process returning status was stopped."); |
9733 | | |
9734 | | #define OS_WIFSTOPPED_METHODDEF \ |
9735 | | {"WIFSTOPPED", _PyCFunction_CAST(os_WIFSTOPPED), METH_FASTCALL|METH_KEYWORDS, os_WIFSTOPPED__doc__}, |
9736 | | |
9737 | | static int |
9738 | | os_WIFSTOPPED_impl(PyObject *module, int status); |
9739 | | |
9740 | | static PyObject * |
9741 | | os_WIFSTOPPED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
9742 | 0 | { |
9743 | 0 | PyObject *return_value = NULL; |
9744 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
9745 | |
|
9746 | 0 | #define NUM_KEYWORDS 1 |
9747 | 0 | static struct { |
9748 | 0 | PyGC_Head _this_is_not_used; |
9749 | 0 | PyObject_VAR_HEAD |
9750 | 0 | Py_hash_t ob_hash; |
9751 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
9752 | 0 | } _kwtuple = { |
9753 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
9754 | 0 | .ob_hash = -1, |
9755 | 0 | .ob_item = { &_Py_ID(status), }, |
9756 | 0 | }; |
9757 | 0 | #undef NUM_KEYWORDS |
9758 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
9759 | |
|
9760 | | #else // !Py_BUILD_CORE |
9761 | | # define KWTUPLE NULL |
9762 | | #endif // !Py_BUILD_CORE |
9763 | |
|
9764 | 0 | static const char * const _keywords[] = {"status", NULL}; |
9765 | 0 | static _PyArg_Parser _parser = { |
9766 | 0 | .keywords = _keywords, |
9767 | 0 | .fname = "WIFSTOPPED", |
9768 | 0 | .kwtuple = KWTUPLE, |
9769 | 0 | }; |
9770 | 0 | #undef KWTUPLE |
9771 | 0 | PyObject *argsbuf[1]; |
9772 | 0 | int status; |
9773 | 0 | int _return_value; |
9774 | |
|
9775 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
9776 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
9777 | 0 | if (!args) { |
9778 | 0 | goto exit; |
9779 | 0 | } |
9780 | 0 | status = PyLong_AsInt(args[0]); |
9781 | 0 | if (status == -1 && PyErr_Occurred()) { |
9782 | 0 | goto exit; |
9783 | 0 | } |
9784 | 0 | _return_value = os_WIFSTOPPED_impl(module, status); |
9785 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
9786 | 0 | goto exit; |
9787 | 0 | } |
9788 | 0 | return_value = PyBool_FromLong((long)_return_value); |
9789 | |
|
9790 | 0 | exit: |
9791 | 0 | return return_value; |
9792 | 0 | } |
9793 | | |
9794 | | #endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFSTOPPED) */ |
9795 | | |
9796 | | #if defined(HAVE_SYS_WAIT_H) && defined(WIFSIGNALED) |
9797 | | |
9798 | | PyDoc_STRVAR(os_WIFSIGNALED__doc__, |
9799 | | "WIFSIGNALED($module, /, status)\n" |
9800 | | "--\n" |
9801 | | "\n" |
9802 | | "Return True if the process returning status was terminated by a signal."); |
9803 | | |
9804 | | #define OS_WIFSIGNALED_METHODDEF \ |
9805 | | {"WIFSIGNALED", _PyCFunction_CAST(os_WIFSIGNALED), METH_FASTCALL|METH_KEYWORDS, os_WIFSIGNALED__doc__}, |
9806 | | |
9807 | | static int |
9808 | | os_WIFSIGNALED_impl(PyObject *module, int status); |
9809 | | |
9810 | | static PyObject * |
9811 | | os_WIFSIGNALED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
9812 | 0 | { |
9813 | 0 | PyObject *return_value = NULL; |
9814 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
9815 | |
|
9816 | 0 | #define NUM_KEYWORDS 1 |
9817 | 0 | static struct { |
9818 | 0 | PyGC_Head _this_is_not_used; |
9819 | 0 | PyObject_VAR_HEAD |
9820 | 0 | Py_hash_t ob_hash; |
9821 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
9822 | 0 | } _kwtuple = { |
9823 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
9824 | 0 | .ob_hash = -1, |
9825 | 0 | .ob_item = { &_Py_ID(status), }, |
9826 | 0 | }; |
9827 | 0 | #undef NUM_KEYWORDS |
9828 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
9829 | |
|
9830 | | #else // !Py_BUILD_CORE |
9831 | | # define KWTUPLE NULL |
9832 | | #endif // !Py_BUILD_CORE |
9833 | |
|
9834 | 0 | static const char * const _keywords[] = {"status", NULL}; |
9835 | 0 | static _PyArg_Parser _parser = { |
9836 | 0 | .keywords = _keywords, |
9837 | 0 | .fname = "WIFSIGNALED", |
9838 | 0 | .kwtuple = KWTUPLE, |
9839 | 0 | }; |
9840 | 0 | #undef KWTUPLE |
9841 | 0 | PyObject *argsbuf[1]; |
9842 | 0 | int status; |
9843 | 0 | int _return_value; |
9844 | |
|
9845 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
9846 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
9847 | 0 | if (!args) { |
9848 | 0 | goto exit; |
9849 | 0 | } |
9850 | 0 | status = PyLong_AsInt(args[0]); |
9851 | 0 | if (status == -1 && PyErr_Occurred()) { |
9852 | 0 | goto exit; |
9853 | 0 | } |
9854 | 0 | _return_value = os_WIFSIGNALED_impl(module, status); |
9855 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
9856 | 0 | goto exit; |
9857 | 0 | } |
9858 | 0 | return_value = PyBool_FromLong((long)_return_value); |
9859 | |
|
9860 | 0 | exit: |
9861 | 0 | return return_value; |
9862 | 0 | } |
9863 | | |
9864 | | #endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFSIGNALED) */ |
9865 | | |
9866 | | #if defined(HAVE_SYS_WAIT_H) && defined(WIFEXITED) |
9867 | | |
9868 | | PyDoc_STRVAR(os_WIFEXITED__doc__, |
9869 | | "WIFEXITED($module, /, status)\n" |
9870 | | "--\n" |
9871 | | "\n" |
9872 | | "Return True if the process returning status exited via the exit() system call."); |
9873 | | |
9874 | | #define OS_WIFEXITED_METHODDEF \ |
9875 | | {"WIFEXITED", _PyCFunction_CAST(os_WIFEXITED), METH_FASTCALL|METH_KEYWORDS, os_WIFEXITED__doc__}, |
9876 | | |
9877 | | static int |
9878 | | os_WIFEXITED_impl(PyObject *module, int status); |
9879 | | |
9880 | | static PyObject * |
9881 | | os_WIFEXITED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
9882 | 0 | { |
9883 | 0 | PyObject *return_value = NULL; |
9884 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
9885 | |
|
9886 | 0 | #define NUM_KEYWORDS 1 |
9887 | 0 | static struct { |
9888 | 0 | PyGC_Head _this_is_not_used; |
9889 | 0 | PyObject_VAR_HEAD |
9890 | 0 | Py_hash_t ob_hash; |
9891 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
9892 | 0 | } _kwtuple = { |
9893 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
9894 | 0 | .ob_hash = -1, |
9895 | 0 | .ob_item = { &_Py_ID(status), }, |
9896 | 0 | }; |
9897 | 0 | #undef NUM_KEYWORDS |
9898 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
9899 | |
|
9900 | | #else // !Py_BUILD_CORE |
9901 | | # define KWTUPLE NULL |
9902 | | #endif // !Py_BUILD_CORE |
9903 | |
|
9904 | 0 | static const char * const _keywords[] = {"status", NULL}; |
9905 | 0 | static _PyArg_Parser _parser = { |
9906 | 0 | .keywords = _keywords, |
9907 | 0 | .fname = "WIFEXITED", |
9908 | 0 | .kwtuple = KWTUPLE, |
9909 | 0 | }; |
9910 | 0 | #undef KWTUPLE |
9911 | 0 | PyObject *argsbuf[1]; |
9912 | 0 | int status; |
9913 | 0 | int _return_value; |
9914 | |
|
9915 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
9916 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
9917 | 0 | if (!args) { |
9918 | 0 | goto exit; |
9919 | 0 | } |
9920 | 0 | status = PyLong_AsInt(args[0]); |
9921 | 0 | if (status == -1 && PyErr_Occurred()) { |
9922 | 0 | goto exit; |
9923 | 0 | } |
9924 | 0 | _return_value = os_WIFEXITED_impl(module, status); |
9925 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
9926 | 0 | goto exit; |
9927 | 0 | } |
9928 | 0 | return_value = PyBool_FromLong((long)_return_value); |
9929 | |
|
9930 | 0 | exit: |
9931 | 0 | return return_value; |
9932 | 0 | } |
9933 | | |
9934 | | #endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFEXITED) */ |
9935 | | |
9936 | | #if defined(HAVE_SYS_WAIT_H) && defined(WEXITSTATUS) |
9937 | | |
9938 | | PyDoc_STRVAR(os_WEXITSTATUS__doc__, |
9939 | | "WEXITSTATUS($module, /, status)\n" |
9940 | | "--\n" |
9941 | | "\n" |
9942 | | "Return the process return code from status."); |
9943 | | |
9944 | | #define OS_WEXITSTATUS_METHODDEF \ |
9945 | | {"WEXITSTATUS", _PyCFunction_CAST(os_WEXITSTATUS), METH_FASTCALL|METH_KEYWORDS, os_WEXITSTATUS__doc__}, |
9946 | | |
9947 | | static int |
9948 | | os_WEXITSTATUS_impl(PyObject *module, int status); |
9949 | | |
9950 | | static PyObject * |
9951 | | os_WEXITSTATUS(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
9952 | 0 | { |
9953 | 0 | PyObject *return_value = NULL; |
9954 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
9955 | |
|
9956 | 0 | #define NUM_KEYWORDS 1 |
9957 | 0 | static struct { |
9958 | 0 | PyGC_Head _this_is_not_used; |
9959 | 0 | PyObject_VAR_HEAD |
9960 | 0 | Py_hash_t ob_hash; |
9961 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
9962 | 0 | } _kwtuple = { |
9963 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
9964 | 0 | .ob_hash = -1, |
9965 | 0 | .ob_item = { &_Py_ID(status), }, |
9966 | 0 | }; |
9967 | 0 | #undef NUM_KEYWORDS |
9968 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
9969 | |
|
9970 | | #else // !Py_BUILD_CORE |
9971 | | # define KWTUPLE NULL |
9972 | | #endif // !Py_BUILD_CORE |
9973 | |
|
9974 | 0 | static const char * const _keywords[] = {"status", NULL}; |
9975 | 0 | static _PyArg_Parser _parser = { |
9976 | 0 | .keywords = _keywords, |
9977 | 0 | .fname = "WEXITSTATUS", |
9978 | 0 | .kwtuple = KWTUPLE, |
9979 | 0 | }; |
9980 | 0 | #undef KWTUPLE |
9981 | 0 | PyObject *argsbuf[1]; |
9982 | 0 | int status; |
9983 | 0 | int _return_value; |
9984 | |
|
9985 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
9986 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
9987 | 0 | if (!args) { |
9988 | 0 | goto exit; |
9989 | 0 | } |
9990 | 0 | status = PyLong_AsInt(args[0]); |
9991 | 0 | if (status == -1 && PyErr_Occurred()) { |
9992 | 0 | goto exit; |
9993 | 0 | } |
9994 | 0 | _return_value = os_WEXITSTATUS_impl(module, status); |
9995 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
9996 | 0 | goto exit; |
9997 | 0 | } |
9998 | 0 | return_value = PyLong_FromLong((long)_return_value); |
9999 | |
|
10000 | 0 | exit: |
10001 | 0 | return return_value; |
10002 | 0 | } |
10003 | | |
10004 | | #endif /* defined(HAVE_SYS_WAIT_H) && defined(WEXITSTATUS) */ |
10005 | | |
10006 | | #if defined(HAVE_SYS_WAIT_H) && defined(WTERMSIG) |
10007 | | |
10008 | | PyDoc_STRVAR(os_WTERMSIG__doc__, |
10009 | | "WTERMSIG($module, /, status)\n" |
10010 | | "--\n" |
10011 | | "\n" |
10012 | | "Return the signal that terminated the process that provided the status value."); |
10013 | | |
10014 | | #define OS_WTERMSIG_METHODDEF \ |
10015 | | {"WTERMSIG", _PyCFunction_CAST(os_WTERMSIG), METH_FASTCALL|METH_KEYWORDS, os_WTERMSIG__doc__}, |
10016 | | |
10017 | | static int |
10018 | | os_WTERMSIG_impl(PyObject *module, int status); |
10019 | | |
10020 | | static PyObject * |
10021 | | os_WTERMSIG(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
10022 | 0 | { |
10023 | 0 | PyObject *return_value = NULL; |
10024 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
10025 | |
|
10026 | 0 | #define NUM_KEYWORDS 1 |
10027 | 0 | static struct { |
10028 | 0 | PyGC_Head _this_is_not_used; |
10029 | 0 | PyObject_VAR_HEAD |
10030 | 0 | Py_hash_t ob_hash; |
10031 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
10032 | 0 | } _kwtuple = { |
10033 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
10034 | 0 | .ob_hash = -1, |
10035 | 0 | .ob_item = { &_Py_ID(status), }, |
10036 | 0 | }; |
10037 | 0 | #undef NUM_KEYWORDS |
10038 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
10039 | |
|
10040 | | #else // !Py_BUILD_CORE |
10041 | | # define KWTUPLE NULL |
10042 | | #endif // !Py_BUILD_CORE |
10043 | |
|
10044 | 0 | static const char * const _keywords[] = {"status", NULL}; |
10045 | 0 | static _PyArg_Parser _parser = { |
10046 | 0 | .keywords = _keywords, |
10047 | 0 | .fname = "WTERMSIG", |
10048 | 0 | .kwtuple = KWTUPLE, |
10049 | 0 | }; |
10050 | 0 | #undef KWTUPLE |
10051 | 0 | PyObject *argsbuf[1]; |
10052 | 0 | int status; |
10053 | 0 | int _return_value; |
10054 | |
|
10055 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
10056 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
10057 | 0 | if (!args) { |
10058 | 0 | goto exit; |
10059 | 0 | } |
10060 | 0 | status = PyLong_AsInt(args[0]); |
10061 | 0 | if (status == -1 && PyErr_Occurred()) { |
10062 | 0 | goto exit; |
10063 | 0 | } |
10064 | 0 | _return_value = os_WTERMSIG_impl(module, status); |
10065 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
10066 | 0 | goto exit; |
10067 | 0 | } |
10068 | 0 | return_value = PyLong_FromLong((long)_return_value); |
10069 | |
|
10070 | 0 | exit: |
10071 | 0 | return return_value; |
10072 | 0 | } |
10073 | | |
10074 | | #endif /* defined(HAVE_SYS_WAIT_H) && defined(WTERMSIG) */ |
10075 | | |
10076 | | #if defined(HAVE_SYS_WAIT_H) && defined(WSTOPSIG) |
10077 | | |
10078 | | PyDoc_STRVAR(os_WSTOPSIG__doc__, |
10079 | | "WSTOPSIG($module, /, status)\n" |
10080 | | "--\n" |
10081 | | "\n" |
10082 | | "Return the signal that stopped the process that provided the status value."); |
10083 | | |
10084 | | #define OS_WSTOPSIG_METHODDEF \ |
10085 | | {"WSTOPSIG", _PyCFunction_CAST(os_WSTOPSIG), METH_FASTCALL|METH_KEYWORDS, os_WSTOPSIG__doc__}, |
10086 | | |
10087 | | static int |
10088 | | os_WSTOPSIG_impl(PyObject *module, int status); |
10089 | | |
10090 | | static PyObject * |
10091 | | os_WSTOPSIG(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
10092 | 0 | { |
10093 | 0 | PyObject *return_value = NULL; |
10094 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
10095 | |
|
10096 | 0 | #define NUM_KEYWORDS 1 |
10097 | 0 | static struct { |
10098 | 0 | PyGC_Head _this_is_not_used; |
10099 | 0 | PyObject_VAR_HEAD |
10100 | 0 | Py_hash_t ob_hash; |
10101 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
10102 | 0 | } _kwtuple = { |
10103 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
10104 | 0 | .ob_hash = -1, |
10105 | 0 | .ob_item = { &_Py_ID(status), }, |
10106 | 0 | }; |
10107 | 0 | #undef NUM_KEYWORDS |
10108 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
10109 | |
|
10110 | | #else // !Py_BUILD_CORE |
10111 | | # define KWTUPLE NULL |
10112 | | #endif // !Py_BUILD_CORE |
10113 | |
|
10114 | 0 | static const char * const _keywords[] = {"status", NULL}; |
10115 | 0 | static _PyArg_Parser _parser = { |
10116 | 0 | .keywords = _keywords, |
10117 | 0 | .fname = "WSTOPSIG", |
10118 | 0 | .kwtuple = KWTUPLE, |
10119 | 0 | }; |
10120 | 0 | #undef KWTUPLE |
10121 | 0 | PyObject *argsbuf[1]; |
10122 | 0 | int status; |
10123 | 0 | int _return_value; |
10124 | |
|
10125 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
10126 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
10127 | 0 | if (!args) { |
10128 | 0 | goto exit; |
10129 | 0 | } |
10130 | 0 | status = PyLong_AsInt(args[0]); |
10131 | 0 | if (status == -1 && PyErr_Occurred()) { |
10132 | 0 | goto exit; |
10133 | 0 | } |
10134 | 0 | _return_value = os_WSTOPSIG_impl(module, status); |
10135 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
10136 | 0 | goto exit; |
10137 | 0 | } |
10138 | 0 | return_value = PyLong_FromLong((long)_return_value); |
10139 | |
|
10140 | 0 | exit: |
10141 | 0 | return return_value; |
10142 | 0 | } |
10143 | | |
10144 | | #endif /* defined(HAVE_SYS_WAIT_H) && defined(WSTOPSIG) */ |
10145 | | |
10146 | | #if (defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H)) |
10147 | | |
10148 | | PyDoc_STRVAR(os_fstatvfs__doc__, |
10149 | | "fstatvfs($module, fd, /)\n" |
10150 | | "--\n" |
10151 | | "\n" |
10152 | | "Perform an fstatvfs system call on the given fd.\n" |
10153 | | "\n" |
10154 | | "Equivalent to statvfs(fd)."); |
10155 | | |
10156 | | #define OS_FSTATVFS_METHODDEF \ |
10157 | | {"fstatvfs", (PyCFunction)os_fstatvfs, METH_O, os_fstatvfs__doc__}, |
10158 | | |
10159 | | static PyObject * |
10160 | | os_fstatvfs_impl(PyObject *module, int fd); |
10161 | | |
10162 | | static PyObject * |
10163 | | os_fstatvfs(PyObject *module, PyObject *arg) |
10164 | 0 | { |
10165 | 0 | PyObject *return_value = NULL; |
10166 | 0 | int fd; |
10167 | |
|
10168 | 0 | fd = PyLong_AsInt(arg); |
10169 | 0 | if (fd == -1 && PyErr_Occurred()) { |
10170 | 0 | goto exit; |
10171 | 0 | } |
10172 | 0 | return_value = os_fstatvfs_impl(module, fd); |
10173 | |
|
10174 | 0 | exit: |
10175 | 0 | return return_value; |
10176 | 0 | } |
10177 | | |
10178 | | #endif /* (defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H)) */ |
10179 | | |
10180 | | #if (defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H)) |
10181 | | |
10182 | | PyDoc_STRVAR(os_statvfs__doc__, |
10183 | | "statvfs($module, /, path)\n" |
10184 | | "--\n" |
10185 | | "\n" |
10186 | | "Perform a statvfs system call on the given path.\n" |
10187 | | "\n" |
10188 | | "path may always be specified as a string.\n" |
10189 | | "On some platforms, path may also be specified as an open file descriptor.\n" |
10190 | | " If this functionality is unavailable, using it raises an exception."); |
10191 | | |
10192 | | #define OS_STATVFS_METHODDEF \ |
10193 | | {"statvfs", _PyCFunction_CAST(os_statvfs), METH_FASTCALL|METH_KEYWORDS, os_statvfs__doc__}, |
10194 | | |
10195 | | static PyObject * |
10196 | | os_statvfs_impl(PyObject *module, path_t *path); |
10197 | | |
10198 | | static PyObject * |
10199 | | os_statvfs(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
10200 | 0 | { |
10201 | 0 | PyObject *return_value = NULL; |
10202 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
10203 | |
|
10204 | 0 | #define NUM_KEYWORDS 1 |
10205 | 0 | static struct { |
10206 | 0 | PyGC_Head _this_is_not_used; |
10207 | 0 | PyObject_VAR_HEAD |
10208 | 0 | Py_hash_t ob_hash; |
10209 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
10210 | 0 | } _kwtuple = { |
10211 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
10212 | 0 | .ob_hash = -1, |
10213 | 0 | .ob_item = { &_Py_ID(path), }, |
10214 | 0 | }; |
10215 | 0 | #undef NUM_KEYWORDS |
10216 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
10217 | |
|
10218 | | #else // !Py_BUILD_CORE |
10219 | | # define KWTUPLE NULL |
10220 | | #endif // !Py_BUILD_CORE |
10221 | |
|
10222 | 0 | static const char * const _keywords[] = {"path", NULL}; |
10223 | 0 | static _PyArg_Parser _parser = { |
10224 | 0 | .keywords = _keywords, |
10225 | 0 | .fname = "statvfs", |
10226 | 0 | .kwtuple = KWTUPLE, |
10227 | 0 | }; |
10228 | 0 | #undef KWTUPLE |
10229 | 0 | PyObject *argsbuf[1]; |
10230 | 0 | path_t path = PATH_T_INITIALIZE_P("statvfs", "path", 0, 0, 0, PATH_HAVE_FSTATVFS); |
10231 | |
|
10232 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
10233 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
10234 | 0 | if (!args) { |
10235 | 0 | goto exit; |
10236 | 0 | } |
10237 | 0 | if (!path_converter(args[0], &path)) { |
10238 | 0 | goto exit; |
10239 | 0 | } |
10240 | 0 | return_value = os_statvfs_impl(module, &path); |
10241 | |
|
10242 | 0 | exit: |
10243 | | /* Cleanup for path */ |
10244 | 0 | path_cleanup(&path); |
10245 | |
|
10246 | 0 | return return_value; |
10247 | 0 | } |
10248 | | |
10249 | | #endif /* (defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H)) */ |
10250 | | |
10251 | | #if defined(MS_WINDOWS) |
10252 | | |
10253 | | PyDoc_STRVAR(os__getdiskusage__doc__, |
10254 | | "_getdiskusage($module, /, path)\n" |
10255 | | "--\n" |
10256 | | "\n" |
10257 | | "Return disk usage statistics about the given path as a (total, free) tuple."); |
10258 | | |
10259 | | #define OS__GETDISKUSAGE_METHODDEF \ |
10260 | | {"_getdiskusage", _PyCFunction_CAST(os__getdiskusage), METH_FASTCALL|METH_KEYWORDS, os__getdiskusage__doc__}, |
10261 | | |
10262 | | static PyObject * |
10263 | | os__getdiskusage_impl(PyObject *module, path_t *path); |
10264 | | |
10265 | | static PyObject * |
10266 | | os__getdiskusage(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
10267 | | { |
10268 | | PyObject *return_value = NULL; |
10269 | | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
10270 | | |
10271 | | #define NUM_KEYWORDS 1 |
10272 | | static struct { |
10273 | | PyGC_Head _this_is_not_used; |
10274 | | PyObject_VAR_HEAD |
10275 | | Py_hash_t ob_hash; |
10276 | | PyObject *ob_item[NUM_KEYWORDS]; |
10277 | | } _kwtuple = { |
10278 | | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
10279 | | .ob_hash = -1, |
10280 | | .ob_item = { &_Py_ID(path), }, |
10281 | | }; |
10282 | | #undef NUM_KEYWORDS |
10283 | | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
10284 | | |
10285 | | #else // !Py_BUILD_CORE |
10286 | | # define KWTUPLE NULL |
10287 | | #endif // !Py_BUILD_CORE |
10288 | | |
10289 | | static const char * const _keywords[] = {"path", NULL}; |
10290 | | static _PyArg_Parser _parser = { |
10291 | | .keywords = _keywords, |
10292 | | .fname = "_getdiskusage", |
10293 | | .kwtuple = KWTUPLE, |
10294 | | }; |
10295 | | #undef KWTUPLE |
10296 | | PyObject *argsbuf[1]; |
10297 | | path_t path = PATH_T_INITIALIZE_P("_getdiskusage", "path", 0, 0, 0, 0); |
10298 | | |
10299 | | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
10300 | | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
10301 | | if (!args) { |
10302 | | goto exit; |
10303 | | } |
10304 | | if (!path_converter(args[0], &path)) { |
10305 | | goto exit; |
10306 | | } |
10307 | | return_value = os__getdiskusage_impl(module, &path); |
10308 | | |
10309 | | exit: |
10310 | | /* Cleanup for path */ |
10311 | | path_cleanup(&path); |
10312 | | |
10313 | | return return_value; |
10314 | | } |
10315 | | |
10316 | | #endif /* defined(MS_WINDOWS) */ |
10317 | | |
10318 | | #if defined(HAVE_FPATHCONF) |
10319 | | |
10320 | | PyDoc_STRVAR(os_fpathconf__doc__, |
10321 | | "fpathconf($module, fd, name, /)\n" |
10322 | | "--\n" |
10323 | | "\n" |
10324 | | "Return the configuration limit name for the file descriptor fd.\n" |
10325 | | "\n" |
10326 | | "If there is no limit, return -1."); |
10327 | | |
10328 | | #define OS_FPATHCONF_METHODDEF \ |
10329 | | {"fpathconf", _PyCFunction_CAST(os_fpathconf), METH_FASTCALL, os_fpathconf__doc__}, |
10330 | | |
10331 | | static long |
10332 | | os_fpathconf_impl(PyObject *module, int fd, int name); |
10333 | | |
10334 | | static PyObject * |
10335 | | os_fpathconf(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
10336 | 0 | { |
10337 | 0 | PyObject *return_value = NULL; |
10338 | 0 | int fd; |
10339 | 0 | int name; |
10340 | 0 | long _return_value; |
10341 | |
|
10342 | 0 | if (!_PyArg_CheckPositional("fpathconf", nargs, 2, 2)) { |
10343 | 0 | goto exit; |
10344 | 0 | } |
10345 | 0 | fd = PyObject_AsFileDescriptor(args[0]); |
10346 | 0 | if (fd < 0) { |
10347 | 0 | goto exit; |
10348 | 0 | } |
10349 | 0 | if (!conv_confname(module, args[1], &name, "pathconf_names")) { |
10350 | 0 | goto exit; |
10351 | 0 | } |
10352 | 0 | _return_value = os_fpathconf_impl(module, fd, name); |
10353 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
10354 | 0 | goto exit; |
10355 | 0 | } |
10356 | 0 | return_value = PyLong_FromLong(_return_value); |
10357 | |
|
10358 | 0 | exit: |
10359 | 0 | return return_value; |
10360 | 0 | } |
10361 | | |
10362 | | #endif /* defined(HAVE_FPATHCONF) */ |
10363 | | |
10364 | | #if defined(HAVE_PATHCONF) |
10365 | | |
10366 | | PyDoc_STRVAR(os_pathconf__doc__, |
10367 | | "pathconf($module, /, path, name)\n" |
10368 | | "--\n" |
10369 | | "\n" |
10370 | | "Return the configuration limit name for the file or directory path.\n" |
10371 | | "\n" |
10372 | | "If there is no limit, return -1.\n" |
10373 | | "On some platforms, path may also be specified as an open file descriptor.\n" |
10374 | | " If this functionality is unavailable, using it raises an exception."); |
10375 | | |
10376 | | #define OS_PATHCONF_METHODDEF \ |
10377 | | {"pathconf", _PyCFunction_CAST(os_pathconf), METH_FASTCALL|METH_KEYWORDS, os_pathconf__doc__}, |
10378 | | |
10379 | | static long |
10380 | | os_pathconf_impl(PyObject *module, path_t *path, int name); |
10381 | | |
10382 | | static PyObject * |
10383 | | os_pathconf(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
10384 | 0 | { |
10385 | 0 | PyObject *return_value = NULL; |
10386 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
10387 | |
|
10388 | 0 | #define NUM_KEYWORDS 2 |
10389 | 0 | static struct { |
10390 | 0 | PyGC_Head _this_is_not_used; |
10391 | 0 | PyObject_VAR_HEAD |
10392 | 0 | Py_hash_t ob_hash; |
10393 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
10394 | 0 | } _kwtuple = { |
10395 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
10396 | 0 | .ob_hash = -1, |
10397 | 0 | .ob_item = { &_Py_ID(path), &_Py_ID(name), }, |
10398 | 0 | }; |
10399 | 0 | #undef NUM_KEYWORDS |
10400 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
10401 | |
|
10402 | | #else // !Py_BUILD_CORE |
10403 | | # define KWTUPLE NULL |
10404 | | #endif // !Py_BUILD_CORE |
10405 | |
|
10406 | 0 | static const char * const _keywords[] = {"path", "name", NULL}; |
10407 | 0 | static _PyArg_Parser _parser = { |
10408 | 0 | .keywords = _keywords, |
10409 | 0 | .fname = "pathconf", |
10410 | 0 | .kwtuple = KWTUPLE, |
10411 | 0 | }; |
10412 | 0 | #undef KWTUPLE |
10413 | 0 | PyObject *argsbuf[2]; |
10414 | 0 | path_t path = PATH_T_INITIALIZE_P("pathconf", "path", 0, 0, 0, PATH_HAVE_FPATHCONF); |
10415 | 0 | int name; |
10416 | 0 | long _return_value; |
10417 | |
|
10418 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
10419 | 0 | /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
10420 | 0 | if (!args) { |
10421 | 0 | goto exit; |
10422 | 0 | } |
10423 | 0 | if (!path_converter(args[0], &path)) { |
10424 | 0 | goto exit; |
10425 | 0 | } |
10426 | 0 | if (!conv_confname(module, args[1], &name, "pathconf_names")) { |
10427 | 0 | goto exit; |
10428 | 0 | } |
10429 | 0 | _return_value = os_pathconf_impl(module, &path, name); |
10430 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
10431 | 0 | goto exit; |
10432 | 0 | } |
10433 | 0 | return_value = PyLong_FromLong(_return_value); |
10434 | |
|
10435 | 0 | exit: |
10436 | | /* Cleanup for path */ |
10437 | 0 | path_cleanup(&path); |
10438 | |
|
10439 | 0 | return return_value; |
10440 | 0 | } |
10441 | | |
10442 | | #endif /* defined(HAVE_PATHCONF) */ |
10443 | | |
10444 | | #if defined(HAVE_CONFSTR) |
10445 | | |
10446 | | PyDoc_STRVAR(os_confstr__doc__, |
10447 | | "confstr($module, name, /)\n" |
10448 | | "--\n" |
10449 | | "\n" |
10450 | | "Return a string-valued system configuration variable."); |
10451 | | |
10452 | | #define OS_CONFSTR_METHODDEF \ |
10453 | | {"confstr", (PyCFunction)os_confstr, METH_O, os_confstr__doc__}, |
10454 | | |
10455 | | static PyObject * |
10456 | | os_confstr_impl(PyObject *module, int name); |
10457 | | |
10458 | | static PyObject * |
10459 | | os_confstr(PyObject *module, PyObject *arg) |
10460 | 0 | { |
10461 | 0 | PyObject *return_value = NULL; |
10462 | 0 | int name; |
10463 | |
|
10464 | 0 | if (!conv_confname(module, arg, &name, "confstr_names")) { |
10465 | 0 | goto exit; |
10466 | 0 | } |
10467 | 0 | return_value = os_confstr_impl(module, name); |
10468 | |
|
10469 | 0 | exit: |
10470 | 0 | return return_value; |
10471 | 0 | } |
10472 | | |
10473 | | #endif /* defined(HAVE_CONFSTR) */ |
10474 | | |
10475 | | #if defined(HAVE_SYSCONF) |
10476 | | |
10477 | | PyDoc_STRVAR(os_sysconf__doc__, |
10478 | | "sysconf($module, name, /)\n" |
10479 | | "--\n" |
10480 | | "\n" |
10481 | | "Return an integer-valued system configuration variable."); |
10482 | | |
10483 | | #define OS_SYSCONF_METHODDEF \ |
10484 | | {"sysconf", (PyCFunction)os_sysconf, METH_O, os_sysconf__doc__}, |
10485 | | |
10486 | | static long |
10487 | | os_sysconf_impl(PyObject *module, int name); |
10488 | | |
10489 | | static PyObject * |
10490 | | os_sysconf(PyObject *module, PyObject *arg) |
10491 | 0 | { |
10492 | 0 | PyObject *return_value = NULL; |
10493 | 0 | int name; |
10494 | 0 | long _return_value; |
10495 | |
|
10496 | 0 | if (!conv_confname(module, arg, &name, "sysconf_names")) { |
10497 | 0 | goto exit; |
10498 | 0 | } |
10499 | 0 | _return_value = os_sysconf_impl(module, name); |
10500 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
10501 | 0 | goto exit; |
10502 | 0 | } |
10503 | 0 | return_value = PyLong_FromLong(_return_value); |
10504 | |
|
10505 | 0 | exit: |
10506 | 0 | return return_value; |
10507 | 0 | } |
10508 | | |
10509 | | #endif /* defined(HAVE_SYSCONF) */ |
10510 | | |
10511 | | PyDoc_STRVAR(os_abort__doc__, |
10512 | | "abort($module, /)\n" |
10513 | | "--\n" |
10514 | | "\n" |
10515 | | "Abort the interpreter immediately.\n" |
10516 | | "\n" |
10517 | | "This function \'dumps core\' or otherwise fails in the hardest way possible\n" |
10518 | | "on the hosting operating system. This function never returns."); |
10519 | | |
10520 | | #define OS_ABORT_METHODDEF \ |
10521 | | {"abort", (PyCFunction)os_abort, METH_NOARGS, os_abort__doc__}, |
10522 | | |
10523 | | static PyObject * |
10524 | | os_abort_impl(PyObject *module); |
10525 | | |
10526 | | static PyObject * |
10527 | | os_abort(PyObject *module, PyObject *Py_UNUSED(ignored)) |
10528 | 0 | { |
10529 | 0 | return os_abort_impl(module); |
10530 | 0 | } |
10531 | | |
10532 | | #if defined(MS_WINDOWS) |
10533 | | |
10534 | | PyDoc_STRVAR(os_startfile__doc__, |
10535 | | "startfile($module, /, filepath, operation=<unrepresentable>,\n" |
10536 | | " arguments=<unrepresentable>, cwd=None, show_cmd=1)\n" |
10537 | | "--\n" |
10538 | | "\n" |
10539 | | "Start a file with its associated application.\n" |
10540 | | "\n" |
10541 | | "When \"operation\" is not specified or \"open\", this acts like\n" |
10542 | | "double-clicking the file in Explorer, or giving the file name as an\n" |
10543 | | "argument to the DOS \"start\" command: the file is opened with whatever\n" |
10544 | | "application (if any) its extension is associated.\n" |
10545 | | "When another \"operation\" is given, it specifies what should be done with\n" |
10546 | | "the file. A typical operation is \"print\".\n" |
10547 | | "\n" |
10548 | | "\"arguments\" is passed to the application, but should be omitted if the\n" |
10549 | | "file is a document.\n" |
10550 | | "\n" |
10551 | | "\"cwd\" is the working directory for the operation. If \"filepath\" is\n" |
10552 | | "relative, it will be resolved against this directory. This argument\n" |
10553 | | "should usually be an absolute path.\n" |
10554 | | "\n" |
10555 | | "\"show_cmd\" can be used to override the recommended visibility option.\n" |
10556 | | "See the Windows ShellExecute documentation for values.\n" |
10557 | | "\n" |
10558 | | "startfile returns as soon as the associated application is launched.\n" |
10559 | | "There is no option to wait for the application to close, and no way\n" |
10560 | | "to retrieve the application\'s exit status.\n" |
10561 | | "\n" |
10562 | | "The filepath is relative to the current directory. If you want to use\n" |
10563 | | "an absolute path, make sure the first character is not a slash (\"/\");\n" |
10564 | | "the underlying Win32 ShellExecute function doesn\'t work if it is."); |
10565 | | |
10566 | | #define OS_STARTFILE_METHODDEF \ |
10567 | | {"startfile", _PyCFunction_CAST(os_startfile), METH_FASTCALL|METH_KEYWORDS, os_startfile__doc__}, |
10568 | | |
10569 | | static PyObject * |
10570 | | os_startfile_impl(PyObject *module, path_t *filepath, |
10571 | | const wchar_t *operation, const wchar_t *arguments, |
10572 | | path_t *cwd, int show_cmd); |
10573 | | |
10574 | | static PyObject * |
10575 | | os_startfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
10576 | | { |
10577 | | PyObject *return_value = NULL; |
10578 | | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
10579 | | |
10580 | | #define NUM_KEYWORDS 5 |
10581 | | static struct { |
10582 | | PyGC_Head _this_is_not_used; |
10583 | | PyObject_VAR_HEAD |
10584 | | Py_hash_t ob_hash; |
10585 | | PyObject *ob_item[NUM_KEYWORDS]; |
10586 | | } _kwtuple = { |
10587 | | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
10588 | | .ob_hash = -1, |
10589 | | .ob_item = { &_Py_ID(filepath), &_Py_ID(operation), &_Py_ID(arguments), &_Py_ID(cwd), &_Py_ID(show_cmd), }, |
10590 | | }; |
10591 | | #undef NUM_KEYWORDS |
10592 | | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
10593 | | |
10594 | | #else // !Py_BUILD_CORE |
10595 | | # define KWTUPLE NULL |
10596 | | #endif // !Py_BUILD_CORE |
10597 | | |
10598 | | static const char * const _keywords[] = {"filepath", "operation", "arguments", "cwd", "show_cmd", NULL}; |
10599 | | static _PyArg_Parser _parser = { |
10600 | | .keywords = _keywords, |
10601 | | .fname = "startfile", |
10602 | | .kwtuple = KWTUPLE, |
10603 | | }; |
10604 | | #undef KWTUPLE |
10605 | | PyObject *argsbuf[5]; |
10606 | | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
10607 | | path_t filepath = PATH_T_INITIALIZE_P("startfile", "filepath", 0, 0, 0, 0); |
10608 | | const wchar_t *operation = NULL; |
10609 | | const wchar_t *arguments = NULL; |
10610 | | path_t cwd = PATH_T_INITIALIZE_P("startfile", "cwd", 1, 0, 0, 0); |
10611 | | int show_cmd = 1; |
10612 | | |
10613 | | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
10614 | | /*minpos*/ 1, /*maxpos*/ 5, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
10615 | | if (!args) { |
10616 | | goto exit; |
10617 | | } |
10618 | | if (!path_converter(args[0], &filepath)) { |
10619 | | goto exit; |
10620 | | } |
10621 | | if (!noptargs) { |
10622 | | goto skip_optional_pos; |
10623 | | } |
10624 | | if (args[1]) { |
10625 | | if (!PyUnicode_Check(args[1])) { |
10626 | | _PyArg_BadArgument("startfile", "argument 'operation'", "str", args[1]); |
10627 | | goto exit; |
10628 | | } |
10629 | | operation = PyUnicode_AsWideCharString(args[1], NULL); |
10630 | | if (operation == NULL) { |
10631 | | goto exit; |
10632 | | } |
10633 | | if (!--noptargs) { |
10634 | | goto skip_optional_pos; |
10635 | | } |
10636 | | } |
10637 | | if (args[2]) { |
10638 | | if (!PyUnicode_Check(args[2])) { |
10639 | | _PyArg_BadArgument("startfile", "argument 'arguments'", "str", args[2]); |
10640 | | goto exit; |
10641 | | } |
10642 | | arguments = PyUnicode_AsWideCharString(args[2], NULL); |
10643 | | if (arguments == NULL) { |
10644 | | goto exit; |
10645 | | } |
10646 | | if (!--noptargs) { |
10647 | | goto skip_optional_pos; |
10648 | | } |
10649 | | } |
10650 | | if (args[3]) { |
10651 | | if (!path_converter(args[3], &cwd)) { |
10652 | | goto exit; |
10653 | | } |
10654 | | if (!--noptargs) { |
10655 | | goto skip_optional_pos; |
10656 | | } |
10657 | | } |
10658 | | show_cmd = PyLong_AsInt(args[4]); |
10659 | | if (show_cmd == -1 && PyErr_Occurred()) { |
10660 | | goto exit; |
10661 | | } |
10662 | | skip_optional_pos: |
10663 | | return_value = os_startfile_impl(module, &filepath, operation, arguments, &cwd, show_cmd); |
10664 | | |
10665 | | exit: |
10666 | | /* Cleanup for filepath */ |
10667 | | path_cleanup(&filepath); |
10668 | | /* Cleanup for operation */ |
10669 | | PyMem_Free((void *)operation); |
10670 | | /* Cleanup for arguments */ |
10671 | | PyMem_Free((void *)arguments); |
10672 | | /* Cleanup for cwd */ |
10673 | | path_cleanup(&cwd); |
10674 | | |
10675 | | return return_value; |
10676 | | } |
10677 | | |
10678 | | #endif /* defined(MS_WINDOWS) */ |
10679 | | |
10680 | | #if defined(HAVE_GETLOADAVG) |
10681 | | |
10682 | | PyDoc_STRVAR(os_getloadavg__doc__, |
10683 | | "getloadavg($module, /)\n" |
10684 | | "--\n" |
10685 | | "\n" |
10686 | | "Return average recent system load information.\n" |
10687 | | "\n" |
10688 | | "Return the number of processes in the system run queue averaged over\n" |
10689 | | "the last 1, 5, and 15 minutes as a tuple of three floats.\n" |
10690 | | "Raises OSError if the load average was unobtainable."); |
10691 | | |
10692 | | #define OS_GETLOADAVG_METHODDEF \ |
10693 | | {"getloadavg", (PyCFunction)os_getloadavg, METH_NOARGS, os_getloadavg__doc__}, |
10694 | | |
10695 | | static PyObject * |
10696 | | os_getloadavg_impl(PyObject *module); |
10697 | | |
10698 | | static PyObject * |
10699 | | os_getloadavg(PyObject *module, PyObject *Py_UNUSED(ignored)) |
10700 | 0 | { |
10701 | 0 | return os_getloadavg_impl(module); |
10702 | 0 | } |
10703 | | |
10704 | | #endif /* defined(HAVE_GETLOADAVG) */ |
10705 | | |
10706 | | PyDoc_STRVAR(os_device_encoding__doc__, |
10707 | | "device_encoding($module, /, fd)\n" |
10708 | | "--\n" |
10709 | | "\n" |
10710 | | "Return a string describing the encoding of a terminal\'s file descriptor.\n" |
10711 | | "\n" |
10712 | | "The file descriptor must be attached to a terminal.\n" |
10713 | | "If the device is not a terminal, return None."); |
10714 | | |
10715 | | #define OS_DEVICE_ENCODING_METHODDEF \ |
10716 | | {"device_encoding", _PyCFunction_CAST(os_device_encoding), METH_FASTCALL|METH_KEYWORDS, os_device_encoding__doc__}, |
10717 | | |
10718 | | static PyObject * |
10719 | | os_device_encoding_impl(PyObject *module, int fd); |
10720 | | |
10721 | | static PyObject * |
10722 | | os_device_encoding(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
10723 | 0 | { |
10724 | 0 | PyObject *return_value = NULL; |
10725 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
10726 | |
|
10727 | 0 | #define NUM_KEYWORDS 1 |
10728 | 0 | static struct { |
10729 | 0 | PyGC_Head _this_is_not_used; |
10730 | 0 | PyObject_VAR_HEAD |
10731 | 0 | Py_hash_t ob_hash; |
10732 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
10733 | 0 | } _kwtuple = { |
10734 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
10735 | 0 | .ob_hash = -1, |
10736 | 0 | .ob_item = { &_Py_ID(fd), }, |
10737 | 0 | }; |
10738 | 0 | #undef NUM_KEYWORDS |
10739 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
10740 | |
|
10741 | | #else // !Py_BUILD_CORE |
10742 | | # define KWTUPLE NULL |
10743 | | #endif // !Py_BUILD_CORE |
10744 | |
|
10745 | 0 | static const char * const _keywords[] = {"fd", NULL}; |
10746 | 0 | static _PyArg_Parser _parser = { |
10747 | 0 | .keywords = _keywords, |
10748 | 0 | .fname = "device_encoding", |
10749 | 0 | .kwtuple = KWTUPLE, |
10750 | 0 | }; |
10751 | 0 | #undef KWTUPLE |
10752 | 0 | PyObject *argsbuf[1]; |
10753 | 0 | int fd; |
10754 | |
|
10755 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
10756 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
10757 | 0 | if (!args) { |
10758 | 0 | goto exit; |
10759 | 0 | } |
10760 | 0 | fd = PyLong_AsInt(args[0]); |
10761 | 0 | if (fd == -1 && PyErr_Occurred()) { |
10762 | 0 | goto exit; |
10763 | 0 | } |
10764 | 0 | return_value = os_device_encoding_impl(module, fd); |
10765 | |
|
10766 | 0 | exit: |
10767 | 0 | return return_value; |
10768 | 0 | } |
10769 | | |
10770 | | #if defined(HAVE_SETRESUID) |
10771 | | |
10772 | | PyDoc_STRVAR(os_setresuid__doc__, |
10773 | | "setresuid($module, ruid, euid, suid, /)\n" |
10774 | | "--\n" |
10775 | | "\n" |
10776 | | "Set the current process\'s real, effective, and saved user ids."); |
10777 | | |
10778 | | #define OS_SETRESUID_METHODDEF \ |
10779 | | {"setresuid", _PyCFunction_CAST(os_setresuid), METH_FASTCALL, os_setresuid__doc__}, |
10780 | | |
10781 | | static PyObject * |
10782 | | os_setresuid_impl(PyObject *module, uid_t ruid, uid_t euid, uid_t suid); |
10783 | | |
10784 | | static PyObject * |
10785 | | os_setresuid(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
10786 | 0 | { |
10787 | 0 | PyObject *return_value = NULL; |
10788 | 0 | uid_t ruid; |
10789 | 0 | uid_t euid; |
10790 | 0 | uid_t suid; |
10791 | |
|
10792 | 0 | if (!_PyArg_CheckPositional("setresuid", nargs, 3, 3)) { |
10793 | 0 | goto exit; |
10794 | 0 | } |
10795 | 0 | if (!_Py_Uid_Converter(args[0], &ruid)) { |
10796 | 0 | goto exit; |
10797 | 0 | } |
10798 | 0 | if (!_Py_Uid_Converter(args[1], &euid)) { |
10799 | 0 | goto exit; |
10800 | 0 | } |
10801 | 0 | if (!_Py_Uid_Converter(args[2], &suid)) { |
10802 | 0 | goto exit; |
10803 | 0 | } |
10804 | 0 | return_value = os_setresuid_impl(module, ruid, euid, suid); |
10805 | |
|
10806 | 0 | exit: |
10807 | 0 | return return_value; |
10808 | 0 | } |
10809 | | |
10810 | | #endif /* defined(HAVE_SETRESUID) */ |
10811 | | |
10812 | | #if defined(HAVE_SETRESGID) |
10813 | | |
10814 | | PyDoc_STRVAR(os_setresgid__doc__, |
10815 | | "setresgid($module, rgid, egid, sgid, /)\n" |
10816 | | "--\n" |
10817 | | "\n" |
10818 | | "Set the current process\'s real, effective, and saved group ids."); |
10819 | | |
10820 | | #define OS_SETRESGID_METHODDEF \ |
10821 | | {"setresgid", _PyCFunction_CAST(os_setresgid), METH_FASTCALL, os_setresgid__doc__}, |
10822 | | |
10823 | | static PyObject * |
10824 | | os_setresgid_impl(PyObject *module, gid_t rgid, gid_t egid, gid_t sgid); |
10825 | | |
10826 | | static PyObject * |
10827 | | os_setresgid(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
10828 | 0 | { |
10829 | 0 | PyObject *return_value = NULL; |
10830 | 0 | gid_t rgid; |
10831 | 0 | gid_t egid; |
10832 | 0 | gid_t sgid; |
10833 | |
|
10834 | 0 | if (!_PyArg_CheckPositional("setresgid", nargs, 3, 3)) { |
10835 | 0 | goto exit; |
10836 | 0 | } |
10837 | 0 | if (!_Py_Gid_Converter(args[0], &rgid)) { |
10838 | 0 | goto exit; |
10839 | 0 | } |
10840 | 0 | if (!_Py_Gid_Converter(args[1], &egid)) { |
10841 | 0 | goto exit; |
10842 | 0 | } |
10843 | 0 | if (!_Py_Gid_Converter(args[2], &sgid)) { |
10844 | 0 | goto exit; |
10845 | 0 | } |
10846 | 0 | return_value = os_setresgid_impl(module, rgid, egid, sgid); |
10847 | |
|
10848 | 0 | exit: |
10849 | 0 | return return_value; |
10850 | 0 | } |
10851 | | |
10852 | | #endif /* defined(HAVE_SETRESGID) */ |
10853 | | |
10854 | | #if defined(HAVE_GETRESUID) |
10855 | | |
10856 | | PyDoc_STRVAR(os_getresuid__doc__, |
10857 | | "getresuid($module, /)\n" |
10858 | | "--\n" |
10859 | | "\n" |
10860 | | "Return a tuple of the current process\'s real, effective, and saved user ids."); |
10861 | | |
10862 | | #define OS_GETRESUID_METHODDEF \ |
10863 | | {"getresuid", (PyCFunction)os_getresuid, METH_NOARGS, os_getresuid__doc__}, |
10864 | | |
10865 | | static PyObject * |
10866 | | os_getresuid_impl(PyObject *module); |
10867 | | |
10868 | | static PyObject * |
10869 | | os_getresuid(PyObject *module, PyObject *Py_UNUSED(ignored)) |
10870 | 0 | { |
10871 | 0 | return os_getresuid_impl(module); |
10872 | 0 | } |
10873 | | |
10874 | | #endif /* defined(HAVE_GETRESUID) */ |
10875 | | |
10876 | | #if defined(HAVE_GETRESGID) |
10877 | | |
10878 | | PyDoc_STRVAR(os_getresgid__doc__, |
10879 | | "getresgid($module, /)\n" |
10880 | | "--\n" |
10881 | | "\n" |
10882 | | "Return a tuple of the current process\'s real, effective, and saved group ids."); |
10883 | | |
10884 | | #define OS_GETRESGID_METHODDEF \ |
10885 | | {"getresgid", (PyCFunction)os_getresgid, METH_NOARGS, os_getresgid__doc__}, |
10886 | | |
10887 | | static PyObject * |
10888 | | os_getresgid_impl(PyObject *module); |
10889 | | |
10890 | | static PyObject * |
10891 | | os_getresgid(PyObject *module, PyObject *Py_UNUSED(ignored)) |
10892 | 0 | { |
10893 | 0 | return os_getresgid_impl(module); |
10894 | 0 | } |
10895 | | |
10896 | | #endif /* defined(HAVE_GETRESGID) */ |
10897 | | |
10898 | | #if defined(USE_XATTRS) |
10899 | | |
10900 | | PyDoc_STRVAR(os_getxattr__doc__, |
10901 | | "getxattr($module, /, path, attribute, *, follow_symlinks=True)\n" |
10902 | | "--\n" |
10903 | | "\n" |
10904 | | "Return the value of extended attribute attribute on path.\n" |
10905 | | "\n" |
10906 | | "path may be either a string, a path-like object, or an open file descriptor.\n" |
10907 | | "If follow_symlinks is False, and the last element of the path is a symbolic\n" |
10908 | | " link, getxattr will examine the symbolic link itself instead of the file\n" |
10909 | | " the link points to."); |
10910 | | |
10911 | | #define OS_GETXATTR_METHODDEF \ |
10912 | | {"getxattr", _PyCFunction_CAST(os_getxattr), METH_FASTCALL|METH_KEYWORDS, os_getxattr__doc__}, |
10913 | | |
10914 | | static PyObject * |
10915 | | os_getxattr_impl(PyObject *module, path_t *path, path_t *attribute, |
10916 | | int follow_symlinks); |
10917 | | |
10918 | | static PyObject * |
10919 | | os_getxattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
10920 | 0 | { |
10921 | 0 | PyObject *return_value = NULL; |
10922 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
10923 | |
|
10924 | 0 | #define NUM_KEYWORDS 3 |
10925 | 0 | static struct { |
10926 | 0 | PyGC_Head _this_is_not_used; |
10927 | 0 | PyObject_VAR_HEAD |
10928 | 0 | Py_hash_t ob_hash; |
10929 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
10930 | 0 | } _kwtuple = { |
10931 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
10932 | 0 | .ob_hash = -1, |
10933 | 0 | .ob_item = { &_Py_ID(path), &_Py_ID(attribute), &_Py_ID(follow_symlinks), }, |
10934 | 0 | }; |
10935 | 0 | #undef NUM_KEYWORDS |
10936 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
10937 | |
|
10938 | | #else // !Py_BUILD_CORE |
10939 | | # define KWTUPLE NULL |
10940 | | #endif // !Py_BUILD_CORE |
10941 | |
|
10942 | 0 | static const char * const _keywords[] = {"path", "attribute", "follow_symlinks", NULL}; |
10943 | 0 | static _PyArg_Parser _parser = { |
10944 | 0 | .keywords = _keywords, |
10945 | 0 | .fname = "getxattr", |
10946 | 0 | .kwtuple = KWTUPLE, |
10947 | 0 | }; |
10948 | 0 | #undef KWTUPLE |
10949 | 0 | PyObject *argsbuf[3]; |
10950 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2; |
10951 | 0 | path_t path = PATH_T_INITIALIZE_P("getxattr", "path", 0, 0, 0, 1); |
10952 | 0 | path_t attribute = PATH_T_INITIALIZE_P("getxattr", "attribute", 0, 0, 0, 0); |
10953 | 0 | int follow_symlinks = 1; |
10954 | |
|
10955 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
10956 | 0 | /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
10957 | 0 | if (!args) { |
10958 | 0 | goto exit; |
10959 | 0 | } |
10960 | 0 | if (!path_converter(args[0], &path)) { |
10961 | 0 | goto exit; |
10962 | 0 | } |
10963 | 0 | if (!path_converter(args[1], &attribute)) { |
10964 | 0 | goto exit; |
10965 | 0 | } |
10966 | 0 | if (!noptargs) { |
10967 | 0 | goto skip_optional_kwonly; |
10968 | 0 | } |
10969 | 0 | follow_symlinks = PyObject_IsTrue(args[2]); |
10970 | 0 | if (follow_symlinks < 0) { |
10971 | 0 | goto exit; |
10972 | 0 | } |
10973 | 0 | skip_optional_kwonly: |
10974 | 0 | return_value = os_getxattr_impl(module, &path, &attribute, follow_symlinks); |
10975 | |
|
10976 | 0 | exit: |
10977 | | /* Cleanup for path */ |
10978 | 0 | path_cleanup(&path); |
10979 | | /* Cleanup for attribute */ |
10980 | 0 | path_cleanup(&attribute); |
10981 | |
|
10982 | 0 | return return_value; |
10983 | 0 | } |
10984 | | |
10985 | | #endif /* defined(USE_XATTRS) */ |
10986 | | |
10987 | | #if defined(USE_XATTRS) |
10988 | | |
10989 | | PyDoc_STRVAR(os_setxattr__doc__, |
10990 | | "setxattr($module, /, path, attribute, value, flags=0, *,\n" |
10991 | | " follow_symlinks=True)\n" |
10992 | | "--\n" |
10993 | | "\n" |
10994 | | "Set extended attribute attribute on path to value.\n" |
10995 | | "\n" |
10996 | | "path may be either a string, a path-like object, or an open file descriptor.\n" |
10997 | | "If follow_symlinks is False, and the last element of the path is a symbolic\n" |
10998 | | " link, setxattr will modify the symbolic link itself instead of the file\n" |
10999 | | " the link points to."); |
11000 | | |
11001 | | #define OS_SETXATTR_METHODDEF \ |
11002 | | {"setxattr", _PyCFunction_CAST(os_setxattr), METH_FASTCALL|METH_KEYWORDS, os_setxattr__doc__}, |
11003 | | |
11004 | | static PyObject * |
11005 | | os_setxattr_impl(PyObject *module, path_t *path, path_t *attribute, |
11006 | | Py_buffer *value, int flags, int follow_symlinks); |
11007 | | |
11008 | | static PyObject * |
11009 | | os_setxattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
11010 | 0 | { |
11011 | 0 | PyObject *return_value = NULL; |
11012 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
11013 | |
|
11014 | 0 | #define NUM_KEYWORDS 5 |
11015 | 0 | static struct { |
11016 | 0 | PyGC_Head _this_is_not_used; |
11017 | 0 | PyObject_VAR_HEAD |
11018 | 0 | Py_hash_t ob_hash; |
11019 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
11020 | 0 | } _kwtuple = { |
11021 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
11022 | 0 | .ob_hash = -1, |
11023 | 0 | .ob_item = { &_Py_ID(path), &_Py_ID(attribute), &_Py_ID(value), &_Py_ID(flags), &_Py_ID(follow_symlinks), }, |
11024 | 0 | }; |
11025 | 0 | #undef NUM_KEYWORDS |
11026 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
11027 | |
|
11028 | | #else // !Py_BUILD_CORE |
11029 | | # define KWTUPLE NULL |
11030 | | #endif // !Py_BUILD_CORE |
11031 | |
|
11032 | 0 | static const char * const _keywords[] = {"path", "attribute", "value", "flags", "follow_symlinks", NULL}; |
11033 | 0 | static _PyArg_Parser _parser = { |
11034 | 0 | .keywords = _keywords, |
11035 | 0 | .fname = "setxattr", |
11036 | 0 | .kwtuple = KWTUPLE, |
11037 | 0 | }; |
11038 | 0 | #undef KWTUPLE |
11039 | 0 | PyObject *argsbuf[5]; |
11040 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3; |
11041 | 0 | path_t path = PATH_T_INITIALIZE_P("setxattr", "path", 0, 0, 0, 1); |
11042 | 0 | path_t attribute = PATH_T_INITIALIZE_P("setxattr", "attribute", 0, 0, 0, 0); |
11043 | 0 | Py_buffer value = {NULL, NULL}; |
11044 | 0 | int flags = 0; |
11045 | 0 | int follow_symlinks = 1; |
11046 | |
|
11047 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
11048 | 0 | /*minpos*/ 3, /*maxpos*/ 4, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
11049 | 0 | if (!args) { |
11050 | 0 | goto exit; |
11051 | 0 | } |
11052 | 0 | if (!path_converter(args[0], &path)) { |
11053 | 0 | goto exit; |
11054 | 0 | } |
11055 | 0 | if (!path_converter(args[1], &attribute)) { |
11056 | 0 | goto exit; |
11057 | 0 | } |
11058 | 0 | if (PyObject_GetBuffer(args[2], &value, PyBUF_SIMPLE) != 0) { |
11059 | 0 | goto exit; |
11060 | 0 | } |
11061 | 0 | if (!noptargs) { |
11062 | 0 | goto skip_optional_pos; |
11063 | 0 | } |
11064 | 0 | if (args[3]) { |
11065 | 0 | flags = PyLong_AsInt(args[3]); |
11066 | 0 | if (flags == -1 && PyErr_Occurred()) { |
11067 | 0 | goto exit; |
11068 | 0 | } |
11069 | 0 | if (!--noptargs) { |
11070 | 0 | goto skip_optional_pos; |
11071 | 0 | } |
11072 | 0 | } |
11073 | 0 | skip_optional_pos: |
11074 | 0 | if (!noptargs) { |
11075 | 0 | goto skip_optional_kwonly; |
11076 | 0 | } |
11077 | 0 | follow_symlinks = PyObject_IsTrue(args[4]); |
11078 | 0 | if (follow_symlinks < 0) { |
11079 | 0 | goto exit; |
11080 | 0 | } |
11081 | 0 | skip_optional_kwonly: |
11082 | 0 | return_value = os_setxattr_impl(module, &path, &attribute, &value, flags, follow_symlinks); |
11083 | |
|
11084 | 0 | exit: |
11085 | | /* Cleanup for path */ |
11086 | 0 | path_cleanup(&path); |
11087 | | /* Cleanup for attribute */ |
11088 | 0 | path_cleanup(&attribute); |
11089 | | /* Cleanup for value */ |
11090 | 0 | if (value.obj) { |
11091 | 0 | PyBuffer_Release(&value); |
11092 | 0 | } |
11093 | |
|
11094 | 0 | return return_value; |
11095 | 0 | } |
11096 | | |
11097 | | #endif /* defined(USE_XATTRS) */ |
11098 | | |
11099 | | #if defined(USE_XATTRS) |
11100 | | |
11101 | | PyDoc_STRVAR(os_removexattr__doc__, |
11102 | | "removexattr($module, /, path, attribute, *, follow_symlinks=True)\n" |
11103 | | "--\n" |
11104 | | "\n" |
11105 | | "Remove extended attribute attribute on path.\n" |
11106 | | "\n" |
11107 | | "path may be either a string, a path-like object, or an open file descriptor.\n" |
11108 | | "If follow_symlinks is False, and the last element of the path is a symbolic\n" |
11109 | | " link, removexattr will modify the symbolic link itself instead of the file\n" |
11110 | | " the link points to."); |
11111 | | |
11112 | | #define OS_REMOVEXATTR_METHODDEF \ |
11113 | | {"removexattr", _PyCFunction_CAST(os_removexattr), METH_FASTCALL|METH_KEYWORDS, os_removexattr__doc__}, |
11114 | | |
11115 | | static PyObject * |
11116 | | os_removexattr_impl(PyObject *module, path_t *path, path_t *attribute, |
11117 | | int follow_symlinks); |
11118 | | |
11119 | | static PyObject * |
11120 | | os_removexattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
11121 | 0 | { |
11122 | 0 | PyObject *return_value = NULL; |
11123 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
11124 | |
|
11125 | 0 | #define NUM_KEYWORDS 3 |
11126 | 0 | static struct { |
11127 | 0 | PyGC_Head _this_is_not_used; |
11128 | 0 | PyObject_VAR_HEAD |
11129 | 0 | Py_hash_t ob_hash; |
11130 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
11131 | 0 | } _kwtuple = { |
11132 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
11133 | 0 | .ob_hash = -1, |
11134 | 0 | .ob_item = { &_Py_ID(path), &_Py_ID(attribute), &_Py_ID(follow_symlinks), }, |
11135 | 0 | }; |
11136 | 0 | #undef NUM_KEYWORDS |
11137 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
11138 | |
|
11139 | | #else // !Py_BUILD_CORE |
11140 | | # define KWTUPLE NULL |
11141 | | #endif // !Py_BUILD_CORE |
11142 | |
|
11143 | 0 | static const char * const _keywords[] = {"path", "attribute", "follow_symlinks", NULL}; |
11144 | 0 | static _PyArg_Parser _parser = { |
11145 | 0 | .keywords = _keywords, |
11146 | 0 | .fname = "removexattr", |
11147 | 0 | .kwtuple = KWTUPLE, |
11148 | 0 | }; |
11149 | 0 | #undef KWTUPLE |
11150 | 0 | PyObject *argsbuf[3]; |
11151 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2; |
11152 | 0 | path_t path = PATH_T_INITIALIZE_P("removexattr", "path", 0, 0, 0, 1); |
11153 | 0 | path_t attribute = PATH_T_INITIALIZE_P("removexattr", "attribute", 0, 0, 0, 0); |
11154 | 0 | int follow_symlinks = 1; |
11155 | |
|
11156 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
11157 | 0 | /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
11158 | 0 | if (!args) { |
11159 | 0 | goto exit; |
11160 | 0 | } |
11161 | 0 | if (!path_converter(args[0], &path)) { |
11162 | 0 | goto exit; |
11163 | 0 | } |
11164 | 0 | if (!path_converter(args[1], &attribute)) { |
11165 | 0 | goto exit; |
11166 | 0 | } |
11167 | 0 | if (!noptargs) { |
11168 | 0 | goto skip_optional_kwonly; |
11169 | 0 | } |
11170 | 0 | follow_symlinks = PyObject_IsTrue(args[2]); |
11171 | 0 | if (follow_symlinks < 0) { |
11172 | 0 | goto exit; |
11173 | 0 | } |
11174 | 0 | skip_optional_kwonly: |
11175 | 0 | return_value = os_removexattr_impl(module, &path, &attribute, follow_symlinks); |
11176 | |
|
11177 | 0 | exit: |
11178 | | /* Cleanup for path */ |
11179 | 0 | path_cleanup(&path); |
11180 | | /* Cleanup for attribute */ |
11181 | 0 | path_cleanup(&attribute); |
11182 | |
|
11183 | 0 | return return_value; |
11184 | 0 | } |
11185 | | |
11186 | | #endif /* defined(USE_XATTRS) */ |
11187 | | |
11188 | | #if defined(USE_XATTRS) |
11189 | | |
11190 | | PyDoc_STRVAR(os_listxattr__doc__, |
11191 | | "listxattr($module, /, path=None, *, follow_symlinks=True)\n" |
11192 | | "--\n" |
11193 | | "\n" |
11194 | | "Return a list of extended attributes on path.\n" |
11195 | | "\n" |
11196 | | "path may be either None, a string, a path-like object, or an open file descriptor.\n" |
11197 | | "if path is None, listxattr will examine the current directory.\n" |
11198 | | "If follow_symlinks is False, and the last element of the path is a symbolic\n" |
11199 | | " link, listxattr will examine the symbolic link itself instead of the file\n" |
11200 | | " the link points to."); |
11201 | | |
11202 | | #define OS_LISTXATTR_METHODDEF \ |
11203 | | {"listxattr", _PyCFunction_CAST(os_listxattr), METH_FASTCALL|METH_KEYWORDS, os_listxattr__doc__}, |
11204 | | |
11205 | | static PyObject * |
11206 | | os_listxattr_impl(PyObject *module, path_t *path, int follow_symlinks); |
11207 | | |
11208 | | static PyObject * |
11209 | | os_listxattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
11210 | 0 | { |
11211 | 0 | PyObject *return_value = NULL; |
11212 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
11213 | |
|
11214 | 0 | #define NUM_KEYWORDS 2 |
11215 | 0 | static struct { |
11216 | 0 | PyGC_Head _this_is_not_used; |
11217 | 0 | PyObject_VAR_HEAD |
11218 | 0 | Py_hash_t ob_hash; |
11219 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
11220 | 0 | } _kwtuple = { |
11221 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
11222 | 0 | .ob_hash = -1, |
11223 | 0 | .ob_item = { &_Py_ID(path), &_Py_ID(follow_symlinks), }, |
11224 | 0 | }; |
11225 | 0 | #undef NUM_KEYWORDS |
11226 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
11227 | |
|
11228 | | #else // !Py_BUILD_CORE |
11229 | | # define KWTUPLE NULL |
11230 | | #endif // !Py_BUILD_CORE |
11231 | |
|
11232 | 0 | static const char * const _keywords[] = {"path", "follow_symlinks", NULL}; |
11233 | 0 | static _PyArg_Parser _parser = { |
11234 | 0 | .keywords = _keywords, |
11235 | 0 | .fname = "listxattr", |
11236 | 0 | .kwtuple = KWTUPLE, |
11237 | 0 | }; |
11238 | 0 | #undef KWTUPLE |
11239 | 0 | PyObject *argsbuf[2]; |
11240 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; |
11241 | 0 | path_t path = PATH_T_INITIALIZE_P("listxattr", "path", 1, 0, 0, 1); |
11242 | 0 | int follow_symlinks = 1; |
11243 | |
|
11244 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
11245 | 0 | /*minpos*/ 0, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
11246 | 0 | if (!args) { |
11247 | 0 | goto exit; |
11248 | 0 | } |
11249 | 0 | if (!noptargs) { |
11250 | 0 | goto skip_optional_pos; |
11251 | 0 | } |
11252 | 0 | if (args[0]) { |
11253 | 0 | if (!path_converter(args[0], &path)) { |
11254 | 0 | goto exit; |
11255 | 0 | } |
11256 | 0 | if (!--noptargs) { |
11257 | 0 | goto skip_optional_pos; |
11258 | 0 | } |
11259 | 0 | } |
11260 | 0 | skip_optional_pos: |
11261 | 0 | if (!noptargs) { |
11262 | 0 | goto skip_optional_kwonly; |
11263 | 0 | } |
11264 | 0 | follow_symlinks = PyObject_IsTrue(args[1]); |
11265 | 0 | if (follow_symlinks < 0) { |
11266 | 0 | goto exit; |
11267 | 0 | } |
11268 | 0 | skip_optional_kwonly: |
11269 | 0 | return_value = os_listxattr_impl(module, &path, follow_symlinks); |
11270 | |
|
11271 | 0 | exit: |
11272 | | /* Cleanup for path */ |
11273 | 0 | path_cleanup(&path); |
11274 | |
|
11275 | 0 | return return_value; |
11276 | 0 | } |
11277 | | |
11278 | | #endif /* defined(USE_XATTRS) */ |
11279 | | |
11280 | | PyDoc_STRVAR(os_urandom__doc__, |
11281 | | "urandom($module, size, /)\n" |
11282 | | "--\n" |
11283 | | "\n" |
11284 | | "Return a bytes object containing random bytes suitable for cryptographic use."); |
11285 | | |
11286 | | #define OS_URANDOM_METHODDEF \ |
11287 | | {"urandom", (PyCFunction)os_urandom, METH_O, os_urandom__doc__}, |
11288 | | |
11289 | | static PyObject * |
11290 | | os_urandom_impl(PyObject *module, Py_ssize_t size); |
11291 | | |
11292 | | static PyObject * |
11293 | | os_urandom(PyObject *module, PyObject *arg) |
11294 | 0 | { |
11295 | 0 | PyObject *return_value = NULL; |
11296 | 0 | Py_ssize_t size; |
11297 | |
|
11298 | 0 | { |
11299 | 0 | Py_ssize_t ival = -1; |
11300 | 0 | PyObject *iobj = _PyNumber_Index(arg); |
11301 | 0 | if (iobj != NULL) { |
11302 | 0 | ival = PyLong_AsSsize_t(iobj); |
11303 | 0 | Py_DECREF(iobj); |
11304 | 0 | } |
11305 | 0 | if (ival == -1 && PyErr_Occurred()) { |
11306 | 0 | goto exit; |
11307 | 0 | } |
11308 | 0 | size = ival; |
11309 | 0 | } |
11310 | 0 | return_value = os_urandom_impl(module, size); |
11311 | |
|
11312 | 0 | exit: |
11313 | 0 | return return_value; |
11314 | 0 | } |
11315 | | |
11316 | | #if defined(HAVE_MEMFD_CREATE) |
11317 | | |
11318 | | PyDoc_STRVAR(os_memfd_create__doc__, |
11319 | | "memfd_create($module, /, name, flags=MFD_CLOEXEC)\n" |
11320 | | "--\n" |
11321 | | "\n"); |
11322 | | |
11323 | | #define OS_MEMFD_CREATE_METHODDEF \ |
11324 | | {"memfd_create", _PyCFunction_CAST(os_memfd_create), METH_FASTCALL|METH_KEYWORDS, os_memfd_create__doc__}, |
11325 | | |
11326 | | static PyObject * |
11327 | | os_memfd_create_impl(PyObject *module, PyObject *name, unsigned int flags); |
11328 | | |
11329 | | static PyObject * |
11330 | | os_memfd_create(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
11331 | 0 | { |
11332 | 0 | PyObject *return_value = NULL; |
11333 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
11334 | |
|
11335 | 0 | #define NUM_KEYWORDS 2 |
11336 | 0 | static struct { |
11337 | 0 | PyGC_Head _this_is_not_used; |
11338 | 0 | PyObject_VAR_HEAD |
11339 | 0 | Py_hash_t ob_hash; |
11340 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
11341 | 0 | } _kwtuple = { |
11342 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
11343 | 0 | .ob_hash = -1, |
11344 | 0 | .ob_item = { &_Py_ID(name), &_Py_ID(flags), }, |
11345 | 0 | }; |
11346 | 0 | #undef NUM_KEYWORDS |
11347 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
11348 | |
|
11349 | | #else // !Py_BUILD_CORE |
11350 | | # define KWTUPLE NULL |
11351 | | #endif // !Py_BUILD_CORE |
11352 | |
|
11353 | 0 | static const char * const _keywords[] = {"name", "flags", NULL}; |
11354 | 0 | static _PyArg_Parser _parser = { |
11355 | 0 | .keywords = _keywords, |
11356 | 0 | .fname = "memfd_create", |
11357 | 0 | .kwtuple = KWTUPLE, |
11358 | 0 | }; |
11359 | 0 | #undef KWTUPLE |
11360 | 0 | PyObject *argsbuf[2]; |
11361 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
11362 | 0 | PyObject *name = NULL; |
11363 | 0 | unsigned int flags = MFD_CLOEXEC; |
11364 | |
|
11365 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
11366 | 0 | /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
11367 | 0 | if (!args) { |
11368 | 0 | goto exit; |
11369 | 0 | } |
11370 | 0 | if (!PyUnicode_FSConverter(args[0], &name)) { |
11371 | 0 | goto exit; |
11372 | 0 | } |
11373 | 0 | if (!noptargs) { |
11374 | 0 | goto skip_optional_pos; |
11375 | 0 | } |
11376 | 0 | flags = (unsigned int)PyLong_AsUnsignedLongMask(args[1]); |
11377 | 0 | if (flags == (unsigned int)-1 && PyErr_Occurred()) { |
11378 | 0 | goto exit; |
11379 | 0 | } |
11380 | 0 | skip_optional_pos: |
11381 | 0 | return_value = os_memfd_create_impl(module, name, flags); |
11382 | |
|
11383 | 0 | exit: |
11384 | | /* Cleanup for name */ |
11385 | 0 | Py_XDECREF(name); |
11386 | |
|
11387 | 0 | return return_value; |
11388 | 0 | } |
11389 | | |
11390 | | #endif /* defined(HAVE_MEMFD_CREATE) */ |
11391 | | |
11392 | | #if (defined(HAVE_EVENTFD) && defined(EFD_CLOEXEC)) |
11393 | | |
11394 | | PyDoc_STRVAR(os_eventfd__doc__, |
11395 | | "eventfd($module, /, initval, flags=EFD_CLOEXEC)\n" |
11396 | | "--\n" |
11397 | | "\n" |
11398 | | "Creates and returns an event notification file descriptor."); |
11399 | | |
11400 | | #define OS_EVENTFD_METHODDEF \ |
11401 | | {"eventfd", _PyCFunction_CAST(os_eventfd), METH_FASTCALL|METH_KEYWORDS, os_eventfd__doc__}, |
11402 | | |
11403 | | static PyObject * |
11404 | | os_eventfd_impl(PyObject *module, unsigned int initval, int flags); |
11405 | | |
11406 | | static PyObject * |
11407 | | os_eventfd(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
11408 | 0 | { |
11409 | 0 | PyObject *return_value = NULL; |
11410 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
11411 | |
|
11412 | 0 | #define NUM_KEYWORDS 2 |
11413 | 0 | static struct { |
11414 | 0 | PyGC_Head _this_is_not_used; |
11415 | 0 | PyObject_VAR_HEAD |
11416 | 0 | Py_hash_t ob_hash; |
11417 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
11418 | 0 | } _kwtuple = { |
11419 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
11420 | 0 | .ob_hash = -1, |
11421 | 0 | .ob_item = { &_Py_ID(initval), &_Py_ID(flags), }, |
11422 | 0 | }; |
11423 | 0 | #undef NUM_KEYWORDS |
11424 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
11425 | |
|
11426 | | #else // !Py_BUILD_CORE |
11427 | | # define KWTUPLE NULL |
11428 | | #endif // !Py_BUILD_CORE |
11429 | |
|
11430 | 0 | static const char * const _keywords[] = {"initval", "flags", NULL}; |
11431 | 0 | static _PyArg_Parser _parser = { |
11432 | 0 | .keywords = _keywords, |
11433 | 0 | .fname = "eventfd", |
11434 | 0 | .kwtuple = KWTUPLE, |
11435 | 0 | }; |
11436 | 0 | #undef KWTUPLE |
11437 | 0 | PyObject *argsbuf[2]; |
11438 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
11439 | 0 | unsigned int initval; |
11440 | 0 | int flags = EFD_CLOEXEC; |
11441 | |
|
11442 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
11443 | 0 | /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
11444 | 0 | if (!args) { |
11445 | 0 | goto exit; |
11446 | 0 | } |
11447 | 0 | if (!_PyLong_UnsignedInt_Converter(args[0], &initval)) { |
11448 | 0 | goto exit; |
11449 | 0 | } |
11450 | 0 | if (!noptargs) { |
11451 | 0 | goto skip_optional_pos; |
11452 | 0 | } |
11453 | 0 | flags = PyLong_AsInt(args[1]); |
11454 | 0 | if (flags == -1 && PyErr_Occurred()) { |
11455 | 0 | goto exit; |
11456 | 0 | } |
11457 | 0 | skip_optional_pos: |
11458 | 0 | return_value = os_eventfd_impl(module, initval, flags); |
11459 | |
|
11460 | 0 | exit: |
11461 | 0 | return return_value; |
11462 | 0 | } |
11463 | | |
11464 | | #endif /* (defined(HAVE_EVENTFD) && defined(EFD_CLOEXEC)) */ |
11465 | | |
11466 | | #if (defined(HAVE_EVENTFD) && defined(EFD_CLOEXEC)) |
11467 | | |
11468 | | PyDoc_STRVAR(os_eventfd_read__doc__, |
11469 | | "eventfd_read($module, /, fd)\n" |
11470 | | "--\n" |
11471 | | "\n" |
11472 | | "Read eventfd value"); |
11473 | | |
11474 | | #define OS_EVENTFD_READ_METHODDEF \ |
11475 | | {"eventfd_read", _PyCFunction_CAST(os_eventfd_read), METH_FASTCALL|METH_KEYWORDS, os_eventfd_read__doc__}, |
11476 | | |
11477 | | static PyObject * |
11478 | | os_eventfd_read_impl(PyObject *module, int fd); |
11479 | | |
11480 | | static PyObject * |
11481 | | os_eventfd_read(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
11482 | 0 | { |
11483 | 0 | PyObject *return_value = NULL; |
11484 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
11485 | |
|
11486 | 0 | #define NUM_KEYWORDS 1 |
11487 | 0 | static struct { |
11488 | 0 | PyGC_Head _this_is_not_used; |
11489 | 0 | PyObject_VAR_HEAD |
11490 | 0 | Py_hash_t ob_hash; |
11491 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
11492 | 0 | } _kwtuple = { |
11493 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
11494 | 0 | .ob_hash = -1, |
11495 | 0 | .ob_item = { &_Py_ID(fd), }, |
11496 | 0 | }; |
11497 | 0 | #undef NUM_KEYWORDS |
11498 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
11499 | |
|
11500 | | #else // !Py_BUILD_CORE |
11501 | | # define KWTUPLE NULL |
11502 | | #endif // !Py_BUILD_CORE |
11503 | |
|
11504 | 0 | static const char * const _keywords[] = {"fd", NULL}; |
11505 | 0 | static _PyArg_Parser _parser = { |
11506 | 0 | .keywords = _keywords, |
11507 | 0 | .fname = "eventfd_read", |
11508 | 0 | .kwtuple = KWTUPLE, |
11509 | 0 | }; |
11510 | 0 | #undef KWTUPLE |
11511 | 0 | PyObject *argsbuf[1]; |
11512 | 0 | int fd; |
11513 | |
|
11514 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
11515 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
11516 | 0 | if (!args) { |
11517 | 0 | goto exit; |
11518 | 0 | } |
11519 | 0 | fd = PyObject_AsFileDescriptor(args[0]); |
11520 | 0 | if (fd < 0) { |
11521 | 0 | goto exit; |
11522 | 0 | } |
11523 | 0 | return_value = os_eventfd_read_impl(module, fd); |
11524 | |
|
11525 | 0 | exit: |
11526 | 0 | return return_value; |
11527 | 0 | } |
11528 | | |
11529 | | #endif /* (defined(HAVE_EVENTFD) && defined(EFD_CLOEXEC)) */ |
11530 | | |
11531 | | #if (defined(HAVE_EVENTFD) && defined(EFD_CLOEXEC)) |
11532 | | |
11533 | | PyDoc_STRVAR(os_eventfd_write__doc__, |
11534 | | "eventfd_write($module, /, fd, value)\n" |
11535 | | "--\n" |
11536 | | "\n" |
11537 | | "Write eventfd value."); |
11538 | | |
11539 | | #define OS_EVENTFD_WRITE_METHODDEF \ |
11540 | | {"eventfd_write", _PyCFunction_CAST(os_eventfd_write), METH_FASTCALL|METH_KEYWORDS, os_eventfd_write__doc__}, |
11541 | | |
11542 | | static PyObject * |
11543 | | os_eventfd_write_impl(PyObject *module, int fd, unsigned long long value); |
11544 | | |
11545 | | static PyObject * |
11546 | | os_eventfd_write(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
11547 | 0 | { |
11548 | 0 | PyObject *return_value = NULL; |
11549 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
11550 | |
|
11551 | 0 | #define NUM_KEYWORDS 2 |
11552 | 0 | static struct { |
11553 | 0 | PyGC_Head _this_is_not_used; |
11554 | 0 | PyObject_VAR_HEAD |
11555 | 0 | Py_hash_t ob_hash; |
11556 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
11557 | 0 | } _kwtuple = { |
11558 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
11559 | 0 | .ob_hash = -1, |
11560 | 0 | .ob_item = { &_Py_ID(fd), &_Py_ID(value), }, |
11561 | 0 | }; |
11562 | 0 | #undef NUM_KEYWORDS |
11563 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
11564 | |
|
11565 | | #else // !Py_BUILD_CORE |
11566 | | # define KWTUPLE NULL |
11567 | | #endif // !Py_BUILD_CORE |
11568 | |
|
11569 | 0 | static const char * const _keywords[] = {"fd", "value", NULL}; |
11570 | 0 | static _PyArg_Parser _parser = { |
11571 | 0 | .keywords = _keywords, |
11572 | 0 | .fname = "eventfd_write", |
11573 | 0 | .kwtuple = KWTUPLE, |
11574 | 0 | }; |
11575 | 0 | #undef KWTUPLE |
11576 | 0 | PyObject *argsbuf[2]; |
11577 | 0 | int fd; |
11578 | 0 | unsigned long long value; |
11579 | |
|
11580 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
11581 | 0 | /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
11582 | 0 | if (!args) { |
11583 | 0 | goto exit; |
11584 | 0 | } |
11585 | 0 | fd = PyObject_AsFileDescriptor(args[0]); |
11586 | 0 | if (fd < 0) { |
11587 | 0 | goto exit; |
11588 | 0 | } |
11589 | 0 | if (!_PyLong_UnsignedLongLong_Converter(args[1], &value)) { |
11590 | 0 | goto exit; |
11591 | 0 | } |
11592 | 0 | return_value = os_eventfd_write_impl(module, fd, value); |
11593 | |
|
11594 | 0 | exit: |
11595 | 0 | return return_value; |
11596 | 0 | } |
11597 | | |
11598 | | #endif /* (defined(HAVE_EVENTFD) && defined(EFD_CLOEXEC)) */ |
11599 | | |
11600 | | #if (defined(TERMSIZE_USE_CONIO) || defined(TERMSIZE_USE_IOCTL)) |
11601 | | |
11602 | | PyDoc_STRVAR(os_get_terminal_size__doc__, |
11603 | | "get_terminal_size($module, fd=<unrepresentable>, /)\n" |
11604 | | "--\n" |
11605 | | "\n" |
11606 | | "Return the size of the terminal window as (columns, lines).\n" |
11607 | | "\n" |
11608 | | "The optional argument fd (default standard output) specifies\n" |
11609 | | "which file descriptor should be queried.\n" |
11610 | | "\n" |
11611 | | "If the file descriptor is not connected to a terminal, an OSError\n" |
11612 | | "is thrown.\n" |
11613 | | "\n" |
11614 | | "This function will only be defined if an implementation is\n" |
11615 | | "available for this system.\n" |
11616 | | "\n" |
11617 | | "shutil.get_terminal_size is the high-level function which should\n" |
11618 | | "normally be used, os.get_terminal_size is the low-level implementation."); |
11619 | | |
11620 | | #define OS_GET_TERMINAL_SIZE_METHODDEF \ |
11621 | | {"get_terminal_size", _PyCFunction_CAST(os_get_terminal_size), METH_FASTCALL, os_get_terminal_size__doc__}, |
11622 | | |
11623 | | static PyObject * |
11624 | | os_get_terminal_size_impl(PyObject *module, int fd); |
11625 | | |
11626 | | static PyObject * |
11627 | | os_get_terminal_size(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
11628 | 0 | { |
11629 | 0 | PyObject *return_value = NULL; |
11630 | 0 | int fd = fileno(stdout); |
11631 | |
|
11632 | 0 | if (!_PyArg_CheckPositional("get_terminal_size", nargs, 0, 1)) { |
11633 | 0 | goto exit; |
11634 | 0 | } |
11635 | 0 | if (nargs < 1) { |
11636 | 0 | goto skip_optional; |
11637 | 0 | } |
11638 | 0 | fd = PyLong_AsInt(args[0]); |
11639 | 0 | if (fd == -1 && PyErr_Occurred()) { |
11640 | 0 | goto exit; |
11641 | 0 | } |
11642 | 0 | skip_optional: |
11643 | 0 | return_value = os_get_terminal_size_impl(module, fd); |
11644 | |
|
11645 | 0 | exit: |
11646 | 0 | return return_value; |
11647 | 0 | } |
11648 | | |
11649 | | #endif /* (defined(TERMSIZE_USE_CONIO) || defined(TERMSIZE_USE_IOCTL)) */ |
11650 | | |
11651 | | PyDoc_STRVAR(os_cpu_count__doc__, |
11652 | | "cpu_count($module, /)\n" |
11653 | | "--\n" |
11654 | | "\n" |
11655 | | "Return the number of logical CPUs in the system.\n" |
11656 | | "\n" |
11657 | | "Return None if indeterminable."); |
11658 | | |
11659 | | #define OS_CPU_COUNT_METHODDEF \ |
11660 | | {"cpu_count", (PyCFunction)os_cpu_count, METH_NOARGS, os_cpu_count__doc__}, |
11661 | | |
11662 | | static PyObject * |
11663 | | os_cpu_count_impl(PyObject *module); |
11664 | | |
11665 | | static PyObject * |
11666 | | os_cpu_count(PyObject *module, PyObject *Py_UNUSED(ignored)) |
11667 | 0 | { |
11668 | 0 | return os_cpu_count_impl(module); |
11669 | 0 | } |
11670 | | |
11671 | | PyDoc_STRVAR(os_get_inheritable__doc__, |
11672 | | "get_inheritable($module, fd, /)\n" |
11673 | | "--\n" |
11674 | | "\n" |
11675 | | "Get the close-on-exe flag of the specified file descriptor."); |
11676 | | |
11677 | | #define OS_GET_INHERITABLE_METHODDEF \ |
11678 | | {"get_inheritable", (PyCFunction)os_get_inheritable, METH_O, os_get_inheritable__doc__}, |
11679 | | |
11680 | | static int |
11681 | | os_get_inheritable_impl(PyObject *module, int fd); |
11682 | | |
11683 | | static PyObject * |
11684 | | os_get_inheritable(PyObject *module, PyObject *arg) |
11685 | 0 | { |
11686 | 0 | PyObject *return_value = NULL; |
11687 | 0 | int fd; |
11688 | 0 | int _return_value; |
11689 | |
|
11690 | 0 | fd = PyLong_AsInt(arg); |
11691 | 0 | if (fd == -1 && PyErr_Occurred()) { |
11692 | 0 | goto exit; |
11693 | 0 | } |
11694 | 0 | _return_value = os_get_inheritable_impl(module, fd); |
11695 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
11696 | 0 | goto exit; |
11697 | 0 | } |
11698 | 0 | return_value = PyBool_FromLong((long)_return_value); |
11699 | |
|
11700 | 0 | exit: |
11701 | 0 | return return_value; |
11702 | 0 | } |
11703 | | |
11704 | | PyDoc_STRVAR(os_set_inheritable__doc__, |
11705 | | "set_inheritable($module, fd, inheritable, /)\n" |
11706 | | "--\n" |
11707 | | "\n" |
11708 | | "Set the inheritable flag of the specified file descriptor."); |
11709 | | |
11710 | | #define OS_SET_INHERITABLE_METHODDEF \ |
11711 | | {"set_inheritable", _PyCFunction_CAST(os_set_inheritable), METH_FASTCALL, os_set_inheritable__doc__}, |
11712 | | |
11713 | | static PyObject * |
11714 | | os_set_inheritable_impl(PyObject *module, int fd, int inheritable); |
11715 | | |
11716 | | static PyObject * |
11717 | | os_set_inheritable(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
11718 | 0 | { |
11719 | 0 | PyObject *return_value = NULL; |
11720 | 0 | int fd; |
11721 | 0 | int inheritable; |
11722 | |
|
11723 | 0 | if (!_PyArg_CheckPositional("set_inheritable", nargs, 2, 2)) { |
11724 | 0 | goto exit; |
11725 | 0 | } |
11726 | 0 | fd = PyLong_AsInt(args[0]); |
11727 | 0 | if (fd == -1 && PyErr_Occurred()) { |
11728 | 0 | goto exit; |
11729 | 0 | } |
11730 | 0 | inheritable = PyLong_AsInt(args[1]); |
11731 | 0 | if (inheritable == -1 && PyErr_Occurred()) { |
11732 | 0 | goto exit; |
11733 | 0 | } |
11734 | 0 | return_value = os_set_inheritable_impl(module, fd, inheritable); |
11735 | |
|
11736 | 0 | exit: |
11737 | 0 | return return_value; |
11738 | 0 | } |
11739 | | |
11740 | | #if defined(MS_WINDOWS) |
11741 | | |
11742 | | PyDoc_STRVAR(os_get_handle_inheritable__doc__, |
11743 | | "get_handle_inheritable($module, handle, /)\n" |
11744 | | "--\n" |
11745 | | "\n" |
11746 | | "Get the close-on-exe flag of the specified file descriptor."); |
11747 | | |
11748 | | #define OS_GET_HANDLE_INHERITABLE_METHODDEF \ |
11749 | | {"get_handle_inheritable", (PyCFunction)os_get_handle_inheritable, METH_O, os_get_handle_inheritable__doc__}, |
11750 | | |
11751 | | static int |
11752 | | os_get_handle_inheritable_impl(PyObject *module, intptr_t handle); |
11753 | | |
11754 | | static PyObject * |
11755 | | os_get_handle_inheritable(PyObject *module, PyObject *arg) |
11756 | | { |
11757 | | PyObject *return_value = NULL; |
11758 | | intptr_t handle; |
11759 | | int _return_value; |
11760 | | |
11761 | | handle = (intptr_t)PyLong_AsVoidPtr(arg); |
11762 | | if (!handle && PyErr_Occurred()) { |
11763 | | goto exit; |
11764 | | } |
11765 | | _return_value = os_get_handle_inheritable_impl(module, handle); |
11766 | | if ((_return_value == -1) && PyErr_Occurred()) { |
11767 | | goto exit; |
11768 | | } |
11769 | | return_value = PyBool_FromLong((long)_return_value); |
11770 | | |
11771 | | exit: |
11772 | | return return_value; |
11773 | | } |
11774 | | |
11775 | | #endif /* defined(MS_WINDOWS) */ |
11776 | | |
11777 | | #if defined(MS_WINDOWS) |
11778 | | |
11779 | | PyDoc_STRVAR(os_set_handle_inheritable__doc__, |
11780 | | "set_handle_inheritable($module, handle, inheritable, /)\n" |
11781 | | "--\n" |
11782 | | "\n" |
11783 | | "Set the inheritable flag of the specified handle."); |
11784 | | |
11785 | | #define OS_SET_HANDLE_INHERITABLE_METHODDEF \ |
11786 | | {"set_handle_inheritable", _PyCFunction_CAST(os_set_handle_inheritable), METH_FASTCALL, os_set_handle_inheritable__doc__}, |
11787 | | |
11788 | | static PyObject * |
11789 | | os_set_handle_inheritable_impl(PyObject *module, intptr_t handle, |
11790 | | int inheritable); |
11791 | | |
11792 | | static PyObject * |
11793 | | os_set_handle_inheritable(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
11794 | | { |
11795 | | PyObject *return_value = NULL; |
11796 | | intptr_t handle; |
11797 | | int inheritable; |
11798 | | |
11799 | | if (!_PyArg_CheckPositional("set_handle_inheritable", nargs, 2, 2)) { |
11800 | | goto exit; |
11801 | | } |
11802 | | handle = (intptr_t)PyLong_AsVoidPtr(args[0]); |
11803 | | if (!handle && PyErr_Occurred()) { |
11804 | | goto exit; |
11805 | | } |
11806 | | inheritable = PyObject_IsTrue(args[1]); |
11807 | | if (inheritable < 0) { |
11808 | | goto exit; |
11809 | | } |
11810 | | return_value = os_set_handle_inheritable_impl(module, handle, inheritable); |
11811 | | |
11812 | | exit: |
11813 | | return return_value; |
11814 | | } |
11815 | | |
11816 | | #endif /* defined(MS_WINDOWS) */ |
11817 | | |
11818 | | PyDoc_STRVAR(os_get_blocking__doc__, |
11819 | | "get_blocking($module, fd, /)\n" |
11820 | | "--\n" |
11821 | | "\n" |
11822 | | "Get the blocking mode of the file descriptor.\n" |
11823 | | "\n" |
11824 | | "Return False if the O_NONBLOCK flag is set, True if the flag is cleared."); |
11825 | | |
11826 | | #define OS_GET_BLOCKING_METHODDEF \ |
11827 | | {"get_blocking", (PyCFunction)os_get_blocking, METH_O, os_get_blocking__doc__}, |
11828 | | |
11829 | | static int |
11830 | | os_get_blocking_impl(PyObject *module, int fd); |
11831 | | |
11832 | | static PyObject * |
11833 | | os_get_blocking(PyObject *module, PyObject *arg) |
11834 | 0 | { |
11835 | 0 | PyObject *return_value = NULL; |
11836 | 0 | int fd; |
11837 | 0 | int _return_value; |
11838 | |
|
11839 | 0 | fd = PyLong_AsInt(arg); |
11840 | 0 | if (fd == -1 && PyErr_Occurred()) { |
11841 | 0 | goto exit; |
11842 | 0 | } |
11843 | 0 | _return_value = os_get_blocking_impl(module, fd); |
11844 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
11845 | 0 | goto exit; |
11846 | 0 | } |
11847 | 0 | return_value = PyBool_FromLong((long)_return_value); |
11848 | |
|
11849 | 0 | exit: |
11850 | 0 | return return_value; |
11851 | 0 | } |
11852 | | |
11853 | | PyDoc_STRVAR(os_set_blocking__doc__, |
11854 | | "set_blocking($module, fd, blocking, /)\n" |
11855 | | "--\n" |
11856 | | "\n" |
11857 | | "Set the blocking mode of the specified file descriptor.\n" |
11858 | | "\n" |
11859 | | "Set the O_NONBLOCK flag if blocking is False,\n" |
11860 | | "clear the O_NONBLOCK flag otherwise."); |
11861 | | |
11862 | | #define OS_SET_BLOCKING_METHODDEF \ |
11863 | | {"set_blocking", _PyCFunction_CAST(os_set_blocking), METH_FASTCALL, os_set_blocking__doc__}, |
11864 | | |
11865 | | static PyObject * |
11866 | | os_set_blocking_impl(PyObject *module, int fd, int blocking); |
11867 | | |
11868 | | static PyObject * |
11869 | | os_set_blocking(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
11870 | 0 | { |
11871 | 0 | PyObject *return_value = NULL; |
11872 | 0 | int fd; |
11873 | 0 | int blocking; |
11874 | |
|
11875 | 0 | if (!_PyArg_CheckPositional("set_blocking", nargs, 2, 2)) { |
11876 | 0 | goto exit; |
11877 | 0 | } |
11878 | 0 | fd = PyLong_AsInt(args[0]); |
11879 | 0 | if (fd == -1 && PyErr_Occurred()) { |
11880 | 0 | goto exit; |
11881 | 0 | } |
11882 | 0 | blocking = PyObject_IsTrue(args[1]); |
11883 | 0 | if (blocking < 0) { |
11884 | 0 | goto exit; |
11885 | 0 | } |
11886 | 0 | return_value = os_set_blocking_impl(module, fd, blocking); |
11887 | |
|
11888 | 0 | exit: |
11889 | 0 | return return_value; |
11890 | 0 | } |
11891 | | |
11892 | | PyDoc_STRVAR(os_DirEntry_is_symlink__doc__, |
11893 | | "is_symlink($self, /)\n" |
11894 | | "--\n" |
11895 | | "\n" |
11896 | | "Return True if the entry is a symbolic link; cached per entry."); |
11897 | | |
11898 | | #define OS_DIRENTRY_IS_SYMLINK_METHODDEF \ |
11899 | | {"is_symlink", _PyCFunction_CAST(os_DirEntry_is_symlink), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, os_DirEntry_is_symlink__doc__}, |
11900 | | |
11901 | | static int |
11902 | | os_DirEntry_is_symlink_impl(DirEntry *self, PyTypeObject *defining_class); |
11903 | | |
11904 | | static PyObject * |
11905 | | os_DirEntry_is_symlink(PyObject *self, PyTypeObject *defining_class, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
11906 | 0 | { |
11907 | 0 | PyObject *return_value = NULL; |
11908 | 0 | int _return_value; |
11909 | |
|
11910 | 0 | if (nargs || (kwnames && PyTuple_GET_SIZE(kwnames))) { |
11911 | 0 | PyErr_SetString(PyExc_TypeError, "is_symlink() takes no arguments"); |
11912 | 0 | goto exit; |
11913 | 0 | } |
11914 | 0 | _return_value = os_DirEntry_is_symlink_impl((DirEntry *)self, defining_class); |
11915 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
11916 | 0 | goto exit; |
11917 | 0 | } |
11918 | 0 | return_value = PyBool_FromLong((long)_return_value); |
11919 | |
|
11920 | 0 | exit: |
11921 | 0 | return return_value; |
11922 | 0 | } |
11923 | | |
11924 | | PyDoc_STRVAR(os_DirEntry_is_junction__doc__, |
11925 | | "is_junction($self, /)\n" |
11926 | | "--\n" |
11927 | | "\n" |
11928 | | "Return True if the entry is a junction; cached per entry."); |
11929 | | |
11930 | | #define OS_DIRENTRY_IS_JUNCTION_METHODDEF \ |
11931 | | {"is_junction", (PyCFunction)os_DirEntry_is_junction, METH_NOARGS, os_DirEntry_is_junction__doc__}, |
11932 | | |
11933 | | static int |
11934 | | os_DirEntry_is_junction_impl(DirEntry *self); |
11935 | | |
11936 | | static PyObject * |
11937 | | os_DirEntry_is_junction(PyObject *self, PyObject *Py_UNUSED(ignored)) |
11938 | 0 | { |
11939 | 0 | PyObject *return_value = NULL; |
11940 | 0 | int _return_value; |
11941 | |
|
11942 | 0 | _return_value = os_DirEntry_is_junction_impl((DirEntry *)self); |
11943 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
11944 | 0 | goto exit; |
11945 | 0 | } |
11946 | 0 | return_value = PyBool_FromLong((long)_return_value); |
11947 | |
|
11948 | 0 | exit: |
11949 | 0 | return return_value; |
11950 | 0 | } |
11951 | | |
11952 | | PyDoc_STRVAR(os_DirEntry_stat__doc__, |
11953 | | "stat($self, /, *, follow_symlinks=True)\n" |
11954 | | "--\n" |
11955 | | "\n" |
11956 | | "Return stat_result object for the entry; cached per entry."); |
11957 | | |
11958 | | #define OS_DIRENTRY_STAT_METHODDEF \ |
11959 | | {"stat", _PyCFunction_CAST(os_DirEntry_stat), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, os_DirEntry_stat__doc__}, |
11960 | | |
11961 | | static PyObject * |
11962 | | os_DirEntry_stat_impl(DirEntry *self, PyTypeObject *defining_class, |
11963 | | int follow_symlinks); |
11964 | | |
11965 | | static PyObject * |
11966 | | os_DirEntry_stat(PyObject *self, PyTypeObject *defining_class, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
11967 | 0 | { |
11968 | 0 | PyObject *return_value = NULL; |
11969 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
11970 | |
|
11971 | 0 | #define NUM_KEYWORDS 1 |
11972 | 0 | static struct { |
11973 | 0 | PyGC_Head _this_is_not_used; |
11974 | 0 | PyObject_VAR_HEAD |
11975 | 0 | Py_hash_t ob_hash; |
11976 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
11977 | 0 | } _kwtuple = { |
11978 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
11979 | 0 | .ob_hash = -1, |
11980 | 0 | .ob_item = { &_Py_ID(follow_symlinks), }, |
11981 | 0 | }; |
11982 | 0 | #undef NUM_KEYWORDS |
11983 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
11984 | |
|
11985 | | #else // !Py_BUILD_CORE |
11986 | | # define KWTUPLE NULL |
11987 | | #endif // !Py_BUILD_CORE |
11988 | |
|
11989 | 0 | static const char * const _keywords[] = {"follow_symlinks", NULL}; |
11990 | 0 | static _PyArg_Parser _parser = { |
11991 | 0 | .keywords = _keywords, |
11992 | 0 | .fname = "stat", |
11993 | 0 | .kwtuple = KWTUPLE, |
11994 | 0 | }; |
11995 | 0 | #undef KWTUPLE |
11996 | 0 | PyObject *argsbuf[1]; |
11997 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; |
11998 | 0 | int follow_symlinks = 1; |
11999 | |
|
12000 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
12001 | 0 | /*minpos*/ 0, /*maxpos*/ 0, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
12002 | 0 | if (!args) { |
12003 | 0 | goto exit; |
12004 | 0 | } |
12005 | 0 | if (!noptargs) { |
12006 | 0 | goto skip_optional_kwonly; |
12007 | 0 | } |
12008 | 0 | follow_symlinks = PyObject_IsTrue(args[0]); |
12009 | 0 | if (follow_symlinks < 0) { |
12010 | 0 | goto exit; |
12011 | 0 | } |
12012 | 0 | skip_optional_kwonly: |
12013 | 0 | return_value = os_DirEntry_stat_impl((DirEntry *)self, defining_class, follow_symlinks); |
12014 | |
|
12015 | 0 | exit: |
12016 | 0 | return return_value; |
12017 | 0 | } |
12018 | | |
12019 | | PyDoc_STRVAR(os_DirEntry_is_dir__doc__, |
12020 | | "is_dir($self, /, *, follow_symlinks=True)\n" |
12021 | | "--\n" |
12022 | | "\n" |
12023 | | "Return True if the entry is a directory; cached per entry."); |
12024 | | |
12025 | | #define OS_DIRENTRY_IS_DIR_METHODDEF \ |
12026 | | {"is_dir", _PyCFunction_CAST(os_DirEntry_is_dir), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, os_DirEntry_is_dir__doc__}, |
12027 | | |
12028 | | static int |
12029 | | os_DirEntry_is_dir_impl(DirEntry *self, PyTypeObject *defining_class, |
12030 | | int follow_symlinks); |
12031 | | |
12032 | | static PyObject * |
12033 | | os_DirEntry_is_dir(PyObject *self, PyTypeObject *defining_class, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
12034 | 0 | { |
12035 | 0 | PyObject *return_value = NULL; |
12036 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
12037 | |
|
12038 | 0 | #define NUM_KEYWORDS 1 |
12039 | 0 | static struct { |
12040 | 0 | PyGC_Head _this_is_not_used; |
12041 | 0 | PyObject_VAR_HEAD |
12042 | 0 | Py_hash_t ob_hash; |
12043 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
12044 | 0 | } _kwtuple = { |
12045 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
12046 | 0 | .ob_hash = -1, |
12047 | 0 | .ob_item = { &_Py_ID(follow_symlinks), }, |
12048 | 0 | }; |
12049 | 0 | #undef NUM_KEYWORDS |
12050 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
12051 | |
|
12052 | | #else // !Py_BUILD_CORE |
12053 | | # define KWTUPLE NULL |
12054 | | #endif // !Py_BUILD_CORE |
12055 | |
|
12056 | 0 | static const char * const _keywords[] = {"follow_symlinks", NULL}; |
12057 | 0 | static _PyArg_Parser _parser = { |
12058 | 0 | .keywords = _keywords, |
12059 | 0 | .fname = "is_dir", |
12060 | 0 | .kwtuple = KWTUPLE, |
12061 | 0 | }; |
12062 | 0 | #undef KWTUPLE |
12063 | 0 | PyObject *argsbuf[1]; |
12064 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; |
12065 | 0 | int follow_symlinks = 1; |
12066 | 0 | int _return_value; |
12067 | |
|
12068 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
12069 | 0 | /*minpos*/ 0, /*maxpos*/ 0, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
12070 | 0 | if (!args) { |
12071 | 0 | goto exit; |
12072 | 0 | } |
12073 | 0 | if (!noptargs) { |
12074 | 0 | goto skip_optional_kwonly; |
12075 | 0 | } |
12076 | 0 | follow_symlinks = PyObject_IsTrue(args[0]); |
12077 | 0 | if (follow_symlinks < 0) { |
12078 | 0 | goto exit; |
12079 | 0 | } |
12080 | 0 | skip_optional_kwonly: |
12081 | 0 | _return_value = os_DirEntry_is_dir_impl((DirEntry *)self, defining_class, follow_symlinks); |
12082 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
12083 | 0 | goto exit; |
12084 | 0 | } |
12085 | 0 | return_value = PyBool_FromLong((long)_return_value); |
12086 | |
|
12087 | 0 | exit: |
12088 | 0 | return return_value; |
12089 | 0 | } |
12090 | | |
12091 | | PyDoc_STRVAR(os_DirEntry_is_file__doc__, |
12092 | | "is_file($self, /, *, follow_symlinks=True)\n" |
12093 | | "--\n" |
12094 | | "\n" |
12095 | | "Return True if the entry is a file; cached per entry."); |
12096 | | |
12097 | | #define OS_DIRENTRY_IS_FILE_METHODDEF \ |
12098 | | {"is_file", _PyCFunction_CAST(os_DirEntry_is_file), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, os_DirEntry_is_file__doc__}, |
12099 | | |
12100 | | static int |
12101 | | os_DirEntry_is_file_impl(DirEntry *self, PyTypeObject *defining_class, |
12102 | | int follow_symlinks); |
12103 | | |
12104 | | static PyObject * |
12105 | | os_DirEntry_is_file(PyObject *self, PyTypeObject *defining_class, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
12106 | 0 | { |
12107 | 0 | PyObject *return_value = NULL; |
12108 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
12109 | |
|
12110 | 0 | #define NUM_KEYWORDS 1 |
12111 | 0 | static struct { |
12112 | 0 | PyGC_Head _this_is_not_used; |
12113 | 0 | PyObject_VAR_HEAD |
12114 | 0 | Py_hash_t ob_hash; |
12115 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
12116 | 0 | } _kwtuple = { |
12117 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
12118 | 0 | .ob_hash = -1, |
12119 | 0 | .ob_item = { &_Py_ID(follow_symlinks), }, |
12120 | 0 | }; |
12121 | 0 | #undef NUM_KEYWORDS |
12122 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
12123 | |
|
12124 | | #else // !Py_BUILD_CORE |
12125 | | # define KWTUPLE NULL |
12126 | | #endif // !Py_BUILD_CORE |
12127 | |
|
12128 | 0 | static const char * const _keywords[] = {"follow_symlinks", NULL}; |
12129 | 0 | static _PyArg_Parser _parser = { |
12130 | 0 | .keywords = _keywords, |
12131 | 0 | .fname = "is_file", |
12132 | 0 | .kwtuple = KWTUPLE, |
12133 | 0 | }; |
12134 | 0 | #undef KWTUPLE |
12135 | 0 | PyObject *argsbuf[1]; |
12136 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; |
12137 | 0 | int follow_symlinks = 1; |
12138 | 0 | int _return_value; |
12139 | |
|
12140 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
12141 | 0 | /*minpos*/ 0, /*maxpos*/ 0, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
12142 | 0 | if (!args) { |
12143 | 0 | goto exit; |
12144 | 0 | } |
12145 | 0 | if (!noptargs) { |
12146 | 0 | goto skip_optional_kwonly; |
12147 | 0 | } |
12148 | 0 | follow_symlinks = PyObject_IsTrue(args[0]); |
12149 | 0 | if (follow_symlinks < 0) { |
12150 | 0 | goto exit; |
12151 | 0 | } |
12152 | 0 | skip_optional_kwonly: |
12153 | 0 | _return_value = os_DirEntry_is_file_impl((DirEntry *)self, defining_class, follow_symlinks); |
12154 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
12155 | 0 | goto exit; |
12156 | 0 | } |
12157 | 0 | return_value = PyBool_FromLong((long)_return_value); |
12158 | |
|
12159 | 0 | exit: |
12160 | 0 | return return_value; |
12161 | 0 | } |
12162 | | |
12163 | | PyDoc_STRVAR(os_DirEntry_inode__doc__, |
12164 | | "inode($self, /)\n" |
12165 | | "--\n" |
12166 | | "\n" |
12167 | | "Return inode of the entry; cached per entry."); |
12168 | | |
12169 | | #define OS_DIRENTRY_INODE_METHODDEF \ |
12170 | | {"inode", (PyCFunction)os_DirEntry_inode, METH_NOARGS, os_DirEntry_inode__doc__}, |
12171 | | |
12172 | | static PyObject * |
12173 | | os_DirEntry_inode_impl(DirEntry *self); |
12174 | | |
12175 | | static PyObject * |
12176 | | os_DirEntry_inode(PyObject *self, PyObject *Py_UNUSED(ignored)) |
12177 | 0 | { |
12178 | 0 | return os_DirEntry_inode_impl((DirEntry *)self); |
12179 | 0 | } |
12180 | | |
12181 | | PyDoc_STRVAR(os_DirEntry___fspath____doc__, |
12182 | | "__fspath__($self, /)\n" |
12183 | | "--\n" |
12184 | | "\n" |
12185 | | "Returns the path for the entry."); |
12186 | | |
12187 | | #define OS_DIRENTRY___FSPATH___METHODDEF \ |
12188 | | {"__fspath__", (PyCFunction)os_DirEntry___fspath__, METH_NOARGS, os_DirEntry___fspath____doc__}, |
12189 | | |
12190 | | static PyObject * |
12191 | | os_DirEntry___fspath___impl(DirEntry *self); |
12192 | | |
12193 | | static PyObject * |
12194 | | os_DirEntry___fspath__(PyObject *self, PyObject *Py_UNUSED(ignored)) |
12195 | 0 | { |
12196 | 0 | return os_DirEntry___fspath___impl((DirEntry *)self); |
12197 | 0 | } |
12198 | | |
12199 | | PyDoc_STRVAR(os_scandir__doc__, |
12200 | | "scandir($module, /, path=None)\n" |
12201 | | "--\n" |
12202 | | "\n" |
12203 | | "Return an iterator of DirEntry objects for given path.\n" |
12204 | | "\n" |
12205 | | "path can be specified as either str, bytes, or a path-like object. If path\n" |
12206 | | "is bytes, the names of yielded DirEntry objects will also be bytes; in\n" |
12207 | | "all other circumstances they will be str.\n" |
12208 | | "\n" |
12209 | | "If path is None, uses the path=\'.\'."); |
12210 | | |
12211 | | #define OS_SCANDIR_METHODDEF \ |
12212 | | {"scandir", _PyCFunction_CAST(os_scandir), METH_FASTCALL|METH_KEYWORDS, os_scandir__doc__}, |
12213 | | |
12214 | | static PyObject * |
12215 | | os_scandir_impl(PyObject *module, path_t *path); |
12216 | | |
12217 | | static PyObject * |
12218 | | os_scandir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
12219 | 0 | { |
12220 | 0 | PyObject *return_value = NULL; |
12221 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
12222 | |
|
12223 | 0 | #define NUM_KEYWORDS 1 |
12224 | 0 | static struct { |
12225 | 0 | PyGC_Head _this_is_not_used; |
12226 | 0 | PyObject_VAR_HEAD |
12227 | 0 | Py_hash_t ob_hash; |
12228 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
12229 | 0 | } _kwtuple = { |
12230 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
12231 | 0 | .ob_hash = -1, |
12232 | 0 | .ob_item = { &_Py_ID(path), }, |
12233 | 0 | }; |
12234 | 0 | #undef NUM_KEYWORDS |
12235 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
12236 | |
|
12237 | | #else // !Py_BUILD_CORE |
12238 | | # define KWTUPLE NULL |
12239 | | #endif // !Py_BUILD_CORE |
12240 | |
|
12241 | 0 | static const char * const _keywords[] = {"path", NULL}; |
12242 | 0 | static _PyArg_Parser _parser = { |
12243 | 0 | .keywords = _keywords, |
12244 | 0 | .fname = "scandir", |
12245 | 0 | .kwtuple = KWTUPLE, |
12246 | 0 | }; |
12247 | 0 | #undef KWTUPLE |
12248 | 0 | PyObject *argsbuf[1]; |
12249 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; |
12250 | 0 | path_t path = PATH_T_INITIALIZE_P("scandir", "path", 1, 0, 0, PATH_HAVE_FDOPENDIR); |
12251 | |
|
12252 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
12253 | 0 | /*minpos*/ 0, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
12254 | 0 | if (!args) { |
12255 | 0 | goto exit; |
12256 | 0 | } |
12257 | 0 | if (!noptargs) { |
12258 | 0 | goto skip_optional_pos; |
12259 | 0 | } |
12260 | 0 | if (!path_converter(args[0], &path)) { |
12261 | 0 | goto exit; |
12262 | 0 | } |
12263 | 0 | skip_optional_pos: |
12264 | 0 | return_value = os_scandir_impl(module, &path); |
12265 | |
|
12266 | 0 | exit: |
12267 | | /* Cleanup for path */ |
12268 | 0 | path_cleanup(&path); |
12269 | |
|
12270 | 0 | return return_value; |
12271 | 0 | } |
12272 | | |
12273 | | PyDoc_STRVAR(os_fspath__doc__, |
12274 | | "fspath($module, /, path)\n" |
12275 | | "--\n" |
12276 | | "\n" |
12277 | | "Return the file system path representation of the object.\n" |
12278 | | "\n" |
12279 | | "If the object is str or bytes, then allow it to pass through as-is. If the\n" |
12280 | | "object defines __fspath__(), then return the result of that method. All other\n" |
12281 | | "types raise a TypeError."); |
12282 | | |
12283 | | #define OS_FSPATH_METHODDEF \ |
12284 | | {"fspath", _PyCFunction_CAST(os_fspath), METH_FASTCALL|METH_KEYWORDS, os_fspath__doc__}, |
12285 | | |
12286 | | static PyObject * |
12287 | | os_fspath_impl(PyObject *module, PyObject *path); |
12288 | | |
12289 | | static PyObject * |
12290 | | os_fspath(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
12291 | 2.89k | { |
12292 | 2.89k | PyObject *return_value = NULL; |
12293 | 2.89k | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
12294 | | |
12295 | 2.89k | #define NUM_KEYWORDS 1 |
12296 | 2.89k | static struct { |
12297 | 2.89k | PyGC_Head _this_is_not_used; |
12298 | 2.89k | PyObject_VAR_HEAD |
12299 | 2.89k | Py_hash_t ob_hash; |
12300 | 2.89k | PyObject *ob_item[NUM_KEYWORDS]; |
12301 | 2.89k | } _kwtuple = { |
12302 | 2.89k | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
12303 | 2.89k | .ob_hash = -1, |
12304 | 2.89k | .ob_item = { &_Py_ID(path), }, |
12305 | 2.89k | }; |
12306 | 2.89k | #undef NUM_KEYWORDS |
12307 | 2.89k | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
12308 | | |
12309 | | #else // !Py_BUILD_CORE |
12310 | | # define KWTUPLE NULL |
12311 | | #endif // !Py_BUILD_CORE |
12312 | | |
12313 | 2.89k | static const char * const _keywords[] = {"path", NULL}; |
12314 | 2.89k | static _PyArg_Parser _parser = { |
12315 | 2.89k | .keywords = _keywords, |
12316 | 2.89k | .fname = "fspath", |
12317 | 2.89k | .kwtuple = KWTUPLE, |
12318 | 2.89k | }; |
12319 | 2.89k | #undef KWTUPLE |
12320 | 2.89k | PyObject *argsbuf[1]; |
12321 | 2.89k | PyObject *path; |
12322 | | |
12323 | 2.89k | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
12324 | 2.89k | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
12325 | 2.89k | if (!args) { |
12326 | 0 | goto exit; |
12327 | 0 | } |
12328 | 2.89k | path = args[0]; |
12329 | 2.89k | return_value = os_fspath_impl(module, path); |
12330 | | |
12331 | 2.89k | exit: |
12332 | 2.89k | return return_value; |
12333 | 2.89k | } |
12334 | | |
12335 | | #if defined(HAVE_GETRANDOM_SYSCALL) |
12336 | | |
12337 | | PyDoc_STRVAR(os_getrandom__doc__, |
12338 | | "getrandom($module, /, size, flags=0)\n" |
12339 | | "--\n" |
12340 | | "\n" |
12341 | | "Obtain a series of random bytes."); |
12342 | | |
12343 | | #define OS_GETRANDOM_METHODDEF \ |
12344 | | {"getrandom", _PyCFunction_CAST(os_getrandom), METH_FASTCALL|METH_KEYWORDS, os_getrandom__doc__}, |
12345 | | |
12346 | | static PyObject * |
12347 | | os_getrandom_impl(PyObject *module, Py_ssize_t size, int flags); |
12348 | | |
12349 | | static PyObject * |
12350 | | os_getrandom(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
12351 | 0 | { |
12352 | 0 | PyObject *return_value = NULL; |
12353 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
12354 | |
|
12355 | 0 | #define NUM_KEYWORDS 2 |
12356 | 0 | static struct { |
12357 | 0 | PyGC_Head _this_is_not_used; |
12358 | 0 | PyObject_VAR_HEAD |
12359 | 0 | Py_hash_t ob_hash; |
12360 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
12361 | 0 | } _kwtuple = { |
12362 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
12363 | 0 | .ob_hash = -1, |
12364 | 0 | .ob_item = { &_Py_ID(size), &_Py_ID(flags), }, |
12365 | 0 | }; |
12366 | 0 | #undef NUM_KEYWORDS |
12367 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
12368 | |
|
12369 | | #else // !Py_BUILD_CORE |
12370 | | # define KWTUPLE NULL |
12371 | | #endif // !Py_BUILD_CORE |
12372 | |
|
12373 | 0 | static const char * const _keywords[] = {"size", "flags", NULL}; |
12374 | 0 | static _PyArg_Parser _parser = { |
12375 | 0 | .keywords = _keywords, |
12376 | 0 | .fname = "getrandom", |
12377 | 0 | .kwtuple = KWTUPLE, |
12378 | 0 | }; |
12379 | 0 | #undef KWTUPLE |
12380 | 0 | PyObject *argsbuf[2]; |
12381 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
12382 | 0 | Py_ssize_t size; |
12383 | 0 | int flags = 0; |
12384 | |
|
12385 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
12386 | 0 | /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
12387 | 0 | if (!args) { |
12388 | 0 | goto exit; |
12389 | 0 | } |
12390 | 0 | { |
12391 | 0 | Py_ssize_t ival = -1; |
12392 | 0 | PyObject *iobj = _PyNumber_Index(args[0]); |
12393 | 0 | if (iobj != NULL) { |
12394 | 0 | ival = PyLong_AsSsize_t(iobj); |
12395 | 0 | Py_DECREF(iobj); |
12396 | 0 | } |
12397 | 0 | if (ival == -1 && PyErr_Occurred()) { |
12398 | 0 | goto exit; |
12399 | 0 | } |
12400 | 0 | size = ival; |
12401 | 0 | } |
12402 | 0 | if (!noptargs) { |
12403 | 0 | goto skip_optional_pos; |
12404 | 0 | } |
12405 | 0 | flags = PyLong_AsInt(args[1]); |
12406 | 0 | if (flags == -1 && PyErr_Occurred()) { |
12407 | 0 | goto exit; |
12408 | 0 | } |
12409 | 0 | skip_optional_pos: |
12410 | 0 | return_value = os_getrandom_impl(module, size, flags); |
12411 | |
|
12412 | 0 | exit: |
12413 | 0 | return return_value; |
12414 | 0 | } |
12415 | | |
12416 | | #endif /* defined(HAVE_GETRANDOM_SYSCALL) */ |
12417 | | |
12418 | | #if (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM)) |
12419 | | |
12420 | | PyDoc_STRVAR(os__add_dll_directory__doc__, |
12421 | | "_add_dll_directory($module, /, path)\n" |
12422 | | "--\n" |
12423 | | "\n" |
12424 | | "Add a path to the DLL search path.\n" |
12425 | | "\n" |
12426 | | "This search path is used when resolving dependencies for imported\n" |
12427 | | "extension modules (the module itself is resolved through sys.path),\n" |
12428 | | "and also by ctypes.\n" |
12429 | | "\n" |
12430 | | "Returns an opaque value that may be passed to os.remove_dll_directory\n" |
12431 | | "to remove this directory from the search path."); |
12432 | | |
12433 | | #define OS__ADD_DLL_DIRECTORY_METHODDEF \ |
12434 | | {"_add_dll_directory", _PyCFunction_CAST(os__add_dll_directory), METH_FASTCALL|METH_KEYWORDS, os__add_dll_directory__doc__}, |
12435 | | |
12436 | | static PyObject * |
12437 | | os__add_dll_directory_impl(PyObject *module, path_t *path); |
12438 | | |
12439 | | static PyObject * |
12440 | | os__add_dll_directory(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
12441 | | { |
12442 | | PyObject *return_value = NULL; |
12443 | | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
12444 | | |
12445 | | #define NUM_KEYWORDS 1 |
12446 | | static struct { |
12447 | | PyGC_Head _this_is_not_used; |
12448 | | PyObject_VAR_HEAD |
12449 | | Py_hash_t ob_hash; |
12450 | | PyObject *ob_item[NUM_KEYWORDS]; |
12451 | | } _kwtuple = { |
12452 | | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
12453 | | .ob_hash = -1, |
12454 | | .ob_item = { &_Py_ID(path), }, |
12455 | | }; |
12456 | | #undef NUM_KEYWORDS |
12457 | | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
12458 | | |
12459 | | #else // !Py_BUILD_CORE |
12460 | | # define KWTUPLE NULL |
12461 | | #endif // !Py_BUILD_CORE |
12462 | | |
12463 | | static const char * const _keywords[] = {"path", NULL}; |
12464 | | static _PyArg_Parser _parser = { |
12465 | | .keywords = _keywords, |
12466 | | .fname = "_add_dll_directory", |
12467 | | .kwtuple = KWTUPLE, |
12468 | | }; |
12469 | | #undef KWTUPLE |
12470 | | PyObject *argsbuf[1]; |
12471 | | path_t path = PATH_T_INITIALIZE_P("_add_dll_directory", "path", 0, 0, 0, 0); |
12472 | | |
12473 | | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
12474 | | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
12475 | | if (!args) { |
12476 | | goto exit; |
12477 | | } |
12478 | | if (!path_converter(args[0], &path)) { |
12479 | | goto exit; |
12480 | | } |
12481 | | return_value = os__add_dll_directory_impl(module, &path); |
12482 | | |
12483 | | exit: |
12484 | | /* Cleanup for path */ |
12485 | | path_cleanup(&path); |
12486 | | |
12487 | | return return_value; |
12488 | | } |
12489 | | |
12490 | | #endif /* (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM)) */ |
12491 | | |
12492 | | #if (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM)) |
12493 | | |
12494 | | PyDoc_STRVAR(os__remove_dll_directory__doc__, |
12495 | | "_remove_dll_directory($module, /, cookie)\n" |
12496 | | "--\n" |
12497 | | "\n" |
12498 | | "Removes a path from the DLL search path.\n" |
12499 | | "\n" |
12500 | | "The parameter is an opaque value that was returned from\n" |
12501 | | "os.add_dll_directory. You can only remove directories that you added\n" |
12502 | | "yourself."); |
12503 | | |
12504 | | #define OS__REMOVE_DLL_DIRECTORY_METHODDEF \ |
12505 | | {"_remove_dll_directory", _PyCFunction_CAST(os__remove_dll_directory), METH_FASTCALL|METH_KEYWORDS, os__remove_dll_directory__doc__}, |
12506 | | |
12507 | | static PyObject * |
12508 | | os__remove_dll_directory_impl(PyObject *module, PyObject *cookie); |
12509 | | |
12510 | | static PyObject * |
12511 | | os__remove_dll_directory(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
12512 | | { |
12513 | | PyObject *return_value = NULL; |
12514 | | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
12515 | | |
12516 | | #define NUM_KEYWORDS 1 |
12517 | | static struct { |
12518 | | PyGC_Head _this_is_not_used; |
12519 | | PyObject_VAR_HEAD |
12520 | | Py_hash_t ob_hash; |
12521 | | PyObject *ob_item[NUM_KEYWORDS]; |
12522 | | } _kwtuple = { |
12523 | | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
12524 | | .ob_hash = -1, |
12525 | | .ob_item = { &_Py_ID(cookie), }, |
12526 | | }; |
12527 | | #undef NUM_KEYWORDS |
12528 | | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
12529 | | |
12530 | | #else // !Py_BUILD_CORE |
12531 | | # define KWTUPLE NULL |
12532 | | #endif // !Py_BUILD_CORE |
12533 | | |
12534 | | static const char * const _keywords[] = {"cookie", NULL}; |
12535 | | static _PyArg_Parser _parser = { |
12536 | | .keywords = _keywords, |
12537 | | .fname = "_remove_dll_directory", |
12538 | | .kwtuple = KWTUPLE, |
12539 | | }; |
12540 | | #undef KWTUPLE |
12541 | | PyObject *argsbuf[1]; |
12542 | | PyObject *cookie; |
12543 | | |
12544 | | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
12545 | | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
12546 | | if (!args) { |
12547 | | goto exit; |
12548 | | } |
12549 | | cookie = args[0]; |
12550 | | return_value = os__remove_dll_directory_impl(module, cookie); |
12551 | | |
12552 | | exit: |
12553 | | return return_value; |
12554 | | } |
12555 | | |
12556 | | #endif /* (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM)) */ |
12557 | | |
12558 | | #if (defined(WIFEXITED) || defined(MS_WINDOWS)) |
12559 | | |
12560 | | PyDoc_STRVAR(os_waitstatus_to_exitcode__doc__, |
12561 | | "waitstatus_to_exitcode($module, /, status)\n" |
12562 | | "--\n" |
12563 | | "\n" |
12564 | | "Convert a wait status to an exit code.\n" |
12565 | | "\n" |
12566 | | "On Unix:\n" |
12567 | | "\n" |
12568 | | "* If WIFEXITED(status) is true, return WEXITSTATUS(status).\n" |
12569 | | "* If WIFSIGNALED(status) is true, return -WTERMSIG(status).\n" |
12570 | | "* Otherwise, raise a ValueError.\n" |
12571 | | "\n" |
12572 | | "On Windows, return status shifted right by 8 bits.\n" |
12573 | | "\n" |
12574 | | "On Unix, if the process is being traced or if waitpid() was called with\n" |
12575 | | "WUNTRACED option, the caller must first check if WIFSTOPPED(status) is true.\n" |
12576 | | "This function must not be called if WIFSTOPPED(status) is true."); |
12577 | | |
12578 | | #define OS_WAITSTATUS_TO_EXITCODE_METHODDEF \ |
12579 | | {"waitstatus_to_exitcode", _PyCFunction_CAST(os_waitstatus_to_exitcode), METH_FASTCALL|METH_KEYWORDS, os_waitstatus_to_exitcode__doc__}, |
12580 | | |
12581 | | static PyObject * |
12582 | | os_waitstatus_to_exitcode_impl(PyObject *module, PyObject *status_obj); |
12583 | | |
12584 | | static PyObject * |
12585 | | os_waitstatus_to_exitcode(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
12586 | 0 | { |
12587 | 0 | PyObject *return_value = NULL; |
12588 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
12589 | |
|
12590 | 0 | #define NUM_KEYWORDS 1 |
12591 | 0 | static struct { |
12592 | 0 | PyGC_Head _this_is_not_used; |
12593 | 0 | PyObject_VAR_HEAD |
12594 | 0 | Py_hash_t ob_hash; |
12595 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
12596 | 0 | } _kwtuple = { |
12597 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
12598 | 0 | .ob_hash = -1, |
12599 | 0 | .ob_item = { &_Py_ID(status), }, |
12600 | 0 | }; |
12601 | 0 | #undef NUM_KEYWORDS |
12602 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
12603 | |
|
12604 | | #else // !Py_BUILD_CORE |
12605 | | # define KWTUPLE NULL |
12606 | | #endif // !Py_BUILD_CORE |
12607 | |
|
12608 | 0 | static const char * const _keywords[] = {"status", NULL}; |
12609 | 0 | static _PyArg_Parser _parser = { |
12610 | 0 | .keywords = _keywords, |
12611 | 0 | .fname = "waitstatus_to_exitcode", |
12612 | 0 | .kwtuple = KWTUPLE, |
12613 | 0 | }; |
12614 | 0 | #undef KWTUPLE |
12615 | 0 | PyObject *argsbuf[1]; |
12616 | 0 | PyObject *status_obj; |
12617 | |
|
12618 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
12619 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
12620 | 0 | if (!args) { |
12621 | 0 | goto exit; |
12622 | 0 | } |
12623 | 0 | status_obj = args[0]; |
12624 | 0 | return_value = os_waitstatus_to_exitcode_impl(module, status_obj); |
12625 | |
|
12626 | 0 | exit: |
12627 | 0 | return return_value; |
12628 | 0 | } |
12629 | | |
12630 | | #endif /* (defined(WIFEXITED) || defined(MS_WINDOWS)) */ |
12631 | | |
12632 | | #if defined(MS_WINDOWS) |
12633 | | |
12634 | | PyDoc_STRVAR(os__supports_virtual_terminal__doc__, |
12635 | | "_supports_virtual_terminal($module, /)\n" |
12636 | | "--\n" |
12637 | | "\n" |
12638 | | "Checks if virtual terminal is supported in windows"); |
12639 | | |
12640 | | #define OS__SUPPORTS_VIRTUAL_TERMINAL_METHODDEF \ |
12641 | | {"_supports_virtual_terminal", (PyCFunction)os__supports_virtual_terminal, METH_NOARGS, os__supports_virtual_terminal__doc__}, |
12642 | | |
12643 | | static PyObject * |
12644 | | os__supports_virtual_terminal_impl(PyObject *module); |
12645 | | |
12646 | | static PyObject * |
12647 | | os__supports_virtual_terminal(PyObject *module, PyObject *Py_UNUSED(ignored)) |
12648 | | { |
12649 | | return os__supports_virtual_terminal_impl(module); |
12650 | | } |
12651 | | |
12652 | | #endif /* defined(MS_WINDOWS) */ |
12653 | | |
12654 | | PyDoc_STRVAR(os__inputhook__doc__, |
12655 | | "_inputhook($module, /)\n" |
12656 | | "--\n" |
12657 | | "\n" |
12658 | | "Calls PyOS_CallInputHook droppong the GIL first"); |
12659 | | |
12660 | | #define OS__INPUTHOOK_METHODDEF \ |
12661 | | {"_inputhook", (PyCFunction)os__inputhook, METH_NOARGS, os__inputhook__doc__}, |
12662 | | |
12663 | | static PyObject * |
12664 | | os__inputhook_impl(PyObject *module); |
12665 | | |
12666 | | static PyObject * |
12667 | | os__inputhook(PyObject *module, PyObject *Py_UNUSED(ignored)) |
12668 | 0 | { |
12669 | 0 | return os__inputhook_impl(module); |
12670 | 0 | } |
12671 | | |
12672 | | PyDoc_STRVAR(os__is_inputhook_installed__doc__, |
12673 | | "_is_inputhook_installed($module, /)\n" |
12674 | | "--\n" |
12675 | | "\n" |
12676 | | "Checks if PyOS_CallInputHook is set"); |
12677 | | |
12678 | | #define OS__IS_INPUTHOOK_INSTALLED_METHODDEF \ |
12679 | | {"_is_inputhook_installed", (PyCFunction)os__is_inputhook_installed, METH_NOARGS, os__is_inputhook_installed__doc__}, |
12680 | | |
12681 | | static PyObject * |
12682 | | os__is_inputhook_installed_impl(PyObject *module); |
12683 | | |
12684 | | static PyObject * |
12685 | | os__is_inputhook_installed(PyObject *module, PyObject *Py_UNUSED(ignored)) |
12686 | 0 | { |
12687 | 0 | return os__is_inputhook_installed_impl(module); |
12688 | 0 | } |
12689 | | |
12690 | | PyDoc_STRVAR(os__create_environ__doc__, |
12691 | | "_create_environ($module, /)\n" |
12692 | | "--\n" |
12693 | | "\n" |
12694 | | "Create the environment dictionary."); |
12695 | | |
12696 | | #define OS__CREATE_ENVIRON_METHODDEF \ |
12697 | | {"_create_environ", (PyCFunction)os__create_environ, METH_NOARGS, os__create_environ__doc__}, |
12698 | | |
12699 | | static PyObject * |
12700 | | os__create_environ_impl(PyObject *module); |
12701 | | |
12702 | | static PyObject * |
12703 | | os__create_environ(PyObject *module, PyObject *Py_UNUSED(ignored)) |
12704 | 0 | { |
12705 | 0 | return os__create_environ_impl(module); |
12706 | 0 | } |
12707 | | |
12708 | | #if defined(__EMSCRIPTEN__) |
12709 | | |
12710 | | PyDoc_STRVAR(os__emscripten_debugger__doc__, |
12711 | | "_emscripten_debugger($module, /)\n" |
12712 | | "--\n" |
12713 | | "\n" |
12714 | | "Create a breakpoint for the JavaScript debugger. Emscripten only."); |
12715 | | |
12716 | | #define OS__EMSCRIPTEN_DEBUGGER_METHODDEF \ |
12717 | | {"_emscripten_debugger", (PyCFunction)os__emscripten_debugger, METH_NOARGS, os__emscripten_debugger__doc__}, |
12718 | | |
12719 | | static PyObject * |
12720 | | os__emscripten_debugger_impl(PyObject *module); |
12721 | | |
12722 | | static PyObject * |
12723 | | os__emscripten_debugger(PyObject *module, PyObject *Py_UNUSED(ignored)) |
12724 | | { |
12725 | | return os__emscripten_debugger_impl(module); |
12726 | | } |
12727 | | |
12728 | | #endif /* defined(__EMSCRIPTEN__) */ |
12729 | | |
12730 | | #ifndef OS_TTYNAME_METHODDEF |
12731 | | #define OS_TTYNAME_METHODDEF |
12732 | | #endif /* !defined(OS_TTYNAME_METHODDEF) */ |
12733 | | |
12734 | | #ifndef OS_CTERMID_METHODDEF |
12735 | | #define OS_CTERMID_METHODDEF |
12736 | | #endif /* !defined(OS_CTERMID_METHODDEF) */ |
12737 | | |
12738 | | #ifndef OS_FCHDIR_METHODDEF |
12739 | | #define OS_FCHDIR_METHODDEF |
12740 | | #endif /* !defined(OS_FCHDIR_METHODDEF) */ |
12741 | | |
12742 | | #ifndef OS_FCHMOD_METHODDEF |
12743 | | #define OS_FCHMOD_METHODDEF |
12744 | | #endif /* !defined(OS_FCHMOD_METHODDEF) */ |
12745 | | |
12746 | | #ifndef OS_LCHMOD_METHODDEF |
12747 | | #define OS_LCHMOD_METHODDEF |
12748 | | #endif /* !defined(OS_LCHMOD_METHODDEF) */ |
12749 | | |
12750 | | #ifndef OS_CHFLAGS_METHODDEF |
12751 | | #define OS_CHFLAGS_METHODDEF |
12752 | | #endif /* !defined(OS_CHFLAGS_METHODDEF) */ |
12753 | | |
12754 | | #ifndef OS_LCHFLAGS_METHODDEF |
12755 | | #define OS_LCHFLAGS_METHODDEF |
12756 | | #endif /* !defined(OS_LCHFLAGS_METHODDEF) */ |
12757 | | |
12758 | | #ifndef OS_CHROOT_METHODDEF |
12759 | | #define OS_CHROOT_METHODDEF |
12760 | | #endif /* !defined(OS_CHROOT_METHODDEF) */ |
12761 | | |
12762 | | #ifndef OS_FSYNC_METHODDEF |
12763 | | #define OS_FSYNC_METHODDEF |
12764 | | #endif /* !defined(OS_FSYNC_METHODDEF) */ |
12765 | | |
12766 | | #ifndef OS_SYNC_METHODDEF |
12767 | | #define OS_SYNC_METHODDEF |
12768 | | #endif /* !defined(OS_SYNC_METHODDEF) */ |
12769 | | |
12770 | | #ifndef OS_FDATASYNC_METHODDEF |
12771 | | #define OS_FDATASYNC_METHODDEF |
12772 | | #endif /* !defined(OS_FDATASYNC_METHODDEF) */ |
12773 | | |
12774 | | #ifndef OS_CHOWN_METHODDEF |
12775 | | #define OS_CHOWN_METHODDEF |
12776 | | #endif /* !defined(OS_CHOWN_METHODDEF) */ |
12777 | | |
12778 | | #ifndef OS_FCHOWN_METHODDEF |
12779 | | #define OS_FCHOWN_METHODDEF |
12780 | | #endif /* !defined(OS_FCHOWN_METHODDEF) */ |
12781 | | |
12782 | | #ifndef OS_LCHOWN_METHODDEF |
12783 | | #define OS_LCHOWN_METHODDEF |
12784 | | #endif /* !defined(OS_LCHOWN_METHODDEF) */ |
12785 | | |
12786 | | #ifndef OS_LINK_METHODDEF |
12787 | | #define OS_LINK_METHODDEF |
12788 | | #endif /* !defined(OS_LINK_METHODDEF) */ |
12789 | | |
12790 | | #ifndef OS_LISTDRIVES_METHODDEF |
12791 | | #define OS_LISTDRIVES_METHODDEF |
12792 | | #endif /* !defined(OS_LISTDRIVES_METHODDEF) */ |
12793 | | |
12794 | | #ifndef OS_LISTVOLUMES_METHODDEF |
12795 | | #define OS_LISTVOLUMES_METHODDEF |
12796 | | #endif /* !defined(OS_LISTVOLUMES_METHODDEF) */ |
12797 | | |
12798 | | #ifndef OS_LISTMOUNTS_METHODDEF |
12799 | | #define OS_LISTMOUNTS_METHODDEF |
12800 | | #endif /* !defined(OS_LISTMOUNTS_METHODDEF) */ |
12801 | | |
12802 | | #ifndef OS__PATH_ISDEVDRIVE_METHODDEF |
12803 | | #define OS__PATH_ISDEVDRIVE_METHODDEF |
12804 | | #endif /* !defined(OS__PATH_ISDEVDRIVE_METHODDEF) */ |
12805 | | |
12806 | | #ifndef OS__GETFULLPATHNAME_METHODDEF |
12807 | | #define OS__GETFULLPATHNAME_METHODDEF |
12808 | | #endif /* !defined(OS__GETFULLPATHNAME_METHODDEF) */ |
12809 | | |
12810 | | #ifndef OS__GETFINALPATHNAME_METHODDEF |
12811 | | #define OS__GETFINALPATHNAME_METHODDEF |
12812 | | #endif /* !defined(OS__GETFINALPATHNAME_METHODDEF) */ |
12813 | | |
12814 | | #ifndef OS__FINDFIRSTFILE_METHODDEF |
12815 | | #define OS__FINDFIRSTFILE_METHODDEF |
12816 | | #endif /* !defined(OS__FINDFIRSTFILE_METHODDEF) */ |
12817 | | |
12818 | | #ifndef OS__GETVOLUMEPATHNAME_METHODDEF |
12819 | | #define OS__GETVOLUMEPATHNAME_METHODDEF |
12820 | | #endif /* !defined(OS__GETVOLUMEPATHNAME_METHODDEF) */ |
12821 | | |
12822 | | #ifndef OS__PATH_SPLITROOT_METHODDEF |
12823 | | #define OS__PATH_SPLITROOT_METHODDEF |
12824 | | #endif /* !defined(OS__PATH_SPLITROOT_METHODDEF) */ |
12825 | | |
12826 | | #ifndef OS__PATH_EXISTS_METHODDEF |
12827 | | #define OS__PATH_EXISTS_METHODDEF |
12828 | | #endif /* !defined(OS__PATH_EXISTS_METHODDEF) */ |
12829 | | |
12830 | | #ifndef OS__PATH_LEXISTS_METHODDEF |
12831 | | #define OS__PATH_LEXISTS_METHODDEF |
12832 | | #endif /* !defined(OS__PATH_LEXISTS_METHODDEF) */ |
12833 | | |
12834 | | #ifndef OS__PATH_ISDIR_METHODDEF |
12835 | | #define OS__PATH_ISDIR_METHODDEF |
12836 | | #endif /* !defined(OS__PATH_ISDIR_METHODDEF) */ |
12837 | | |
12838 | | #ifndef OS__PATH_ISFILE_METHODDEF |
12839 | | #define OS__PATH_ISFILE_METHODDEF |
12840 | | #endif /* !defined(OS__PATH_ISFILE_METHODDEF) */ |
12841 | | |
12842 | | #ifndef OS__PATH_ISLINK_METHODDEF |
12843 | | #define OS__PATH_ISLINK_METHODDEF |
12844 | | #endif /* !defined(OS__PATH_ISLINK_METHODDEF) */ |
12845 | | |
12846 | | #ifndef OS__PATH_ISJUNCTION_METHODDEF |
12847 | | #define OS__PATH_ISJUNCTION_METHODDEF |
12848 | | #endif /* !defined(OS__PATH_ISJUNCTION_METHODDEF) */ |
12849 | | |
12850 | | #ifndef OS_NICE_METHODDEF |
12851 | | #define OS_NICE_METHODDEF |
12852 | | #endif /* !defined(OS_NICE_METHODDEF) */ |
12853 | | |
12854 | | #ifndef OS_GETPRIORITY_METHODDEF |
12855 | | #define OS_GETPRIORITY_METHODDEF |
12856 | | #endif /* !defined(OS_GETPRIORITY_METHODDEF) */ |
12857 | | |
12858 | | #ifndef OS_SETPRIORITY_METHODDEF |
12859 | | #define OS_SETPRIORITY_METHODDEF |
12860 | | #endif /* !defined(OS_SETPRIORITY_METHODDEF) */ |
12861 | | |
12862 | | #ifndef OS_SYSTEM_METHODDEF |
12863 | | #define OS_SYSTEM_METHODDEF |
12864 | | #endif /* !defined(OS_SYSTEM_METHODDEF) */ |
12865 | | |
12866 | | #ifndef OS_UMASK_METHODDEF |
12867 | | #define OS_UMASK_METHODDEF |
12868 | | #endif /* !defined(OS_UMASK_METHODDEF) */ |
12869 | | |
12870 | | #ifndef OS_UNAME_METHODDEF |
12871 | | #define OS_UNAME_METHODDEF |
12872 | | #endif /* !defined(OS_UNAME_METHODDEF) */ |
12873 | | |
12874 | | #ifndef OS_EXECV_METHODDEF |
12875 | | #define OS_EXECV_METHODDEF |
12876 | | #endif /* !defined(OS_EXECV_METHODDEF) */ |
12877 | | |
12878 | | #ifndef OS_EXECVE_METHODDEF |
12879 | | #define OS_EXECVE_METHODDEF |
12880 | | #endif /* !defined(OS_EXECVE_METHODDEF) */ |
12881 | | |
12882 | | #ifndef OS_POSIX_SPAWN_METHODDEF |
12883 | | #define OS_POSIX_SPAWN_METHODDEF |
12884 | | #endif /* !defined(OS_POSIX_SPAWN_METHODDEF) */ |
12885 | | |
12886 | | #ifndef OS_POSIX_SPAWNP_METHODDEF |
12887 | | #define OS_POSIX_SPAWNP_METHODDEF |
12888 | | #endif /* !defined(OS_POSIX_SPAWNP_METHODDEF) */ |
12889 | | |
12890 | | #ifndef OS_SPAWNV_METHODDEF |
12891 | | #define OS_SPAWNV_METHODDEF |
12892 | | #endif /* !defined(OS_SPAWNV_METHODDEF) */ |
12893 | | |
12894 | | #ifndef OS_SPAWNVE_METHODDEF |
12895 | | #define OS_SPAWNVE_METHODDEF |
12896 | | #endif /* !defined(OS_SPAWNVE_METHODDEF) */ |
12897 | | |
12898 | | #ifndef OS_REGISTER_AT_FORK_METHODDEF |
12899 | | #define OS_REGISTER_AT_FORK_METHODDEF |
12900 | | #endif /* !defined(OS_REGISTER_AT_FORK_METHODDEF) */ |
12901 | | |
12902 | | #ifndef OS_FORK1_METHODDEF |
12903 | | #define OS_FORK1_METHODDEF |
12904 | | #endif /* !defined(OS_FORK1_METHODDEF) */ |
12905 | | |
12906 | | #ifndef OS_FORK_METHODDEF |
12907 | | #define OS_FORK_METHODDEF |
12908 | | #endif /* !defined(OS_FORK_METHODDEF) */ |
12909 | | |
12910 | | #ifndef OS_SCHED_GET_PRIORITY_MAX_METHODDEF |
12911 | | #define OS_SCHED_GET_PRIORITY_MAX_METHODDEF |
12912 | | #endif /* !defined(OS_SCHED_GET_PRIORITY_MAX_METHODDEF) */ |
12913 | | |
12914 | | #ifndef OS_SCHED_GET_PRIORITY_MIN_METHODDEF |
12915 | | #define OS_SCHED_GET_PRIORITY_MIN_METHODDEF |
12916 | | #endif /* !defined(OS_SCHED_GET_PRIORITY_MIN_METHODDEF) */ |
12917 | | |
12918 | | #ifndef OS_SCHED_GETSCHEDULER_METHODDEF |
12919 | | #define OS_SCHED_GETSCHEDULER_METHODDEF |
12920 | | #endif /* !defined(OS_SCHED_GETSCHEDULER_METHODDEF) */ |
12921 | | |
12922 | | #ifndef OS_SCHED_SETSCHEDULER_METHODDEF |
12923 | | #define OS_SCHED_SETSCHEDULER_METHODDEF |
12924 | | #endif /* !defined(OS_SCHED_SETSCHEDULER_METHODDEF) */ |
12925 | | |
12926 | | #ifndef OS_SCHED_GETPARAM_METHODDEF |
12927 | | #define OS_SCHED_GETPARAM_METHODDEF |
12928 | | #endif /* !defined(OS_SCHED_GETPARAM_METHODDEF) */ |
12929 | | |
12930 | | #ifndef OS_SCHED_SETPARAM_METHODDEF |
12931 | | #define OS_SCHED_SETPARAM_METHODDEF |
12932 | | #endif /* !defined(OS_SCHED_SETPARAM_METHODDEF) */ |
12933 | | |
12934 | | #ifndef OS_SCHED_RR_GET_INTERVAL_METHODDEF |
12935 | | #define OS_SCHED_RR_GET_INTERVAL_METHODDEF |
12936 | | #endif /* !defined(OS_SCHED_RR_GET_INTERVAL_METHODDEF) */ |
12937 | | |
12938 | | #ifndef OS_SCHED_YIELD_METHODDEF |
12939 | | #define OS_SCHED_YIELD_METHODDEF |
12940 | | #endif /* !defined(OS_SCHED_YIELD_METHODDEF) */ |
12941 | | |
12942 | | #ifndef OS_SCHED_SETAFFINITY_METHODDEF |
12943 | | #define OS_SCHED_SETAFFINITY_METHODDEF |
12944 | | #endif /* !defined(OS_SCHED_SETAFFINITY_METHODDEF) */ |
12945 | | |
12946 | | #ifndef OS_SCHED_GETAFFINITY_METHODDEF |
12947 | | #define OS_SCHED_GETAFFINITY_METHODDEF |
12948 | | #endif /* !defined(OS_SCHED_GETAFFINITY_METHODDEF) */ |
12949 | | |
12950 | | #ifndef OS_POSIX_OPENPT_METHODDEF |
12951 | | #define OS_POSIX_OPENPT_METHODDEF |
12952 | | #endif /* !defined(OS_POSIX_OPENPT_METHODDEF) */ |
12953 | | |
12954 | | #ifndef OS_GRANTPT_METHODDEF |
12955 | | #define OS_GRANTPT_METHODDEF |
12956 | | #endif /* !defined(OS_GRANTPT_METHODDEF) */ |
12957 | | |
12958 | | #ifndef OS_UNLOCKPT_METHODDEF |
12959 | | #define OS_UNLOCKPT_METHODDEF |
12960 | | #endif /* !defined(OS_UNLOCKPT_METHODDEF) */ |
12961 | | |
12962 | | #ifndef OS_PTSNAME_METHODDEF |
12963 | | #define OS_PTSNAME_METHODDEF |
12964 | | #endif /* !defined(OS_PTSNAME_METHODDEF) */ |
12965 | | |
12966 | | #ifndef OS_OPENPTY_METHODDEF |
12967 | | #define OS_OPENPTY_METHODDEF |
12968 | | #endif /* !defined(OS_OPENPTY_METHODDEF) */ |
12969 | | |
12970 | | #ifndef OS_LOGIN_TTY_METHODDEF |
12971 | | #define OS_LOGIN_TTY_METHODDEF |
12972 | | #endif /* !defined(OS_LOGIN_TTY_METHODDEF) */ |
12973 | | |
12974 | | #ifndef OS_FORKPTY_METHODDEF |
12975 | | #define OS_FORKPTY_METHODDEF |
12976 | | #endif /* !defined(OS_FORKPTY_METHODDEF) */ |
12977 | | |
12978 | | #ifndef OS_GETEGID_METHODDEF |
12979 | | #define OS_GETEGID_METHODDEF |
12980 | | #endif /* !defined(OS_GETEGID_METHODDEF) */ |
12981 | | |
12982 | | #ifndef OS_GETEUID_METHODDEF |
12983 | | #define OS_GETEUID_METHODDEF |
12984 | | #endif /* !defined(OS_GETEUID_METHODDEF) */ |
12985 | | |
12986 | | #ifndef OS_GETGID_METHODDEF |
12987 | | #define OS_GETGID_METHODDEF |
12988 | | #endif /* !defined(OS_GETGID_METHODDEF) */ |
12989 | | |
12990 | | #ifndef OS_GETPID_METHODDEF |
12991 | | #define OS_GETPID_METHODDEF |
12992 | | #endif /* !defined(OS_GETPID_METHODDEF) */ |
12993 | | |
12994 | | #ifndef OS_GETGROUPLIST_METHODDEF |
12995 | | #define OS_GETGROUPLIST_METHODDEF |
12996 | | #endif /* !defined(OS_GETGROUPLIST_METHODDEF) */ |
12997 | | |
12998 | | #ifndef OS_GETGROUPS_METHODDEF |
12999 | | #define OS_GETGROUPS_METHODDEF |
13000 | | #endif /* !defined(OS_GETGROUPS_METHODDEF) */ |
13001 | | |
13002 | | #ifndef OS_INITGROUPS_METHODDEF |
13003 | | #define OS_INITGROUPS_METHODDEF |
13004 | | #endif /* !defined(OS_INITGROUPS_METHODDEF) */ |
13005 | | |
13006 | | #ifndef OS_GETPGID_METHODDEF |
13007 | | #define OS_GETPGID_METHODDEF |
13008 | | #endif /* !defined(OS_GETPGID_METHODDEF) */ |
13009 | | |
13010 | | #ifndef OS_GETPGRP_METHODDEF |
13011 | | #define OS_GETPGRP_METHODDEF |
13012 | | #endif /* !defined(OS_GETPGRP_METHODDEF) */ |
13013 | | |
13014 | | #ifndef OS_SETPGRP_METHODDEF |
13015 | | #define OS_SETPGRP_METHODDEF |
13016 | | #endif /* !defined(OS_SETPGRP_METHODDEF) */ |
13017 | | |
13018 | | #ifndef OS_GETPPID_METHODDEF |
13019 | | #define OS_GETPPID_METHODDEF |
13020 | | #endif /* !defined(OS_GETPPID_METHODDEF) */ |
13021 | | |
13022 | | #ifndef OS_GETLOGIN_METHODDEF |
13023 | | #define OS_GETLOGIN_METHODDEF |
13024 | | #endif /* !defined(OS_GETLOGIN_METHODDEF) */ |
13025 | | |
13026 | | #ifndef OS_GETUID_METHODDEF |
13027 | | #define OS_GETUID_METHODDEF |
13028 | | #endif /* !defined(OS_GETUID_METHODDEF) */ |
13029 | | |
13030 | | #ifndef OS_KILL_METHODDEF |
13031 | | #define OS_KILL_METHODDEF |
13032 | | #endif /* !defined(OS_KILL_METHODDEF) */ |
13033 | | |
13034 | | #ifndef OS_KILLPG_METHODDEF |
13035 | | #define OS_KILLPG_METHODDEF |
13036 | | #endif /* !defined(OS_KILLPG_METHODDEF) */ |
13037 | | |
13038 | | #ifndef OS_PLOCK_METHODDEF |
13039 | | #define OS_PLOCK_METHODDEF |
13040 | | #endif /* !defined(OS_PLOCK_METHODDEF) */ |
13041 | | |
13042 | | #ifndef OS_SETUID_METHODDEF |
13043 | | #define OS_SETUID_METHODDEF |
13044 | | #endif /* !defined(OS_SETUID_METHODDEF) */ |
13045 | | |
13046 | | #ifndef OS_SETEUID_METHODDEF |
13047 | | #define OS_SETEUID_METHODDEF |
13048 | | #endif /* !defined(OS_SETEUID_METHODDEF) */ |
13049 | | |
13050 | | #ifndef OS_SETEGID_METHODDEF |
13051 | | #define OS_SETEGID_METHODDEF |
13052 | | #endif /* !defined(OS_SETEGID_METHODDEF) */ |
13053 | | |
13054 | | #ifndef OS_SETREUID_METHODDEF |
13055 | | #define OS_SETREUID_METHODDEF |
13056 | | #endif /* !defined(OS_SETREUID_METHODDEF) */ |
13057 | | |
13058 | | #ifndef OS_SETREGID_METHODDEF |
13059 | | #define OS_SETREGID_METHODDEF |
13060 | | #endif /* !defined(OS_SETREGID_METHODDEF) */ |
13061 | | |
13062 | | #ifndef OS_SETGID_METHODDEF |
13063 | | #define OS_SETGID_METHODDEF |
13064 | | #endif /* !defined(OS_SETGID_METHODDEF) */ |
13065 | | |
13066 | | #ifndef OS_SETGROUPS_METHODDEF |
13067 | | #define OS_SETGROUPS_METHODDEF |
13068 | | #endif /* !defined(OS_SETGROUPS_METHODDEF) */ |
13069 | | |
13070 | | #ifndef OS_WAIT3_METHODDEF |
13071 | | #define OS_WAIT3_METHODDEF |
13072 | | #endif /* !defined(OS_WAIT3_METHODDEF) */ |
13073 | | |
13074 | | #ifndef OS_WAIT4_METHODDEF |
13075 | | #define OS_WAIT4_METHODDEF |
13076 | | #endif /* !defined(OS_WAIT4_METHODDEF) */ |
13077 | | |
13078 | | #ifndef OS_WAITID_METHODDEF |
13079 | | #define OS_WAITID_METHODDEF |
13080 | | #endif /* !defined(OS_WAITID_METHODDEF) */ |
13081 | | |
13082 | | #ifndef OS_WAITPID_METHODDEF |
13083 | | #define OS_WAITPID_METHODDEF |
13084 | | #endif /* !defined(OS_WAITPID_METHODDEF) */ |
13085 | | |
13086 | | #ifndef OS_WAIT_METHODDEF |
13087 | | #define OS_WAIT_METHODDEF |
13088 | | #endif /* !defined(OS_WAIT_METHODDEF) */ |
13089 | | |
13090 | | #ifndef OS_PIDFD_OPEN_METHODDEF |
13091 | | #define OS_PIDFD_OPEN_METHODDEF |
13092 | | #endif /* !defined(OS_PIDFD_OPEN_METHODDEF) */ |
13093 | | |
13094 | | #ifndef OS_SETNS_METHODDEF |
13095 | | #define OS_SETNS_METHODDEF |
13096 | | #endif /* !defined(OS_SETNS_METHODDEF) */ |
13097 | | |
13098 | | #ifndef OS_UNSHARE_METHODDEF |
13099 | | #define OS_UNSHARE_METHODDEF |
13100 | | #endif /* !defined(OS_UNSHARE_METHODDEF) */ |
13101 | | |
13102 | | #ifndef OS_READLINK_METHODDEF |
13103 | | #define OS_READLINK_METHODDEF |
13104 | | #endif /* !defined(OS_READLINK_METHODDEF) */ |
13105 | | |
13106 | | #ifndef OS_SYMLINK_METHODDEF |
13107 | | #define OS_SYMLINK_METHODDEF |
13108 | | #endif /* !defined(OS_SYMLINK_METHODDEF) */ |
13109 | | |
13110 | | #ifndef OS_TIMERFD_CREATE_METHODDEF |
13111 | | #define OS_TIMERFD_CREATE_METHODDEF |
13112 | | #endif /* !defined(OS_TIMERFD_CREATE_METHODDEF) */ |
13113 | | |
13114 | | #ifndef OS_TIMERFD_SETTIME_METHODDEF |
13115 | | #define OS_TIMERFD_SETTIME_METHODDEF |
13116 | | #endif /* !defined(OS_TIMERFD_SETTIME_METHODDEF) */ |
13117 | | |
13118 | | #ifndef OS_TIMERFD_SETTIME_NS_METHODDEF |
13119 | | #define OS_TIMERFD_SETTIME_NS_METHODDEF |
13120 | | #endif /* !defined(OS_TIMERFD_SETTIME_NS_METHODDEF) */ |
13121 | | |
13122 | | #ifndef OS_TIMERFD_GETTIME_METHODDEF |
13123 | | #define OS_TIMERFD_GETTIME_METHODDEF |
13124 | | #endif /* !defined(OS_TIMERFD_GETTIME_METHODDEF) */ |
13125 | | |
13126 | | #ifndef OS_TIMERFD_GETTIME_NS_METHODDEF |
13127 | | #define OS_TIMERFD_GETTIME_NS_METHODDEF |
13128 | | #endif /* !defined(OS_TIMERFD_GETTIME_NS_METHODDEF) */ |
13129 | | |
13130 | | #ifndef OS_GETSID_METHODDEF |
13131 | | #define OS_GETSID_METHODDEF |
13132 | | #endif /* !defined(OS_GETSID_METHODDEF) */ |
13133 | | |
13134 | | #ifndef OS_SETSID_METHODDEF |
13135 | | #define OS_SETSID_METHODDEF |
13136 | | #endif /* !defined(OS_SETSID_METHODDEF) */ |
13137 | | |
13138 | | #ifndef OS_SETPGID_METHODDEF |
13139 | | #define OS_SETPGID_METHODDEF |
13140 | | #endif /* !defined(OS_SETPGID_METHODDEF) */ |
13141 | | |
13142 | | #ifndef OS_TCGETPGRP_METHODDEF |
13143 | | #define OS_TCGETPGRP_METHODDEF |
13144 | | #endif /* !defined(OS_TCGETPGRP_METHODDEF) */ |
13145 | | |
13146 | | #ifndef OS_TCSETPGRP_METHODDEF |
13147 | | #define OS_TCSETPGRP_METHODDEF |
13148 | | #endif /* !defined(OS_TCSETPGRP_METHODDEF) */ |
13149 | | |
13150 | | #ifndef OS_DUP2_METHODDEF |
13151 | | #define OS_DUP2_METHODDEF |
13152 | | #endif /* !defined(OS_DUP2_METHODDEF) */ |
13153 | | |
13154 | | #ifndef OS_LOCKF_METHODDEF |
13155 | | #define OS_LOCKF_METHODDEF |
13156 | | #endif /* !defined(OS_LOCKF_METHODDEF) */ |
13157 | | |
13158 | | #ifndef OS_READV_METHODDEF |
13159 | | #define OS_READV_METHODDEF |
13160 | | #endif /* !defined(OS_READV_METHODDEF) */ |
13161 | | |
13162 | | #ifndef OS_PREAD_METHODDEF |
13163 | | #define OS_PREAD_METHODDEF |
13164 | | #endif /* !defined(OS_PREAD_METHODDEF) */ |
13165 | | |
13166 | | #ifndef OS_PREADV_METHODDEF |
13167 | | #define OS_PREADV_METHODDEF |
13168 | | #endif /* !defined(OS_PREADV_METHODDEF) */ |
13169 | | |
13170 | | #ifndef OS_SENDFILE_METHODDEF |
13171 | | #define OS_SENDFILE_METHODDEF |
13172 | | #endif /* !defined(OS_SENDFILE_METHODDEF) */ |
13173 | | |
13174 | | #ifndef OS__FCOPYFILE_METHODDEF |
13175 | | #define OS__FCOPYFILE_METHODDEF |
13176 | | #endif /* !defined(OS__FCOPYFILE_METHODDEF) */ |
13177 | | |
13178 | | #ifndef OS_PIPE_METHODDEF |
13179 | | #define OS_PIPE_METHODDEF |
13180 | | #endif /* !defined(OS_PIPE_METHODDEF) */ |
13181 | | |
13182 | | #ifndef OS_PIPE2_METHODDEF |
13183 | | #define OS_PIPE2_METHODDEF |
13184 | | #endif /* !defined(OS_PIPE2_METHODDEF) */ |
13185 | | |
13186 | | #ifndef OS_WRITEV_METHODDEF |
13187 | | #define OS_WRITEV_METHODDEF |
13188 | | #endif /* !defined(OS_WRITEV_METHODDEF) */ |
13189 | | |
13190 | | #ifndef OS_PWRITE_METHODDEF |
13191 | | #define OS_PWRITE_METHODDEF |
13192 | | #endif /* !defined(OS_PWRITE_METHODDEF) */ |
13193 | | |
13194 | | #ifndef OS_PWRITEV_METHODDEF |
13195 | | #define OS_PWRITEV_METHODDEF |
13196 | | #endif /* !defined(OS_PWRITEV_METHODDEF) */ |
13197 | | |
13198 | | #ifndef OS_COPY_FILE_RANGE_METHODDEF |
13199 | | #define OS_COPY_FILE_RANGE_METHODDEF |
13200 | | #endif /* !defined(OS_COPY_FILE_RANGE_METHODDEF) */ |
13201 | | |
13202 | | #ifndef OS_SPLICE_METHODDEF |
13203 | | #define OS_SPLICE_METHODDEF |
13204 | | #endif /* !defined(OS_SPLICE_METHODDEF) */ |
13205 | | |
13206 | | #ifndef OS_MKFIFO_METHODDEF |
13207 | | #define OS_MKFIFO_METHODDEF |
13208 | | #endif /* !defined(OS_MKFIFO_METHODDEF) */ |
13209 | | |
13210 | | #ifndef OS_MKNOD_METHODDEF |
13211 | | #define OS_MKNOD_METHODDEF |
13212 | | #endif /* !defined(OS_MKNOD_METHODDEF) */ |
13213 | | |
13214 | | #ifndef OS_MAJOR_METHODDEF |
13215 | | #define OS_MAJOR_METHODDEF |
13216 | | #endif /* !defined(OS_MAJOR_METHODDEF) */ |
13217 | | |
13218 | | #ifndef OS_MINOR_METHODDEF |
13219 | | #define OS_MINOR_METHODDEF |
13220 | | #endif /* !defined(OS_MINOR_METHODDEF) */ |
13221 | | |
13222 | | #ifndef OS_MAKEDEV_METHODDEF |
13223 | | #define OS_MAKEDEV_METHODDEF |
13224 | | #endif /* !defined(OS_MAKEDEV_METHODDEF) */ |
13225 | | |
13226 | | #ifndef OS_FTRUNCATE_METHODDEF |
13227 | | #define OS_FTRUNCATE_METHODDEF |
13228 | | #endif /* !defined(OS_FTRUNCATE_METHODDEF) */ |
13229 | | |
13230 | | #ifndef OS_TRUNCATE_METHODDEF |
13231 | | #define OS_TRUNCATE_METHODDEF |
13232 | | #endif /* !defined(OS_TRUNCATE_METHODDEF) */ |
13233 | | |
13234 | | #ifndef OS_POSIX_FALLOCATE_METHODDEF |
13235 | | #define OS_POSIX_FALLOCATE_METHODDEF |
13236 | | #endif /* !defined(OS_POSIX_FALLOCATE_METHODDEF) */ |
13237 | | |
13238 | | #ifndef OS_POSIX_FADVISE_METHODDEF |
13239 | | #define OS_POSIX_FADVISE_METHODDEF |
13240 | | #endif /* !defined(OS_POSIX_FADVISE_METHODDEF) */ |
13241 | | |
13242 | | #ifndef OS_PUTENV_METHODDEF |
13243 | | #define OS_PUTENV_METHODDEF |
13244 | | #endif /* !defined(OS_PUTENV_METHODDEF) */ |
13245 | | |
13246 | | #ifndef OS_UNSETENV_METHODDEF |
13247 | | #define OS_UNSETENV_METHODDEF |
13248 | | #endif /* !defined(OS_UNSETENV_METHODDEF) */ |
13249 | | |
13250 | | #ifndef OS_WCOREDUMP_METHODDEF |
13251 | | #define OS_WCOREDUMP_METHODDEF |
13252 | | #endif /* !defined(OS_WCOREDUMP_METHODDEF) */ |
13253 | | |
13254 | | #ifndef OS_WIFCONTINUED_METHODDEF |
13255 | | #define OS_WIFCONTINUED_METHODDEF |
13256 | | #endif /* !defined(OS_WIFCONTINUED_METHODDEF) */ |
13257 | | |
13258 | | #ifndef OS_WIFSTOPPED_METHODDEF |
13259 | | #define OS_WIFSTOPPED_METHODDEF |
13260 | | #endif /* !defined(OS_WIFSTOPPED_METHODDEF) */ |
13261 | | |
13262 | | #ifndef OS_WIFSIGNALED_METHODDEF |
13263 | | #define OS_WIFSIGNALED_METHODDEF |
13264 | | #endif /* !defined(OS_WIFSIGNALED_METHODDEF) */ |
13265 | | |
13266 | | #ifndef OS_WIFEXITED_METHODDEF |
13267 | | #define OS_WIFEXITED_METHODDEF |
13268 | | #endif /* !defined(OS_WIFEXITED_METHODDEF) */ |
13269 | | |
13270 | | #ifndef OS_WEXITSTATUS_METHODDEF |
13271 | | #define OS_WEXITSTATUS_METHODDEF |
13272 | | #endif /* !defined(OS_WEXITSTATUS_METHODDEF) */ |
13273 | | |
13274 | | #ifndef OS_WTERMSIG_METHODDEF |
13275 | | #define OS_WTERMSIG_METHODDEF |
13276 | | #endif /* !defined(OS_WTERMSIG_METHODDEF) */ |
13277 | | |
13278 | | #ifndef OS_WSTOPSIG_METHODDEF |
13279 | | #define OS_WSTOPSIG_METHODDEF |
13280 | | #endif /* !defined(OS_WSTOPSIG_METHODDEF) */ |
13281 | | |
13282 | | #ifndef OS_FSTATVFS_METHODDEF |
13283 | | #define OS_FSTATVFS_METHODDEF |
13284 | | #endif /* !defined(OS_FSTATVFS_METHODDEF) */ |
13285 | | |
13286 | | #ifndef OS_STATVFS_METHODDEF |
13287 | | #define OS_STATVFS_METHODDEF |
13288 | | #endif /* !defined(OS_STATVFS_METHODDEF) */ |
13289 | | |
13290 | | #ifndef OS__GETDISKUSAGE_METHODDEF |
13291 | | #define OS__GETDISKUSAGE_METHODDEF |
13292 | | #endif /* !defined(OS__GETDISKUSAGE_METHODDEF) */ |
13293 | | |
13294 | | #ifndef OS_FPATHCONF_METHODDEF |
13295 | | #define OS_FPATHCONF_METHODDEF |
13296 | | #endif /* !defined(OS_FPATHCONF_METHODDEF) */ |
13297 | | |
13298 | | #ifndef OS_PATHCONF_METHODDEF |
13299 | | #define OS_PATHCONF_METHODDEF |
13300 | | #endif /* !defined(OS_PATHCONF_METHODDEF) */ |
13301 | | |
13302 | | #ifndef OS_CONFSTR_METHODDEF |
13303 | | #define OS_CONFSTR_METHODDEF |
13304 | | #endif /* !defined(OS_CONFSTR_METHODDEF) */ |
13305 | | |
13306 | | #ifndef OS_SYSCONF_METHODDEF |
13307 | | #define OS_SYSCONF_METHODDEF |
13308 | | #endif /* !defined(OS_SYSCONF_METHODDEF) */ |
13309 | | |
13310 | | #ifndef OS_STARTFILE_METHODDEF |
13311 | | #define OS_STARTFILE_METHODDEF |
13312 | | #endif /* !defined(OS_STARTFILE_METHODDEF) */ |
13313 | | |
13314 | | #ifndef OS_GETLOADAVG_METHODDEF |
13315 | | #define OS_GETLOADAVG_METHODDEF |
13316 | | #endif /* !defined(OS_GETLOADAVG_METHODDEF) */ |
13317 | | |
13318 | | #ifndef OS_SETRESUID_METHODDEF |
13319 | | #define OS_SETRESUID_METHODDEF |
13320 | | #endif /* !defined(OS_SETRESUID_METHODDEF) */ |
13321 | | |
13322 | | #ifndef OS_SETRESGID_METHODDEF |
13323 | | #define OS_SETRESGID_METHODDEF |
13324 | | #endif /* !defined(OS_SETRESGID_METHODDEF) */ |
13325 | | |
13326 | | #ifndef OS_GETRESUID_METHODDEF |
13327 | | #define OS_GETRESUID_METHODDEF |
13328 | | #endif /* !defined(OS_GETRESUID_METHODDEF) */ |
13329 | | |
13330 | | #ifndef OS_GETRESGID_METHODDEF |
13331 | | #define OS_GETRESGID_METHODDEF |
13332 | | #endif /* !defined(OS_GETRESGID_METHODDEF) */ |
13333 | | |
13334 | | #ifndef OS_GETXATTR_METHODDEF |
13335 | | #define OS_GETXATTR_METHODDEF |
13336 | | #endif /* !defined(OS_GETXATTR_METHODDEF) */ |
13337 | | |
13338 | | #ifndef OS_SETXATTR_METHODDEF |
13339 | | #define OS_SETXATTR_METHODDEF |
13340 | | #endif /* !defined(OS_SETXATTR_METHODDEF) */ |
13341 | | |
13342 | | #ifndef OS_REMOVEXATTR_METHODDEF |
13343 | | #define OS_REMOVEXATTR_METHODDEF |
13344 | | #endif /* !defined(OS_REMOVEXATTR_METHODDEF) */ |
13345 | | |
13346 | | #ifndef OS_LISTXATTR_METHODDEF |
13347 | | #define OS_LISTXATTR_METHODDEF |
13348 | | #endif /* !defined(OS_LISTXATTR_METHODDEF) */ |
13349 | | |
13350 | | #ifndef OS_MEMFD_CREATE_METHODDEF |
13351 | | #define OS_MEMFD_CREATE_METHODDEF |
13352 | | #endif /* !defined(OS_MEMFD_CREATE_METHODDEF) */ |
13353 | | |
13354 | | #ifndef OS_EVENTFD_METHODDEF |
13355 | | #define OS_EVENTFD_METHODDEF |
13356 | | #endif /* !defined(OS_EVENTFD_METHODDEF) */ |
13357 | | |
13358 | | #ifndef OS_EVENTFD_READ_METHODDEF |
13359 | | #define OS_EVENTFD_READ_METHODDEF |
13360 | | #endif /* !defined(OS_EVENTFD_READ_METHODDEF) */ |
13361 | | |
13362 | | #ifndef OS_EVENTFD_WRITE_METHODDEF |
13363 | | #define OS_EVENTFD_WRITE_METHODDEF |
13364 | | #endif /* !defined(OS_EVENTFD_WRITE_METHODDEF) */ |
13365 | | |
13366 | | #ifndef OS_GET_TERMINAL_SIZE_METHODDEF |
13367 | | #define OS_GET_TERMINAL_SIZE_METHODDEF |
13368 | | #endif /* !defined(OS_GET_TERMINAL_SIZE_METHODDEF) */ |
13369 | | |
13370 | | #ifndef OS_GET_HANDLE_INHERITABLE_METHODDEF |
13371 | | #define OS_GET_HANDLE_INHERITABLE_METHODDEF |
13372 | | #endif /* !defined(OS_GET_HANDLE_INHERITABLE_METHODDEF) */ |
13373 | | |
13374 | | #ifndef OS_SET_HANDLE_INHERITABLE_METHODDEF |
13375 | | #define OS_SET_HANDLE_INHERITABLE_METHODDEF |
13376 | | #endif /* !defined(OS_SET_HANDLE_INHERITABLE_METHODDEF) */ |
13377 | | |
13378 | | #ifndef OS_GETRANDOM_METHODDEF |
13379 | | #define OS_GETRANDOM_METHODDEF |
13380 | | #endif /* !defined(OS_GETRANDOM_METHODDEF) */ |
13381 | | |
13382 | | #ifndef OS__ADD_DLL_DIRECTORY_METHODDEF |
13383 | | #define OS__ADD_DLL_DIRECTORY_METHODDEF |
13384 | | #endif /* !defined(OS__ADD_DLL_DIRECTORY_METHODDEF) */ |
13385 | | |
13386 | | #ifndef OS__REMOVE_DLL_DIRECTORY_METHODDEF |
13387 | | #define OS__REMOVE_DLL_DIRECTORY_METHODDEF |
13388 | | #endif /* !defined(OS__REMOVE_DLL_DIRECTORY_METHODDEF) */ |
13389 | | |
13390 | | #ifndef OS_WAITSTATUS_TO_EXITCODE_METHODDEF |
13391 | | #define OS_WAITSTATUS_TO_EXITCODE_METHODDEF |
13392 | | #endif /* !defined(OS_WAITSTATUS_TO_EXITCODE_METHODDEF) */ |
13393 | | |
13394 | | #ifndef OS__SUPPORTS_VIRTUAL_TERMINAL_METHODDEF |
13395 | | #define OS__SUPPORTS_VIRTUAL_TERMINAL_METHODDEF |
13396 | | #endif /* !defined(OS__SUPPORTS_VIRTUAL_TERMINAL_METHODDEF) */ |
13397 | | |
13398 | | #ifndef OS__EMSCRIPTEN_DEBUGGER_METHODDEF |
13399 | | #define OS__EMSCRIPTEN_DEBUGGER_METHODDEF |
13400 | | #endif /* !defined(OS__EMSCRIPTEN_DEBUGGER_METHODDEF) */ |
13401 | | /*[clinic end generated code: output=ae64df0389746258 input=a9049054013a1b77]*/ |