Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1271)

Side by Side Diff: Modules/posixmodule.c

Issue 10812: Add some posix functions
Patch Set: Created 2 years, 2 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Lib/test/test_posix.py ('k') | configure.in » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 /* POSIX module implementation */ 2 /* POSIX module implementation */
3 3
4 /* This file is also used for Windows NT/MS-Win and OS/2. In that case the 4 /* This file is also used for Windows NT/MS-Win and OS/2. In that case the
5 module actually calls itself 'nt' or 'os2', not 'posix', and a few 5 module actually calls itself 'nt' or 'os2', not 'posix', and a few
6 functions are either unimplemented or implemented differently. The source 6 functions are either unimplemented or implemented differently. The source
7 assumes that for Windows NT, the macro 'MS_WINDOWS' is defined independent 7 assumes that for Windows NT, the macro 'MS_WINDOWS' is defined independent
8 of the compiler used. Different compilers define their own feature 8 of the compiler used. Different compilers define their own feature
9 test macro, e.g. '__BORLANDC__' or '_MSC_VER'. For OS/2, the compiler 9 test macro, e.g. '__BORLANDC__' or '_MSC_VER'. For OS/2, the compiler
10 independent macro PYOS_OS2 should be defined. On OS/2 the default 10 independent macro PYOS_OS2 should be defined. On OS/2 the default
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 #define INCL_DOSPROCESS 50 #define INCL_DOSPROCESS
51 #define INCL_NOPMAPI 51 #define INCL_NOPMAPI
52 #include <os2.h> 52 #include <os2.h>
53 #if defined(PYCC_GCC) 53 #if defined(PYCC_GCC)
54 #include <ctype.h> 54 #include <ctype.h>
55 #include <io.h> 55 #include <io.h>
56 #include <stdio.h> 56 #include <stdio.h>
57 #include <process.h> 57 #include <process.h>
58 #endif 58 #endif
59 #include "osdefs.h" 59 #include "osdefs.h"
60 #endif
61
62 #ifdef HAVE_SYS_UIO_H
63 #include <sys/uio.h>
60 #endif 64 #endif
61 65
62 #ifdef HAVE_SYS_TYPES_H 66 #ifdef HAVE_SYS_TYPES_H
63 #include <sys/types.h> 67 #include <sys/types.h>
64 #endif /* HAVE_SYS_TYPES_H */ 68 #endif /* HAVE_SYS_TYPES_H */
65 69
66 #ifdef HAVE_SYS_STAT_H 70 #ifdef HAVE_SYS_STAT_H
67 #include <sys/stat.h> 71 #include <sys/stat.h>
68 #endif /* HAVE_SYS_STAT_H */ 72 #endif /* HAVE_SYS_STAT_H */
69 73
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 #if defined(MAJOR_IN_MKDEV) 343 #if defined(MAJOR_IN_MKDEV)
340 #include <sys/mkdev.h> 344 #include <sys/mkdev.h>
341 #else 345 #else
342 #if defined(MAJOR_IN_SYSMACROS) 346 #if defined(MAJOR_IN_SYSMACROS)
343 #include <sys/sysmacros.h> 347 #include <sys/sysmacros.h>
344 #endif 348 #endif
345 #if defined(HAVE_MKNOD) && defined(HAVE_SYS_MKDEV_H) 349 #if defined(HAVE_MKNOD) && defined(HAVE_SYS_MKDEV_H)
346 #include <sys/mkdev.h> 350 #include <sys/mkdev.h>
347 #endif 351 #endif
348 #endif 352 #endif
353
354 #if !defined(HAVE_LARGEFILE_SUPPORT)
355 #define PARSE_OFF_T_NO_ERROR(x, xobj) x = PyLong_AsLong(xobj);
356 #else
357 #define PARSE_OFF_T_NO_ERROR(x, xobj) x = PyLong_Check(xobj) ? \
358 PyLong_AsLongLong(xobj) : PyLong_AsLong(xobj)
359 #endif
360 #define PARSE_OFF_T(x, xobj) PARSE_OFF_T_NO_ERROR(x, xobj) \
361 if (PyErr_Occurred()) \
362 return NULL;
349 363
350 #if defined _MSC_VER && _MSC_VER >= 1400 364 #if defined _MSC_VER && _MSC_VER >= 1400
351 /* Microsoft CRT in VS2005 and higher will verify that a filehandle is 365 /* Microsoft CRT in VS2005 and higher will verify that a filehandle is
352 * valid and throw an assertion if it isn't. 366 * valid and throw an assertion if it isn't.
353 * Normally, an invalid fd is likely to be a C program error and therefore 367 * Normally, an invalid fd is likely to be a C program error and therefore
354 * an assertion can be useful, but it does contradict the POSIX standard 368 * an assertion can be useful, but it does contradict the POSIX standard
355 * which for write(2) states: 369 * which for write(2) states:
356 * "Otherwise, -1 shall be returned and errno set to indicate the error." 370 * "Otherwise, -1 shall be returned and errno set to indicate the error."
357 * "[EBADF] The fildes argument is not a valid file descriptor open for 371 * "[EBADF] The fildes argument is not a valid file descriptor open for
358 * writing." 372 * writing."
(...skipping 1706 matching lines...) Expand 10 before | Expand all | Expand 10 after
2065 PyDoc_STRVAR(posix_fsync__doc__, 2079 PyDoc_STRVAR(posix_fsync__doc__,
2066 "fsync(fildes)\n\n\ 2080 "fsync(fildes)\n\n\
2067 force write of file with filedescriptor to disk."); 2081 force write of file with filedescriptor to disk.");
2068 2082
2069 static PyObject * 2083 static PyObject *
2070 posix_fsync(PyObject *self, PyObject *fdobj) 2084 posix_fsync(PyObject *self, PyObject *fdobj)
2071 { 2085 {
2072 return posix_fildes(fdobj, fsync); 2086 return posix_fildes(fdobj, fsync);
2073 } 2087 }
2074 #endif /* HAVE_FSYNC */ 2088 #endif /* HAVE_FSYNC */
2089
2090 #ifdef HAVE_SYNC
2091 PyDoc_STRVAR(posix_sync__doc__,
2092 "sync()\n\n\
2093 Force write of everything to disk.");
2094
2095 static PyObject *
2096 posix_sync(PyObject *self, PyObject *noargs)
2097 {
2098 Py_BEGIN_ALLOW_THREADS
2099 sync();
2100 Py_END_ALLOW_THREADS
2101 Py_RETURN_NONE;
2102 }
2103 #endif
2075 2104
2076 #ifdef HAVE_FDATASYNC 2105 #ifdef HAVE_FDATASYNC
2077 2106
2078 #ifdef __hpux 2107 #ifdef __hpux
2079 extern int fdatasync(int); /* On HP-UX, in libc but not in unistd.h */ 2108 extern int fdatasync(int); /* On HP-UX, in libc but not in unistd.h */
2080 #endif 2109 #endif
2081 2110
2082 PyDoc_STRVAR(posix_fdatasync__doc__, 2111 PyDoc_STRVAR(posix_fdatasync__doc__,
2083 "fdatasync(fildes)\n\n\ 2112 "fdatasync(fildes)\n\n\
2084 force write of file with filedescriptor to disk.\n\ 2113 force write of file with filedescriptor to disk.\n\
(...skipping 1250 matching lines...) Expand 10 before | Expand all | Expand 10 after
3335 } 3364 }
3336 Py_DECREF(opath); 3365 Py_DECREF(opath);
3337 Py_INCREF(Py_None); 3366 Py_INCREF(Py_None);
3338 return Py_None; 3367 return Py_None;
3339 #undef UTIME_ARG 3368 #undef UTIME_ARG
3340 #undef ATIME 3369 #undef ATIME
3341 #undef MTIME 3370 #undef MTIME
3342 #endif /* MS_WINDOWS */ 3371 #endif /* MS_WINDOWS */
3343 } 3372 }
3344 3373
3374 #ifdef HAVE_FUTIMES
3375 PyDoc_STRVAR(posix_futimes__doc__,
3376 "futimes(fd, (atime, mtime))\n\
3377 futimes(fd, None)\n\n\
3378 Set the access and modified time of the file specified by the file\n\
3379 descriptor fd to the given values. If the second form is used, set the\n\
3380 access and modified times to the current time.");
3381
3382 static PyObject *
3383 posix_futimes(PyObject *self, PyObject *args)
3384 {
3385 int res, fd;
3386 PyObject* arg;
3387 struct timeval buf[2];
3388
3389 if (!PyArg_ParseTuple(args, "iO:futimes", &fd, &arg))
3390 return NULL;
3391
3392 if (arg == Py_None) {
3393 /* optional time values not given */
3394 Py_BEGIN_ALLOW_THREADS
3395 res = futimes(fd, NULL);
3396 Py_END_ALLOW_THREADS
3397 }
3398 else if (!PyTuple_Check(arg) || PyTuple_Size(arg) != 2) {
3399 PyErr_SetString(PyExc_TypeError,
3400 "futimes() arg 2 must be a tuple (atime, mtime)");
3401 return NULL;
3402 }
3403 else {
3404 if (extract_time(PyTuple_GET_ITEM(arg, 0),
3405 &(buf[0].tv_sec), &(buf[0].tv_usec)) == -1) {
3406 return NULL;
3407 }
3408 if (extract_time(PyTuple_GET_ITEM(arg, 1),
3409 &(buf[1].tv_sec), &(buf[1].tv_usec)) == -1) {
3410 return NULL;
3411 }
3412 Py_BEGIN_ALLOW_THREADS
3413 res = futimes(fd, buf);
3414 Py_END_ALLOW_THREADS
3415 }
3416 if (res < 0)
3417 return posix_error();
3418 Py_RETURN_NONE;
3419 }
3420 #endif
3421
3422 #ifdef HAVE_LUTIMES
3423 PyDoc_STRVAR(posix_lutimes__doc__,
3424 "lutimes(path, (atime, mtime))\n\
3425 lutimes(path, None)\n\n\
3426 Like utime(), but if path is a symbolic link, it is not dereferenced.");
3427
3428 static PyObject *
3429 posix_lutimes(PyObject *self, PyObject *args)
3430 {
3431 PyObject *opath, *arg;
3432 const char *path;
3433 int res;
3434 struct timeval buf[2];
3435
3436 if (!PyArg_ParseTuple(args, "O&O:lutimes",
3437 PyUnicode_FSConverter, &opath, &arg))
3438 return NULL;
3439 path = PyBytes_AsString(opath);
3440 if (arg == Py_None) {
3441 /* optional time values not given */
3442 Py_BEGIN_ALLOW_THREADS
3443 res = lutimes(path, NULL);
3444 Py_END_ALLOW_THREADS
3445 }
3446 else if (!PyTuple_Check(arg) || PyTuple_Size(arg) != 2) {
3447 PyErr_SetString(PyExc_TypeError,
3448 "lutimes() arg 2 must be a tuple (atime, mtime)");
3449 Py_DECREF(opath);
3450 return NULL;
3451 }
3452 else {
3453 if (extract_time(PyTuple_GET_ITEM(arg, 0),
3454 &(buf[0].tv_sec), &(buf[0].tv_usec)) == -1) {
3455 Py_DECREF(opath);
3456 return NULL;
3457 }
3458 if (extract_time(PyTuple_GET_ITEM(arg, 1),
3459 &(buf[1].tv_sec), &(buf[1].tv_usec)) == -1) {
3460 Py_DECREF(opath);
3461 return NULL;
3462 }
3463 Py_BEGIN_ALLOW_THREADS
3464 res = lutimes(path, buf);
3465 Py_END_ALLOW_THREADS
3466 }
3467 Py_DECREF(opath);
3468 if (res < 0)
3469 return posix_error();
3470 Py_RETURN_NONE;
3471 }
3472 #endif
3473
3474 #ifdef HAVE_FUTIMENS
3475 PyDoc_STRVAR(posix_futimens__doc__,
3476 "futimens(fd, (atime_sec, atime_nsec), (mtime_sec, mtime_nsec))\n\
3477 futimens(fd, None, None)\n\n\
3478 Updates the timestamps of a file specified by the file descriptor fd, with\n\
3479 nanosecond precision.\n\
3480 The second form sets atime and mtime to the current time.\n\
3481 If *_nsec is specified as UTIME_NOW, the timestamp is updated to the\n\
3482 current time.\n\
3483 If *_nsec is specified as UTIME_OMIT, the timestamp is not updated.");
3484
3485 static PyObject *
3486 posix_futimens(PyObject *self, PyObject *args)
3487 {
3488 int res, fd;
3489 PyObject *atime, *mtime;
3490 struct timespec buf[2];
3491
3492 if (!PyArg_ParseTuple(args, "iOO:futimens",
3493 &fd, &atime, &mtime))
3494 return NULL;
3495 if (atime == Py_None && mtime == Py_None) {
3496 /* optional time values not given */
3497 Py_BEGIN_ALLOW_THREADS
3498 res = futimens(fd, NULL);
3499 Py_END_ALLOW_THREADS
3500 }
3501 else if (!PyTuple_Check(atime) || PyTuple_Size(atime) != 2) {
3502 PyErr_SetString(PyExc_TypeError,
3503 "futimens() arg 2 must be a tuple (atime_sec, atime_nsec)");
3504 return NULL;
3505 }
3506 else if (!PyTuple_Check(mtime) || PyTuple_Size(mtime) != 2) {
3507 PyErr_SetString(PyExc_TypeError,
3508 "futimens() arg 3 must be a tuple (mtime_sec, mtime_nsec)");
3509 return NULL;
3510 }
3511 else {
3512 if (!PyArg_ParseTuple(atime, "ll:futimens",
3513 &(buf[0].tv_sec), &(buf[0].tv_nsec))) {
3514 return NULL;
3515 }
3516 if (!PyArg_ParseTuple(mtime, "ll:futimens",
3517 &(buf[1].tv_sec), &(buf[1].tv_nsec))) {
3518 return NULL;
3519 }
3520 Py_BEGIN_ALLOW_THREADS
3521 res = futimens(fd, buf);
3522 Py_END_ALLOW_THREADS
3523 }
3524 if (res < 0)
3525 return posix_error();
3526 Py_RETURN_NONE;
3527 }
3528 #endif
3345 3529
3346 /* Process operations */ 3530 /* Process operations */
3347 3531
3348 PyDoc_STRVAR(posix__exit__doc__, 3532 PyDoc_STRVAR(posix__exit__doc__,
3349 "_exit(status)\n\n\ 3533 "_exit(status)\n\n\
3350 Exit to the system with specified status, without normal exit processing."); 3534 Exit to the system with specified status, without normal exit processing.");
3351 3535
3352 static PyObject * 3536 static PyObject *
3353 posix__exit(PyObject *self, PyObject *args) 3537 posix__exit(PyObject *self, PyObject *args)
3354 { 3538 {
(...skipping 24 matching lines...) Expand all
3379 size = PyBytes_GET_SIZE(bytes); 3563 size = PyBytes_GET_SIZE(bytes);
3380 *out = PyMem_Malloc(size+1); 3564 *out = PyMem_Malloc(size+1);
3381 if (!*out) 3565 if (!*out)
3382 return 0; 3566 return 0;
3383 memcpy(*out, PyBytes_AsString(bytes), size+1); 3567 memcpy(*out, PyBytes_AsString(bytes), size+1);
3384 Py_DECREF(bytes); 3568 Py_DECREF(bytes);
3385 return 1; 3569 return 1;
3386 } 3570 }
3387 #endif 3571 #endif
3388 3572
3389 3573 #if defined(HAVE_EXECV) || defined (HAVE_FEXECVE)
3390 #ifdef HAVE_EXECV
3391 PyDoc_STRVAR(posix_execv__doc__,
3392 "execv(path, args)\n\n\
3393 Execute an executable path with arguments, replacing current process.\n\
3394 \n\
3395 path: path of executable file\n\
3396 args: tuple or list of strings");
3397
3398 static PyObject *
3399 posix_execv(PyObject *self, PyObject *args)
3400 {
3401 PyObject *opath;
3402 char *path;
3403 PyObject *argv;
3404 char **argvlist;
3405 Py_ssize_t i, argc;
3406 PyObject *(*getitem)(PyObject *, Py_ssize_t);
3407
3408 /* execv has two arguments: (path, argv), where
3409 argv is a list or tuple of strings. */
3410
3411 if (!PyArg_ParseTuple(args, "O&O:execv",
3412 PyUnicode_FSConverter,
3413 &opath, &argv))
3414 return NULL;
3415 path = PyBytes_AsString(opath);
3416 if (PyList_Check(argv)) {
3417 argc = PyList_Size(argv);
3418 getitem = PyList_GetItem;
3419 }
3420 else if (PyTuple_Check(argv)) {
3421 argc = PyTuple_Size(argv);
3422 getitem = PyTuple_GetItem;
3423 }
3424 else {
3425 PyErr_SetString(PyExc_TypeError, "execv() arg 2 must be a tuple or list" );
3426 Py_DECREF(opath);
3427 return NULL;
3428 }
3429 if (argc < 1) {
3430 PyErr_SetString(PyExc_ValueError, "execv() arg 2 must not be empty");
3431 Py_DECREF(opath);
3432 return NULL;
3433 }
3434
3435 argvlist = PyMem_NEW(char *, argc+1);
3436 if (argvlist == NULL) {
3437 Py_DECREF(opath);
3438 return PyErr_NoMemory();
3439 }
3440 for (i = 0; i < argc; i++) {
3441 if (!fsconvert_strdup((*getitem)(argv, i),
3442 &argvlist[i])) {
3443 free_string_array(argvlist, i);
3444 PyErr_SetString(PyExc_TypeError,
3445 "execv() arg 2 must contain only strings");
3446 Py_DECREF(opath);
3447 return NULL;
3448
3449 }
3450 }
3451 argvlist[argc] = NULL;
3452
3453 execv(path, argvlist);
3454
3455 /* If we get here it's definitely an error */
3456
3457 free_string_array(argvlist, argc);
3458 Py_DECREF(opath);
3459 return posix_error();
3460 }
3461
3462 static char** 3574 static char**
3463 parse_envlist(PyObject* env, Py_ssize_t *envc_ptr) 3575 parse_envlist(PyObject* env, Py_ssize_t *envc_ptr)
3464 { 3576 {
3465 char **envlist; 3577 char **envlist;
3466 Py_ssize_t i, pos, envc; 3578 Py_ssize_t i, pos, envc;
3467 PyObject *keys=NULL, *vals=NULL; 3579 PyObject *keys=NULL, *vals=NULL;
3468 PyObject *key, *val, *key2, *val2; 3580 PyObject *key, *val, *key2, *val2;
3469 char *p, *k, *v; 3581 char *p, *k, *v;
3470 size_t len; 3582 size_t len;
3471 3583
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
3531 *envc_ptr = envc; 3643 *envc_ptr = envc;
3532 return envlist; 3644 return envlist;
3533 3645
3534 error: 3646 error:
3535 Py_XDECREF(keys); 3647 Py_XDECREF(keys);
3536 Py_XDECREF(vals); 3648 Py_XDECREF(vals);
3537 while (--envc >= 0) 3649 while (--envc >= 0)
3538 PyMem_DEL(envlist[envc]); 3650 PyMem_DEL(envlist[envc]);
3539 PyMem_DEL(envlist); 3651 PyMem_DEL(envlist);
3540 return NULL; 3652 return NULL;
3653 }
3654
3655 static char**
3656 parse_arglist(PyObject* argv, Py_ssize_t *argc)
3657 {
3658 int i;
3659 char **argvlist = PyMem_NEW(char *, *argc+1);
3660 if (argvlist == NULL) {
3661 PyErr_NoMemory();
3662 return NULL;
3663 }
3664 for (i = 0; i < *argc; i++) {
3665 if (!fsconvert_strdup(PySequence_ITEM(argv, i),
3666 &argvlist[i]))
3667 {
3668 *argc = i;
3669 goto fail;
3670 }
3671 }
3672 argvlist[*argc] = NULL;
3673 return argvlist;
3674 fail:
3675 free_string_array(argvlist, *argc);
3676 return NULL;
3677 }
3678 #endif
3679
3680 #ifdef HAVE_EXECV
3681 PyDoc_STRVAR(posix_execv__doc__,
3682 "execv(path, args)\n\n\
3683 Execute an executable path with arguments, replacing current process.\n\
3684 \n\
3685 path: path of executable file\n\
3686 args: tuple or list of strings");
3687
3688 static PyObject *
3689 posix_execv(PyObject *self, PyObject *args)
3690 {
3691 PyObject *opath;
3692 char *path;
3693 PyObject *argv;
3694 char **argvlist;
3695 Py_ssize_t argc;
3696
3697 /* execv has two arguments: (path, argv), where
3698 argv is a list or tuple of strings. */
3699
3700 if (!PyArg_ParseTuple(args, "O&O:execv",
3701 PyUnicode_FSConverter,
3702 &opath, &argv))
3703 return NULL;
3704 path = PyBytes_AsString(opath);
3705 if (!PyList_Check(argv) && !PyTuple_Check(argv)) {
3706 PyErr_SetString(PyExc_TypeError,
3707 "execv() arg 2 must be a tuple or list");
3708 Py_DECREF(opath);
3709 return NULL;
3710 }
3711 argc = PySequence_Size(argv);
3712 if (argc < 1) {
3713 PyErr_SetString(PyExc_ValueError, "execv() arg 2 must not be empty");
3714 Py_DECREF(opath);
3715 return NULL;
3716 }
3717
3718 argvlist = parse_arglist(argv, &argc);
3719 if (argvlist == NULL) {
3720 Py_DECREF(opath);
3721 return NULL;
3722 }
3723
3724 execv(path, argvlist);
3725
3726 /* If we get here it's definitely an error */
3727
3728 free_string_array(argvlist, argc);
3729 Py_DECREF(opath);
3730 return posix_error();
3541 } 3731 }
3542 3732
3543 PyDoc_STRVAR(posix_execve__doc__, 3733 PyDoc_STRVAR(posix_execve__doc__,
3544 "execve(path, args, env)\n\n\ 3734 "execve(path, args, env)\n\n\
3545 Execute a path with arguments and environment, replacing current process.\n\ 3735 Execute a path with arguments and environment, replacing current process.\n\
3546 \n\ 3736 \n\
3547 path: path of executable file\n\ 3737 path: path of executable file\n\
3548 args: tuple or list of arguments\n\ 3738 args: tuple or list of arguments\n\
3549 env: dictionary of strings mapping to strings"); 3739 env: dictionary of strings mapping to strings");
3550 3740
3551 static PyObject * 3741 static PyObject *
3552 posix_execve(PyObject *self, PyObject *args) 3742 posix_execve(PyObject *self, PyObject *args)
3553 { 3743 {
3554 PyObject *opath; 3744 PyObject *opath;
3555 char *path; 3745 char *path;
3556 PyObject *argv, *env; 3746 PyObject *argv, *env;
3557 char **argvlist; 3747 char **argvlist;
3558 char **envlist; 3748 char **envlist;
3559 Py_ssize_t i, argc, envc; 3749 Py_ssize_t argc, envc;
3560 PyObject *(*getitem)(PyObject *, Py_ssize_t);
3561 Py_ssize_t lastarg = 0;
3562 3750
3563 /* execve has three arguments: (path, argv, env), where 3751 /* execve has three arguments: (path, argv, env), where
3564 argv is a list or tuple of strings and env is a dictionary 3752 argv is a list or tuple of strings and env is a dictionary
3565 like posix.environ. */ 3753 like posix.environ. */
3566 3754
3567 if (!PyArg_ParseTuple(args, "O&OO:execve", 3755 if (!PyArg_ParseTuple(args, "O&OO:execve",
3568 PyUnicode_FSConverter, 3756 PyUnicode_FSConverter,
3569 &opath, &argv, &env)) 3757 &opath, &argv, &env))
3570 return NULL; 3758 return NULL;
3571 path = PyBytes_AsString(opath); 3759 path = PyBytes_AsString(opath);
3572 if (PyList_Check(argv)) { 3760 if (!PyList_Check(argv) && !PyTuple_Check(argv)) {
3573 argc = PyList_Size(argv);
3574 getitem = PyList_GetItem;
3575 }
3576 else if (PyTuple_Check(argv)) {
3577 argc = PyTuple_Size(argv);
3578 getitem = PyTuple_GetItem;
3579 }
3580 else {
3581 PyErr_SetString(PyExc_TypeError, 3761 PyErr_SetString(PyExc_TypeError,
3582 "execve() arg 2 must be a tuple or list"); 3762 "execve() arg 2 must be a tuple or list");
3583 goto fail_0; 3763 goto fail_0;
3584 } 3764 }
3765 argc = PySequence_Size(argv);
3585 if (!PyMapping_Check(env)) { 3766 if (!PyMapping_Check(env)) {
3586 PyErr_SetString(PyExc_TypeError, 3767 PyErr_SetString(PyExc_TypeError,
3587 "execve() arg 3 must be a mapping object"); 3768 "execve() arg 3 must be a mapping object");
3588 goto fail_0; 3769 goto fail_0;
3589 } 3770 }
3590 3771
3591 argvlist = PyMem_NEW(char *, argc+1); 3772 argvlist = parse_arglist(argv, &argc);
3592 if (argvlist == NULL) { 3773 if (argvlist == NULL) {
3593 PyErr_NoMemory();
3594 goto fail_0; 3774 goto fail_0;
3595 } 3775 }
3596 for (i = 0; i < argc; i++) {
3597 if (!fsconvert_strdup((*getitem)(argv, i),
3598 &argvlist[i]))
3599 {
3600 lastarg = i;
3601 goto fail_1;
3602 }
3603 }
3604 lastarg = argc;
3605 argvlist[argc] = NULL;
3606 3776
3607 envlist = parse_envlist(env, &envc); 3777 envlist = parse_envlist(env, &envc);
3608 if (envlist == NULL) 3778 if (envlist == NULL)
3609 goto fail_1; 3779 goto fail_1;
3610 3780
3611 execve(path, argvlist, envlist); 3781 execve(path, argvlist, envlist);
3612 3782
3613 /* If we get here it's definitely an error */ 3783 /* If we get here it's definitely an error */
3614 3784
3615 (void) posix_error(); 3785 (void) posix_error();
3616 3786
3617 while (--envc >= 0) 3787 while (--envc >= 0)
3618 PyMem_DEL(envlist[envc]); 3788 PyMem_DEL(envlist[envc]);
3619 PyMem_DEL(envlist); 3789 PyMem_DEL(envlist);
3620 fail_1: 3790 fail_1:
3621 free_string_array(argvlist, lastarg); 3791 free_string_array(argvlist, argc);
3622 fail_0: 3792 fail_0:
3623 Py_DECREF(opath); 3793 Py_DECREF(opath);
3624 return NULL; 3794 return NULL;
3625 } 3795 }
3626 #endif /* HAVE_EXECV */ 3796 #endif /* HAVE_EXECV */
3627 3797
3798 #ifdef HAVE_FEXECVE
3799 PyDoc_STRVAR(posix_fexecve__doc__,
3800 "fexecve(fd, args, env)\n\n\
3801 Execute the program specified by a file descriptor with arguments and\n\
3802 environment, replacing the current process.\n\
3803 \n\
3804 fd: file descriptor of executable\n\
3805 args: tuple or list of arguments\n\
3806 env: dictionary of strings mapping to strings");
3807
3808 static PyObject *
3809 posix_fexecve(PyObject *self, PyObject *args)
3810 {
3811 int fd;
3812 PyObject *argv, *env;
3813 char **argvlist;
3814 char **envlist;
3815 Py_ssize_t argc, envc;
3816
3817 if (!PyArg_ParseTuple(args, "iOO:fexecve",
3818 &fd, &argv, &env))
3819 return NULL;
3820 if (!PyList_Check(argv) && !PyTuple_Check(argv)) {
3821 PyErr_SetString(PyExc_TypeError,
3822 "fexecve() arg 2 must be a tuple or list");
3823 return NULL;
3824 }
3825 argc = PySequence_Size(argv);
3826 if (!PyMapping_Check(env)) {
3827 PyErr_SetString(PyExc_TypeError,
3828 "fexecve() arg 3 must be a mapping object");
3829 return NULL;
3830 }
3831
3832 argvlist = parse_arglist(argv, &argc);
3833 if (argvlist == NULL)
3834 return NULL;
3835
3836 envlist = parse_envlist(env, &envc);
3837 if (envlist == NULL)
3838 goto fail;
3839
3840 fexecve(fd, argvlist, envlist);
3841
3842 /* If we get here it's definitely an error */
3843
3844 (void) posix_error();
3845
3846 while (--envc >= 0)
3847 PyMem_DEL(envlist[envc]);
3848 PyMem_DEL(envlist);
3849 fail:
3850 free_string_array(argvlist, argc);
3851 return NULL;
3852 }
3853 #endif /* HAVE_FEXECVE */
3628 3854
3629 #ifdef HAVE_SPAWNV 3855 #ifdef HAVE_SPAWNV
3630 PyDoc_STRVAR(posix_spawnv__doc__, 3856 PyDoc_STRVAR(posix_spawnv__doc__,
3631 "spawnv(mode, path, args)\n\n\ 3857 "spawnv(mode, path, args)\n\n\
3632 Execute the program 'path' in a new process.\n\ 3858 Execute the program 'path' in a new process.\n\
3633 \n\ 3859 \n\
3634 mode: mode of process creation\n\ 3860 mode: mode of process creation\n\
3635 path: path of executable file\n\ 3861 path: path of executable file\n\
3636 args: tuple or list of strings"); 3862 args: tuple or list of strings");
3637 3863
(...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after
4181 } 4407 }
4182 if (pid == -1) 4408 if (pid == -1)
4183 return posix_error(); 4409 return posix_error();
4184 if (result < 0) { 4410 if (result < 0) {
4185 /* Don't clobber the OSError if the fork failed. */ 4411 /* Don't clobber the OSError if the fork failed. */
4186 PyErr_SetString(PyExc_RuntimeError, 4412 PyErr_SetString(PyExc_RuntimeError,
4187 "not holding the import lock"); 4413 "not holding the import lock");
4188 return NULL; 4414 return NULL;
4189 } 4415 }
4190 return Py_BuildValue("(Ni)", PyLong_FromPid(pid), master_fd); 4416 return Py_BuildValue("(Ni)", PyLong_FromPid(pid), master_fd);
4417 }
4418 #endif
4419
4420 #ifdef HAVE_GETHOSTID
4421 PyDoc_STRVAR(posix_gethostid__doc__,
4422 "gethostid() -> hostid\n\n\
4423 Gets the host id, a unique 32-bit identifier for the current machine.");
4424
4425 static PyObject *
4426 posix_gethostid(PyObject *self, PyObject *noargs)
4427 {
4428 return PyLong_FromLong(gethostid());
4429 }
4430 #endif
4431
4432 #ifdef HAVE_SETHOSTNAME
4433 PyDoc_STRVAR(posix_sethostname__doc__,
4434 "sethostname(name)\n\n\
4435 Sets the hostname to name.");
4436
4437 static PyObject *
4438 posix_sethostname(PyObject *self, PyObject *args)
4439 {
4440 const char *hostname;
4441 if (!PyArg_ParseTuple(args, "s:sethostname", &hostname))
4442 return NULL;
4443
4444 if (sethostname(hostname, strlen(hostname)) == -1)
4445 return posix_error();
4446 Py_RETURN_NONE;
4191 } 4447 }
4192 #endif 4448 #endif
4193 4449
4194 #ifdef HAVE_GETEGID 4450 #ifdef HAVE_GETEGID
4195 PyDoc_STRVAR(posix_getegid__doc__, 4451 PyDoc_STRVAR(posix_getegid__doc__,
4196 "getegid() -> egid\n\n\ 4452 "getegid() -> egid\n\n\
4197 Return the current process's effective group id."); 4453 Return the current process's effective group id.");
4198 4454
4199 static PyObject * 4455 static PyObject *
4200 posix_getegid(PyObject *self, PyObject *noargs) 4456 posix_getegid(PyObject *self, PyObject *noargs)
(...skipping 772 matching lines...) Expand 10 before | Expand all | Expand 10 after
4973 if (!PyArg_ParseTuple(args, _Py_PARSE_PID "i:wait4", &pid, &options)) 5229 if (!PyArg_ParseTuple(args, _Py_PARSE_PID "i:wait4", &pid, &options))
4974 return NULL; 5230 return NULL;
4975 5231
4976 Py_BEGIN_ALLOW_THREADS 5232 Py_BEGIN_ALLOW_THREADS
4977 pid = wait4(pid, &status, options, &ru); 5233 pid = wait4(pid, &status, options, &ru);
4978 Py_END_ALLOW_THREADS 5234 Py_END_ALLOW_THREADS
4979 5235
4980 return wait_helper(pid, WAIT_STATUS_INT(status), &ru); 5236 return wait_helper(pid, WAIT_STATUS_INT(status), &ru);
4981 } 5237 }
4982 #endif /* HAVE_WAIT4 */ 5238 #endif /* HAVE_WAIT4 */
5239
5240 #ifdef HAVE_WAITID
5241 PyDoc_STRVAR(posix_waitid__doc__,
5242 "waitid(idtype, id, options) -> siginfo\n\n\
5243 Wait for the completion of one or more child processes.\n\n\
5244 idtype can be P_PID, P_PGID or P_ALL.\n\
5245 id specifies the pid to wait on.\
5246 options is constructed from the ORing of one or more of WEXITED, WSTOPPED\n\
5247 or WCONTINUED and additionally may be ORed with WNOHANG or WNOWAIT.\n\
5248 siginfo is a tuple containing the same data as siginfo_t in the POSIX\n\
5249 specification.");
5250
5251 static PyObject *
5252 posix_waitid(PyObject *self, PyObject *args)
5253 {
5254 idtype_t idtype;
5255 id_t id;
5256 int options, res;
5257 siginfo_t si;
5258 if (!PyArg_ParseTuple(args, "lli:waitid", &idtype, &id, &options))
5259 return NULL;
5260 Py_BEGIN_ALLOW_THREADS
5261 res = waitid(idtype, id, &si, options);
5262 Py_END_ALLOW_THREADS
5263 if (res == -1)
5264 return posix_error();
5265
5266 return Py_BuildValue("iiililill", si.si_signo, si.si_code,
5267 si.si_errno, si.si_pid, si.si_uid, si.si_addr, si.si_status,
5268 si.si_band, si.si_value);
5269 }
5270 #endif
4983 5271
4984 #ifdef HAVE_WAITPID 5272 #ifdef HAVE_WAITPID
4985 PyDoc_STRVAR(posix_waitpid__doc__, 5273 PyDoc_STRVAR(posix_waitpid__doc__,
4986 "waitpid(pid, options) -> (pid, status)\n\n\ 5274 "waitpid(pid, options) -> (pid, status)\n\n\
4987 Wait for completion of a given child process."); 5275 Wait for completion of a given child process.");
4988 5276
4989 static PyObject * 5277 static PyObject *
4990 posix_waitpid(PyObject *self, PyObject *args) 5278 posix_waitpid(PyObject *self, PyObject *args)
4991 { 5279 {
4992 pid_t pid; 5280 pid_t pid;
(...skipping 595 matching lines...) Expand 10 before | Expand all | Expand 10 after
5588 if (!_PyVerify_fd_dup2(fd, fd2)) 5876 if (!_PyVerify_fd_dup2(fd, fd2))
5589 return posix_error(); 5877 return posix_error();
5590 Py_BEGIN_ALLOW_THREADS 5878 Py_BEGIN_ALLOW_THREADS
5591 res = dup2(fd, fd2); 5879 res = dup2(fd, fd2);
5592 Py_END_ALLOW_THREADS 5880 Py_END_ALLOW_THREADS
5593 if (res < 0) 5881 if (res < 0)
5594 return posix_error(); 5882 return posix_error();
5595 Py_INCREF(Py_None); 5883 Py_INCREF(Py_None);
5596 return Py_None; 5884 return Py_None;
5597 } 5885 }
5886
5887 #ifdef HAVE_LOCKF
5888 PyDoc_STRVAR(posix_lockf__doc__,
5889 "lockf(fd, cmd, len)\n\n\
5890 Apply, test or remove a POSIX lock on an open file descriptor.\n\n\
5891 fd is an open file descriptor.\n\
5892 cmd specifies the command to use - one of F_LOCK, F_TLOCK, F_ULOCK or\n\
5893 F_TEST.\n\
5894 len specifies the section of the file to lock.");
5895
5896 static PyObject *
5897 posix_lockf(PyObject *self, PyObject *args)
5898 {
5899 int fd, cmd, res;
5900 off_t len;
5901 PyObject *lenobj;
5902 if (!PyArg_ParseTuple(args, "iiO:lockf",
5903 &fd, &cmd, &lenobj))
5904 return NULL;
5905
5906 PARSE_OFF_T(len, lenobj)
5907
5908 Py_BEGIN_ALLOW_THREADS
5909 res = lockf(fd, cmd, len);
5910 Py_END_ALLOW_THREADS
5911
5912 if (res < 0)
5913 return posix_error();
5914
5915 Py_RETURN_NONE;
5916 }
5917 #endif
5598 5918
5599 5919
5600 PyDoc_STRVAR(posix_lseek__doc__, 5920 PyDoc_STRVAR(posix_lseek__doc__,
5601 "lseek(fd, pos, how) -> newpos\n\n\ 5921 "lseek(fd, pos, how) -> newpos\n\n\
5602 Set the current position of a file descriptor."); 5922 Set the current position of a file descriptor.");
5603 5923
5604 static PyObject * 5924 static PyObject *
5605 posix_lseek(PyObject *self, PyObject *args) 5925 posix_lseek(PyObject *self, PyObject *args)
5606 { 5926 {
5607 int fd, how; 5927 int fd, how;
5608 #if defined(MS_WIN64) || defined(MS_WINDOWS) 5928 #if defined(MS_WIN64) || defined(MS_WINDOWS)
5609 PY_LONG_LONG pos, res; 5929 PY_LONG_LONG pos, res;
5610 #else 5930 #else
5611 off_t pos, res; 5931 off_t pos, res;
5612 #endif 5932 #endif
5613 PyObject *posobj; 5933 PyObject *posobj;
5614 if (!PyArg_ParseTuple(args, "iOi:lseek", &fd, &posobj, &how)) 5934 if (!PyArg_ParseTuple(args, "iOi:lseek", &fd, &posobj, &how))
5615 return NULL; 5935 return NULL;
5616 #ifdef SEEK_SET 5936 #ifdef SEEK_SET
5617 /* Turn 0, 1, 2 into SEEK_{SET,CUR,END} */ 5937 /* Turn 0, 1, 2 into SEEK_{SET,CUR,END} */
5618 switch (how) { 5938 switch (how) {
5619 case 0: how = SEEK_SET; break; 5939 case 0: how = SEEK_SET; break;
5620 case 1: how = SEEK_CUR; break; 5940 case 1: how = SEEK_CUR; break;
5621 case 2: how = SEEK_END; break; 5941 case 2: how = SEEK_END; break;
5622 } 5942 }
5623 #endif /* SEEK_END */ 5943 #endif /* SEEK_END */
5624 5944
5625 #if !defined(HAVE_LARGEFILE_SUPPORT) 5945 PARSE_OFF_T(pos, posobj)
5626 pos = PyLong_AsLong(posobj);
5627 #else
5628 pos = PyLong_Check(posobj) ?
5629 PyLong_AsLongLong(posobj) : PyLong_AsLong(posobj);
5630 #endif
5631 if (PyErr_Occurred())
5632 return NULL;
5633 5946
5634 if (!_PyVerify_fd(fd)) 5947 if (!_PyVerify_fd(fd))
5635 return posix_error(); 5948 return posix_error();
5636 Py_BEGIN_ALLOW_THREADS 5949 Py_BEGIN_ALLOW_THREADS
5637 #if defined(MS_WIN64) || defined(MS_WINDOWS) 5950 #if defined(MS_WIN64) || defined(MS_WINDOWS)
5638 res = _lseeki64(fd, pos, how); 5951 res = _lseeki64(fd, pos, how);
5639 #else 5952 #else
5640 res = lseek(fd, pos, how); 5953 res = lseek(fd, pos, how);
5641 #endif 5954 #endif
5642 Py_END_ALLOW_THREADS 5955 Py_END_ALLOW_THREADS
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
5679 Py_END_ALLOW_THREADS 5992 Py_END_ALLOW_THREADS
5680 if (n < 0) { 5993 if (n < 0) {
5681 Py_DECREF(buffer); 5994 Py_DECREF(buffer);
5682 return posix_error(); 5995 return posix_error();
5683 } 5996 }
5684 if (n != size) 5997 if (n != size)
5685 _PyBytes_Resize(&buffer, n); 5998 _PyBytes_Resize(&buffer, n);
5686 return buffer; 5999 return buffer;
5687 } 6000 }
5688 6001
6002 #if defined(HAVE_READV) || defined(HAVE_WRITEV)
6003 static int
6004 iov_setup(struct iovec **iov, Py_buffer **buf, PyObject *seq, int cnt, int type)
6005 {
6006 int i, j;
6007 *iov = PyMem_New(struct iovec, cnt);
6008 if (*iov == NULL) {
6009 PyErr_NoMemory();
6010 return 0;
6011 }
6012 *buf = PyMem_New(Py_buffer, cnt);
6013 if (*buf == NULL) {
6014 PyMem_Del(*iov);
6015 PyErr_NoMemory();
6016 return 0;
6017 }
6018
6019 for (i = 0; i < cnt; i++) {
6020 if (PyObject_GetBuffer(PySequence_GetItem(seq, i), &(*buf)[i],
6021 type) == -1) {
6022 PyMem_Del(*iov);
6023 for (j = 0; j < i; j++) {
6024 PyBuffer_Release(&(*buf)[j]);
6025 }
6026 PyMem_Del(*buf);
6027 return 0;
6028 }
6029 (*iov)[i].iov_base = (*buf)[i].buf;
6030 (*iov)[i].iov_len = (*buf)[i].len;
6031 }
6032 return 1;
6033 }
6034
6035 static void
6036 iov_cleanup(struct iovec *iov, Py_buffer *buf, int cnt)
6037 {
6038 int i;
6039 PyMem_Del(iov);
6040 for (i = 0; i < cnt; i++) {
6041 PyBuffer_Release(&buf[i]);
6042 }
6043 PyMem_Del(buf);
6044 }
6045 #endif
6046
6047 #ifdef HAVE_READV
6048 PyDoc_STRVAR(posix_readv__doc__,
6049 "readv(fd, buffers) -> bytesread\n\n\
6050 Read from a file descriptor into a number of writable buffers. buffers\n\
6051 is an arbitrary sequence of writable buffers.\n\
6052 Returns the total number of bytes read.");
6053
6054 static PyObject *
6055 posix_readv(PyObject *self, PyObject *args)
6056 {
6057 int fd, cnt;
6058 Py_ssize_t n;
6059 PyObject *seq;
6060 struct iovec *iov;
6061 Py_buffer *buf;
6062
6063 if (!PyArg_ParseTuple(args, "iO:readv", &fd, &seq))
6064 return NULL;
6065 if (!PySequence_Check(seq)) {
6066 PyErr_SetString(PyExc_TypeError,
6067 "readv() arg 2 must be a sequence");
6068 return NULL;
6069 }
6070 cnt = PySequence_Size(seq);
6071
6072 if (!iov_setup(&iov, &buf, seq, cnt, PyBUF_WRITABLE))
6073 return NULL;
6074
6075 Py_BEGIN_ALLOW_THREADS
6076 n = readv(fd, iov, cnt);
6077 Py_END_ALLOW_THREADS
6078
6079 iov_cleanup(iov, buf, cnt);
6080 return PyLong_FromSsize_t(n);
6081 }
6082 #endif
6083
6084 #ifdef HAVE_PREAD
6085 PyDoc_STRVAR(posix_pread__doc__,
6086 "pread(fd, buffersize, offset) -> string\n\n\
6087 Read from a file descriptor, fd, at a position of offset. It will read up\n\
6088 to buffersize number of bytes. The file offset remains unchanged.");
6089
6090 static PyObject *
6091 posix_pread(PyObject *self, PyObject *args)
6092 {
6093 int fd, size;
6094 off_t offset;
6095 Py_ssize_t n;
6096 PyObject *buffer, *offobj;
6097 if (!PyArg_ParseTuple(args, "iiO:pread", &fd, &size, &offobj))
6098 return NULL;
6099
6100 PARSE_OFF_T(offset, offobj)
6101
6102 if (size < 0) {
6103 errno = EINVAL;
6104 return posix_error();
6105 }
6106 buffer = PyBytes_FromStringAndSize((char *)NULL, size);
6107 if (buffer == NULL)
6108 return NULL;
6109 if (!_PyVerify_fd(fd)) {
6110 Py_DECREF(buffer);
6111 return posix_error();
6112 }
6113 Py_BEGIN_ALLOW_THREADS
6114 n = pread(fd, PyBytes_AS_STRING(buffer), size, offset);
6115 Py_END_ALLOW_THREADS
6116 if (n < 0) {
6117 Py_DECREF(buffer);
6118 return posix_error();
6119 }
6120 if (n != size)
6121 _PyBytes_Resize(&buffer, n);
6122 return buffer;
6123 }
6124 #endif
5689 6125
5690 PyDoc_STRVAR(posix_write__doc__, 6126 PyDoc_STRVAR(posix_write__doc__,
5691 "write(fd, string) -> byteswritten\n\n\ 6127 "write(fd, string) -> byteswritten\n\n\
5692 Write a string to a file descriptor."); 6128 Write a string to a file descriptor.");
5693 6129
5694 static PyObject * 6130 static PyObject *
5695 posix_write(PyObject *self, PyObject *args) 6131 posix_write(PyObject *self, PyObject *args)
5696 { 6132 {
5697 Py_buffer pbuf; 6133 Py_buffer pbuf;
5698 int fd; 6134 int fd;
(...skipping 14 matching lines...) Expand all
5713 #else 6149 #else
5714 size = write(fd, pbuf.buf, (size_t)len); 6150 size = write(fd, pbuf.buf, (size_t)len);
5715 #endif 6151 #endif
5716 Py_END_ALLOW_THREADS 6152 Py_END_ALLOW_THREADS
5717 PyBuffer_Release(&pbuf); 6153 PyBuffer_Release(&pbuf);
5718 if (size < 0) 6154 if (size < 0)
5719 return posix_error(); 6155 return posix_error();
5720 return PyLong_FromSsize_t(size); 6156 return PyLong_FromSsize_t(size);
5721 } 6157 }
5722 6158
6159 #ifdef HAVE_WRITEV
6160 PyDoc_STRVAR(posix_writev__doc__,
6161 "writev(fd, buffers) -> byteswritten\n\n\
6162 Write the contents of buffers to a file descriptor, where buffers is an\n\
6163 arbitrary sequence of buffers.\n\
6164 Returns the total bytes written.");
6165
6166 static PyObject *
6167 posix_writev(PyObject *self, PyObject *args)
6168 {
6169 int fd, cnt;
6170 Py_ssize_t res;
6171 PyObject *seq;
6172 struct iovec *iov;
6173 Py_buffer *buf;
6174 if (!PyArg_ParseTuple(args, "iO:writev", &fd, &seq))
6175 return NULL;
6176 if (!PySequence_Check(seq)) {
6177 PyErr_SetString(PyExc_TypeError,
6178 "writev() arg 2 must be a sequence");
6179 return NULL;
6180 }
6181 cnt = PySequence_Size(seq);
6182
6183 if (!iov_setup(&iov, &buf, seq, cnt, PyBUF_SIMPLE)) {
6184 return NULL;
6185 }
6186
6187 Py_BEGIN_ALLOW_THREADS
6188 res = writev(fd, iov, cnt);
6189 Py_END_ALLOW_THREADS
6190
6191 iov_cleanup(iov, buf, cnt);
6192 return PyLong_FromSsize_t(res);
6193 }
6194 #endif
6195
6196 #ifdef HAVE_PWRITE
6197 PyDoc_STRVAR(posix_pwrite__doc__,
6198 "pwrite(fd, string, offset) -> byteswritten\n\n\
6199 Write string to a file descriptor, fd, from offset, leaving the file\n\
6200 offset unchanged.");
6201
6202 static PyObject *
6203 posix_pwrite(PyObject *self, PyObject *args)
6204 {
6205 Py_buffer pbuf;
6206 int fd;
6207 off_t offset;
6208 Py_ssize_t size;
6209 PyObject *offobj;
6210
6211 if (!PyArg_ParseTuple(args, "iy*O:pwrite", &fd, &pbuf, &offobj))
6212 return NULL;
6213
6214 PARSE_OFF_T(offset, offobj)
6215
6216 if (!_PyVerify_fd(fd)) {
6217 PyBuffer_Release(&pbuf);
6218 return posix_error();
6219 }
6220 Py_BEGIN_ALLOW_THREADS
6221 size = pwrite(fd, pbuf.buf, (size_t)pbuf.len, offset);
6222 Py_END_ALLOW_THREADS
6223 PyBuffer_Release(&pbuf);
6224 if (size < 0)
6225 return posix_error();
6226 return PyLong_FromSsize_t(size);
6227 }
6228 #endif
5723 6229
5724 PyDoc_STRVAR(posix_fstat__doc__, 6230 PyDoc_STRVAR(posix_fstat__doc__,
5725 "fstat(fd) -> stat result\n\n\ 6231 "fstat(fd) -> stat result\n\n\
5726 Like stat(), but for an open file descriptor."); 6232 Like stat(), but for an open file descriptor.");
5727 6233
5728 static PyObject * 6234 static PyObject *
5729 posix_fstat(PyObject *self, PyObject *args) 6235 posix_fstat(PyObject *self, PyObject *args)
5730 { 6236 {
5731 int fd; 6237 int fd;
5732 STRUCT_STAT st; 6238 STRUCT_STAT st;
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
5929 posix_ftruncate(PyObject *self, PyObject *args) 6435 posix_ftruncate(PyObject *self, PyObject *args)
5930 { 6436 {
5931 int fd; 6437 int fd;
5932 off_t length; 6438 off_t length;
5933 int res; 6439 int res;
5934 PyObject *lenobj; 6440 PyObject *lenobj;
5935 6441
5936 if (!PyArg_ParseTuple(args, "iO:ftruncate", &fd, &lenobj)) 6442 if (!PyArg_ParseTuple(args, "iO:ftruncate", &fd, &lenobj))
5937 return NULL; 6443 return NULL;
5938 6444
5939 #if !defined(HAVE_LARGEFILE_SUPPORT) 6445 PARSE_OFF_T(length, lenobj)
5940 length = PyLong_AsLong(lenobj);
5941 #else
5942 length = PyLong_Check(lenobj) ?
5943 PyLong_AsLongLong(lenobj) : PyLong_AsLong(lenobj);
5944 #endif
5945 if (PyErr_Occurred())
5946 return NULL;
5947 6446
5948 Py_BEGIN_ALLOW_THREADS 6447 Py_BEGIN_ALLOW_THREADS
5949 res = ftruncate(fd, length); 6448 res = ftruncate(fd, length);
5950 Py_END_ALLOW_THREADS 6449 Py_END_ALLOW_THREADS
5951 if (res < 0) 6450 if (res < 0)
5952 return posix_error(); 6451 return posix_error();
5953 Py_INCREF(Py_None); 6452 Py_INCREF(Py_None);
5954 return Py_None; 6453 return Py_None;
6454 }
6455 #endif
6456
6457 #ifdef HAVE_TRUNCATE
6458 PyDoc_STRVAR(posix_truncate__doc__,
6459 "truncate(path, length)\n\n\
6460 Truncate the file given by path to length bytes.");
6461
6462 static PyObject *
6463 posix_truncate(PyObject *self, PyObject *args)
6464 {
6465 PyObject *opath, *lenobj;
6466 const char *path;
6467 off_t length;
6468 int res;
6469
6470 if (!PyArg_ParseTuple(args, "O&O:truncate",
6471 PyUnicode_FSConverter, &opath, &lenobj))
6472 return NULL;
6473 path = PyBytes_AsString(opath);
6474 PARSE_OFF_T_NO_ERROR(length, lenobj)
6475 if (PyErr_Occurred()) {
6476 Py_DECREF(opath);
6477 return NULL;
6478 }
6479
6480 Py_BEGIN_ALLOW_THREADS
6481 res = truncate(path, length);
6482 Py_END_ALLOW_THREADS
6483 Py_DECREF(opath);
6484 if (res < 0)
6485 return posix_error();
6486 Py_RETURN_NONE;
6487 }
6488 #endif
6489
6490 #ifdef HAVE_POSIX_FALLOCATE
6491 PyDoc_STRVAR(posix_posix_fallocate__doc__,
6492 "posix_fallocate(fd, offset, len)\n\n\
6493 Ensures that enough disk space is allocated for the file specified by fd\n\
6494 starting from offset and continuing for len bytes.");
6495
6496 static PyObject *
6497 posix_posix_fallocate(PyObject *self, PyObject *args)
6498 {
6499 off_t len, offset;
6500 int res, fd;
6501 PyObject *lenobj, *offobj;
6502
6503 if (!PyArg_ParseTuple(args, "iOO:posix_fallocate",
6504 &fd, &offobj, &lenobj))
6505 return NULL;
6506
6507 PARSE_OFF_T(offset, offobj)
6508 PARSE_OFF_T(len, lenobj)
6509
6510 Py_BEGIN_ALLOW_THREADS
6511 res = posix_fallocate(fd, offset, len);
6512 Py_END_ALLOW_THREADS
6513 if (res != 0) {
6514 errno = res;
6515 return posix_error();
6516 }
6517 Py_RETURN_NONE;
6518 }
6519 #endif
6520
6521 #ifdef HAVE_POSIX_FADVISE
6522 PyDoc_STRVAR(posix_posix_fadvise__doc__,
6523 "posix_fadvise(fd, offset, len, advice)\n\n\
6524 Announces an intention to access data in a specific pattern thus allowing\n\
6525 the kernel to make optimizations.\n\
6526 The advice applies to the region of the file specified by fd starting at\n\
6527 offset and continuing for len bytes.\n\
6528 advice is one of POSIX_FADV_NORMAL, POSIX_FADV_SEQUENTIAL,\n\
6529 POSIX_FADV_RANDOM, POSIX_FADV_NOREUSE, POSIX_FADV_WILLNEED or\n\
6530 POSIX_FADV_DONTNEED.");
6531
6532 static PyObject *
6533 posix_posix_fadvise(PyObject *self, PyObject *args)
6534 {
6535 off_t len, offset;
6536 int res, fd, advice;
6537 PyObject *lenobj, *offobj;
6538
6539 if (!PyArg_ParseTuple(args, "iOOi:posix_fadvise",
6540 &fd, &offobj, &lenobj, &advice))
6541 return NULL;
6542
6543 PARSE_OFF_T(offset, offobj)
6544 PARSE_OFF_T(len, lenobj)
6545
6546 Py_BEGIN_ALLOW_THREADS
6547 res = posix_fadvise(fd, offset, len, advice);
6548 Py_END_ALLOW_THREADS
6549 if (res != 0) {
6550 errno = res;
6551 return posix_error();
6552 }
6553 Py_RETURN_NONE;
5955 } 6554 }
5956 #endif 6555 #endif
5957 6556
5958 #ifdef HAVE_PUTENV 6557 #ifdef HAVE_PUTENV
5959 PyDoc_STRVAR(posix_putenv__doc__, 6558 PyDoc_STRVAR(posix_putenv__doc__,
5960 "putenv(key, value)\n\n\ 6559 "putenv(key, value)\n\n\
5961 Change or add an environment variable."); 6560 Change or add an environment variable.");
5962 6561
5963 /* Save putenv() parameters as values here, so we can collect them when they 6562 /* Save putenv() parameters as values here, so we can collect them when they
5964 * get re-set with another call for the same key. */ 6563 * get re-set with another call for the same key. */
(...skipping 1863 matching lines...) Expand 10 before | Expand all | Expand 10 after
7828 #ifdef HAVE_SYSTEM 8427 #ifdef HAVE_SYSTEM
7829 {"system", posix_system, METH_VARARGS, posix_system__doc__}, 8428 {"system", posix_system, METH_VARARGS, posix_system__doc__},
7830 #endif 8429 #endif
7831 {"umask", posix_umask, METH_VARARGS, posix_umask__doc__}, 8430 {"umask", posix_umask, METH_VARARGS, posix_umask__doc__},
7832 #ifdef HAVE_UNAME 8431 #ifdef HAVE_UNAME
7833 {"uname", posix_uname, METH_NOARGS, posix_uname__doc__}, 8432 {"uname", posix_uname, METH_NOARGS, posix_uname__doc__},
7834 #endif /* HAVE_UNAME */ 8433 #endif /* HAVE_UNAME */
7835 {"unlink", posix_unlink, METH_VARARGS, posix_unlink__doc__}, 8434 {"unlink", posix_unlink, METH_VARARGS, posix_unlink__doc__},
7836 {"remove", posix_unlink, METH_VARARGS, posix_remove__doc__}, 8435 {"remove", posix_unlink, METH_VARARGS, posix_remove__doc__},
7837 {"utime", posix_utime, METH_VARARGS, posix_utime__doc__}, 8436 {"utime", posix_utime, METH_VARARGS, posix_utime__doc__},
8437 #ifdef HAVE_FUTIMES
8438 {"futimes", posix_futimes, METH_VARARGS, posix_futimes__doc__},
8439 #endif
8440 #ifdef HAVE_LUTIMES
8441 {"lutimes", posix_lutimes, METH_VARARGS, posix_lutimes__doc__},
8442 #endif
8443 #ifdef HAVE_FUTIMENS
8444 {"futimens", posix_futimens, METH_VARARGS, posix_futimens__doc__},
8445 #endif
7838 #ifdef HAVE_TIMES 8446 #ifdef HAVE_TIMES
7839 {"times", posix_times, METH_NOARGS, posix_times__doc__}, 8447 {"times", posix_times, METH_NOARGS, posix_times__doc__},
7840 #endif /* HAVE_TIMES */ 8448 #endif /* HAVE_TIMES */
7841 {"_exit", posix__exit, METH_VARARGS, posix__exit__doc__}, 8449 {"_exit", posix__exit, METH_VARARGS, posix__exit__doc__},
7842 #ifdef HAVE_EXECV 8450 #ifdef HAVE_EXECV
7843 {"execv", posix_execv, METH_VARARGS, posix_execv__doc__}, 8451 {"execv", posix_execv, METH_VARARGS, posix_execv__doc__},
7844 {"execve", posix_execve, METH_VARARGS, posix_execve__doc__}, 8452 {"execve", posix_execve, METH_VARARGS, posix_execve__doc__},
7845 #endif /* HAVE_EXECV */ 8453 #endif /* HAVE_EXECV */
8454 #ifdef HAVE_FEXECVE
8455 {"fexecve", posix_fexecve, METH_VARARGS, posix_fexecve__doc__},
8456 #endif
7846 #ifdef HAVE_SPAWNV 8457 #ifdef HAVE_SPAWNV
7847 {"spawnv", posix_spawnv, METH_VARARGS, posix_spawnv__doc__}, 8458 {"spawnv", posix_spawnv, METH_VARARGS, posix_spawnv__doc__},
7848 {"spawnve", posix_spawnve, METH_VARARGS, posix_spawnve__doc__}, 8459 {"spawnve", posix_spawnve, METH_VARARGS, posix_spawnve__doc__},
7849 #if defined(PYOS_OS2) 8460 #if defined(PYOS_OS2)
7850 {"spawnvp", posix_spawnvp, METH_VARARGS, posix_spawnvp__doc__}, 8461 {"spawnvp", posix_spawnvp, METH_VARARGS, posix_spawnvp__doc__},
7851 {"spawnvpe", posix_spawnvpe, METH_VARARGS, posix_spawnvpe__doc__}, 8462 {"spawnvpe", posix_spawnvpe, METH_VARARGS, posix_spawnvpe__doc__},
7852 #endif /* PYOS_OS2 */ 8463 #endif /* PYOS_OS2 */
7853 #endif /* HAVE_SPAWNV */ 8464 #endif /* HAVE_SPAWNV */
7854 #ifdef HAVE_FORK1 8465 #ifdef HAVE_FORK1
7855 {"fork1", posix_fork1, METH_NOARGS, posix_fork1__doc__}, 8466 {"fork1", posix_fork1, METH_NOARGS, posix_fork1__doc__},
7856 #endif /* HAVE_FORK1 */ 8467 #endif /* HAVE_FORK1 */
7857 #ifdef HAVE_FORK 8468 #ifdef HAVE_FORK
7858 {"fork", posix_fork, METH_NOARGS, posix_fork__doc__}, 8469 {"fork", posix_fork, METH_NOARGS, posix_fork__doc__},
7859 #endif /* HAVE_FORK */ 8470 #endif /* HAVE_FORK */
7860 #if defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX) 8471 #if defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX)
7861 {"openpty", posix_openpty, METH_NOARGS, posix_openpty__doc__}, 8472 {"openpty", posix_openpty, METH_NOARGS, posix_openpty__doc__},
7862 #endif /* HAVE_OPENPTY || HAVE__GETPTY || HAVE_DEV_PTMX */ 8473 #endif /* HAVE_OPENPTY || HAVE__GETPTY || HAVE_DEV_PTMX */
7863 #ifdef HAVE_FORKPTY 8474 #ifdef HAVE_FORKPTY
7864 {"forkpty", posix_forkpty, METH_NOARGS, posix_forkpty__doc__}, 8475 {"forkpty", posix_forkpty, METH_NOARGS, posix_forkpty__doc__},
7865 #endif /* HAVE_FORKPTY */ 8476 #endif /* HAVE_FORKPTY */
8477 #ifdef HAVE_GETHOSTID
8478 {"gethostid", posix_gethostid, METH_NOARGS, posix_gethostid__doc__},
8479 #endif
8480 #ifdef HAVE_SETHOSTNAME
8481 {"sethostname", posix_sethostname, METH_VARARGS, posix_sethostname__doc_ _},
8482 #endif
7866 #ifdef HAVE_GETEGID 8483 #ifdef HAVE_GETEGID
7867 {"getegid", posix_getegid, METH_NOARGS, posix_getegid__doc__}, 8484 {"getegid", posix_getegid, METH_NOARGS, posix_getegid__doc__},
7868 #endif /* HAVE_GETEGID */ 8485 #endif /* HAVE_GETEGID */
7869 #ifdef HAVE_GETEUID 8486 #ifdef HAVE_GETEUID
7870 {"geteuid", posix_geteuid, METH_NOARGS, posix_geteuid__doc__}, 8487 {"geteuid", posix_geteuid, METH_NOARGS, posix_geteuid__doc__},
7871 #endif /* HAVE_GETEUID */ 8488 #endif /* HAVE_GETEUID */
7872 #ifdef HAVE_GETGID 8489 #ifdef HAVE_GETGID
7873 {"getgid", posix_getgid, METH_NOARGS, posix_getgid__doc__}, 8490 {"getgid", posix_getgid, METH_NOARGS, posix_getgid__doc__},
7874 #endif /* HAVE_GETGID */ 8491 #endif /* HAVE_GETGID */
7875 #ifdef HAVE_GETGROUPS 8492 #ifdef HAVE_GETGROUPS
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
7934 #endif /* HAVE_SETPGRP */ 8551 #endif /* HAVE_SETPGRP */
7935 #ifdef HAVE_WAIT 8552 #ifdef HAVE_WAIT
7936 {"wait", posix_wait, METH_NOARGS, posix_wait__doc__}, 8553 {"wait", posix_wait, METH_NOARGS, posix_wait__doc__},
7937 #endif /* HAVE_WAIT */ 8554 #endif /* HAVE_WAIT */
7938 #ifdef HAVE_WAIT3 8555 #ifdef HAVE_WAIT3
7939 {"wait3", posix_wait3, METH_VARARGS, posix_wait3__doc__}, 8556 {"wait3", posix_wait3, METH_VARARGS, posix_wait3__doc__},
7940 #endif /* HAVE_WAIT3 */ 8557 #endif /* HAVE_WAIT3 */
7941 #ifdef HAVE_WAIT4 8558 #ifdef HAVE_WAIT4
7942 {"wait4", posix_wait4, METH_VARARGS, posix_wait4__doc__}, 8559 {"wait4", posix_wait4, METH_VARARGS, posix_wait4__doc__},
7943 #endif /* HAVE_WAIT4 */ 8560 #endif /* HAVE_WAIT4 */
8561 #ifdef HAVE_WAITID
8562 {"waitid", posix_waitid, METH_VARARGS, posix_waitid__doc__},
8563 #endif
7944 #if defined(HAVE_WAITPID) || defined(HAVE_CWAIT) 8564 #if defined(HAVE_WAITPID) || defined(HAVE_CWAIT)
7945 {"waitpid", posix_waitpid, METH_VARARGS, posix_waitpid__doc__}, 8565 {"waitpid", posix_waitpid, METH_VARARGS, posix_waitpid__doc__},
7946 #endif /* HAVE_WAITPID */ 8566 #endif /* HAVE_WAITPID */
7947 #ifdef HAVE_GETSID 8567 #ifdef HAVE_GETSID
7948 {"getsid", posix_getsid, METH_VARARGS, posix_getsid__doc__}, 8568 {"getsid", posix_getsid, METH_VARARGS, posix_getsid__doc__},
7949 #endif /* HAVE_GETSID */ 8569 #endif /* HAVE_GETSID */
7950 #ifdef HAVE_SETSID 8570 #ifdef HAVE_SETSID
7951 {"setsid", posix_setsid, METH_NOARGS, posix_setsid__doc__}, 8571 {"setsid", posix_setsid, METH_NOARGS, posix_setsid__doc__},
7952 #endif /* HAVE_SETSID */ 8572 #endif /* HAVE_SETSID */
7953 #ifdef HAVE_SETPGID 8573 #ifdef HAVE_SETPGID
7954 {"setpgid", posix_setpgid, METH_VARARGS, posix_setpgid__doc__}, 8574 {"setpgid", posix_setpgid, METH_VARARGS, posix_setpgid__doc__},
7955 #endif /* HAVE_SETPGID */ 8575 #endif /* HAVE_SETPGID */
7956 #ifdef HAVE_TCGETPGRP 8576 #ifdef HAVE_TCGETPGRP
7957 {"tcgetpgrp", posix_tcgetpgrp, METH_VARARGS, posix_tcgetpgrp__doc__}, 8577 {"tcgetpgrp", posix_tcgetpgrp, METH_VARARGS, posix_tcgetpgrp__doc__},
7958 #endif /* HAVE_TCGETPGRP */ 8578 #endif /* HAVE_TCGETPGRP */
7959 #ifdef HAVE_TCSETPGRP 8579 #ifdef HAVE_TCSETPGRP
7960 {"tcsetpgrp", posix_tcsetpgrp, METH_VARARGS, posix_tcsetpgrp__doc__}, 8580 {"tcsetpgrp", posix_tcsetpgrp, METH_VARARGS, posix_tcsetpgrp__doc__},
7961 #endif /* HAVE_TCSETPGRP */ 8581 #endif /* HAVE_TCSETPGRP */
7962 {"open", posix_open, METH_VARARGS, posix_open__doc__}, 8582 {"open", posix_open, METH_VARARGS, posix_open__doc__},
7963 {"close", posix_close, METH_VARARGS, posix_close__doc__}, 8583 {"close", posix_close, METH_VARARGS, posix_close__doc__},
7964 {"closerange", posix_closerange, METH_VARARGS, posix_closerange__doc__} , 8584 {"closerange", posix_closerange, METH_VARARGS, posix_closerange__doc__} ,
7965 {"device_encoding", device_encoding, METH_VARARGS, device_encoding__doc__}, 8585 {"device_encoding", device_encoding, METH_VARARGS, device_encoding__doc__},
7966 {"dup", posix_dup, METH_VARARGS, posix_dup__doc__}, 8586 {"dup", posix_dup, METH_VARARGS, posix_dup__doc__},
7967 {"dup2", posix_dup2, METH_VARARGS, posix_dup2__doc__}, 8587 {"dup2", posix_dup2, METH_VARARGS, posix_dup2__doc__},
8588 #ifdef HAVE_LOCKF
8589 {"lockf", posix_lockf, METH_VARARGS, posix_lockf__doc__},
8590 #endif
7968 {"lseek", posix_lseek, METH_VARARGS, posix_lseek__doc__}, 8591 {"lseek", posix_lseek, METH_VARARGS, posix_lseek__doc__},
7969 {"read", posix_read, METH_VARARGS, posix_read__doc__}, 8592 {"read", posix_read, METH_VARARGS, posix_read__doc__},
8593 #ifdef HAVE_READV
8594 {"readv", posix_readv, METH_VARARGS, posix_readv__doc__},
8595 #endif
8596 #ifdef HAVE_PREAD
8597 {"pread", posix_pread, METH_VARARGS, posix_pread__doc__},
8598 #endif
7970 {"write", posix_write, METH_VARARGS, posix_write__doc__}, 8599 {"write", posix_write, METH_VARARGS, posix_write__doc__},
8600 #ifdef HAVE_WRITEV
8601 {"writev", posix_writev, METH_VARARGS, posix_writev__doc__},
8602 #endif
8603 #ifdef HAVE_PWRITE
8604 {"pwrite", posix_pwrite, METH_VARARGS, posix_pwrite__doc__},
8605 #endif
7971 {"fstat", posix_fstat, METH_VARARGS, posix_fstat__doc__}, 8606 {"fstat", posix_fstat, METH_VARARGS, posix_fstat__doc__},
7972 {"isatty", posix_isatty, METH_VARARGS, posix_isatty__doc__}, 8607 {"isatty", posix_isatty, METH_VARARGS, posix_isatty__doc__},
7973 #ifdef HAVE_PIPE 8608 #ifdef HAVE_PIPE
7974 {"pipe", posix_pipe, METH_NOARGS, posix_pipe__doc__}, 8609 {"pipe", posix_pipe, METH_NOARGS, posix_pipe__doc__},
7975 #endif 8610 #endif
7976 #ifdef HAVE_MKFIFO 8611 #ifdef HAVE_MKFIFO
7977 {"mkfifo", posix_mkfifo, METH_VARARGS, posix_mkfifo__doc__}, 8612 {"mkfifo", posix_mkfifo, METH_VARARGS, posix_mkfifo__doc__},
7978 #endif 8613 #endif
7979 #if defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV) 8614 #if defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV)
7980 {"mknod", posix_mknod, METH_VARARGS, posix_mknod__doc__}, 8615 {"mknod", posix_mknod, METH_VARARGS, posix_mknod__doc__},
7981 #endif 8616 #endif
7982 #ifdef HAVE_DEVICE_MACROS 8617 #ifdef HAVE_DEVICE_MACROS
7983 {"major", posix_major, METH_VARARGS, posix_major__doc__}, 8618 {"major", posix_major, METH_VARARGS, posix_major__doc__},
7984 {"minor", posix_minor, METH_VARARGS, posix_minor__doc__}, 8619 {"minor", posix_minor, METH_VARARGS, posix_minor__doc__},
7985 {"makedev", posix_makedev, METH_VARARGS, posix_makedev__doc__}, 8620 {"makedev", posix_makedev, METH_VARARGS, posix_makedev__doc__},
7986 #endif 8621 #endif
7987 #ifdef HAVE_FTRUNCATE 8622 #ifdef HAVE_FTRUNCATE
7988 {"ftruncate", posix_ftruncate, METH_VARARGS, posix_ftruncate__doc__}, 8623 {"ftruncate", posix_ftruncate, METH_VARARGS, posix_ftruncate__doc__},
8624 #endif
8625 #ifdef HAVE_TRUNCATE
8626 {"truncate", posix_truncate, METH_VARARGS, posix_truncate__doc__},
8627 #endif
8628 #ifdef HAVE_POSIX_FALLOCATE
8629 {"posix_fallocate", posix_posix_fallocate, METH_VARARGS, posix_posix_falloca te__doc__},
8630 #endif
8631 #ifdef HAVE_POSIX_FADVISE
8632 {"posix_fadvise", posix_posix_fadvise, METH_VARARGS, posix_posix_fadvise__ doc__},
7989 #endif 8633 #endif
7990 #ifdef HAVE_PUTENV 8634 #ifdef HAVE_PUTENV
7991 {"putenv", posix_putenv, METH_VARARGS, posix_putenv__doc__}, 8635 {"putenv", posix_putenv, METH_VARARGS, posix_putenv__doc__},
7992 #endif 8636 #endif
7993 #ifdef HAVE_UNSETENV 8637 #ifdef HAVE_UNSETENV
7994 {"unsetenv", posix_unsetenv, METH_VARARGS, posix_unsetenv__doc__}, 8638 {"unsetenv", posix_unsetenv, METH_VARARGS, posix_unsetenv__doc__},
7995 #endif 8639 #endif
7996 {"strerror", posix_strerror, METH_VARARGS, posix_strerror__doc__}, 8640 {"strerror", posix_strerror, METH_VARARGS, posix_strerror__doc__},
7997 #ifdef HAVE_FCHDIR 8641 #ifdef HAVE_FCHDIR
7998 {"fchdir", posix_fchdir, METH_O, posix_fchdir__doc__}, 8642 {"fchdir", posix_fchdir, METH_O, posix_fchdir__doc__},
7999 #endif 8643 #endif
8000 #ifdef HAVE_FSYNC 8644 #ifdef HAVE_FSYNC
8001 {"fsync", posix_fsync, METH_O, posix_fsync__doc__}, 8645 {"fsync", posix_fsync, METH_O, posix_fsync__doc__},
8646 #endif
8647 #ifdef HAVE_SYNC
8648 {"sync", posix_sync, METH_NOARGS, posix_sync__doc__},
8002 #endif 8649 #endif
8003 #ifdef HAVE_FDATASYNC 8650 #ifdef HAVE_FDATASYNC
8004 {"fdatasync", posix_fdatasync, METH_O, posix_fdatasync__doc__}, 8651 {"fdatasync", posix_fdatasync, METH_O, posix_fdatasync__doc__},
8005 #endif 8652 #endif
8006 #ifdef HAVE_SYS_WAIT_H 8653 #ifdef HAVE_SYS_WAIT_H
8007 #ifdef WCOREDUMP 8654 #ifdef WCOREDUMP
8008 {"WCOREDUMP", posix_WCOREDUMP, METH_VARARGS, posix_WCOREDUMP__doc__}, 8655 {"WCOREDUMP", posix_WCOREDUMP, METH_VARARGS, posix_WCOREDUMP__doc__},
8009 #endif /* WCOREDUMP */ 8656 #endif /* WCOREDUMP */
8010 #ifdef WIFCONTINUED 8657 #ifdef WIFCONTINUED
8011 {"WIFCONTINUED",posix_WIFCONTINUED, METH_VARARGS, posix_WIFCONTINUED__doc__} , 8658 {"WIFCONTINUED",posix_WIFCONTINUED, METH_VARARGS, posix_WIFCONTINUED__doc__} ,
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
8351 if (ins(d, "EX_NOTFOUND", (long)EX_NOTFOUND)) return -1; 8998 if (ins(d, "EX_NOTFOUND", (long)EX_NOTFOUND)) return -1;
8352 #endif /* EX_NOTFOUND */ 8999 #endif /* EX_NOTFOUND */
8353 9000
8354 /* statvfs */ 9001 /* statvfs */
8355 #ifdef ST_RDONLY 9002 #ifdef ST_RDONLY
8356 if (ins(d, "ST_RDONLY", (long)ST_RDONLY)) return -1; 9003 if (ins(d, "ST_RDONLY", (long)ST_RDONLY)) return -1;
8357 #endif /* ST_RDONLY */ 9004 #endif /* ST_RDONLY */
8358 #ifdef ST_NOSUID 9005 #ifdef ST_NOSUID
8359 if (ins(d, "ST_NOSUID", (long)ST_NOSUID)) return -1; 9006 if (ins(d, "ST_NOSUID", (long)ST_NOSUID)) return -1;
8360 #endif /* ST_NOSUID */ 9007 #endif /* ST_NOSUID */
9008
9009 /* constants for posix_fadvise */
9010 #ifdef POSIX_FADV_NORMAL
9011 if (ins(d, "POSIX_FADV_NORMAL", (long)POSIX_FADV_NORMAL)) return -1;
9012 #endif
9013 #ifdef POSIX_FADV_SEQUENTIAL
9014 if (ins(d, "POSIX_FADV_SEQUENTIAL", (long)POSIX_FADV_SEQUENTIAL)) return -1;
9015 #endif
9016 #ifdef POSIX_FADV_RANDOM
9017 if (ins(d, "POSIX_FADV_RANDOM", (long)POSIX_FADV_RANDOM)) return -1;
9018 #endif
9019 #ifdef POSIX_FADV_NOREUSE
9020 if (ins(d, "POSIX_FADV_NOREUSE", (long)POSIX_FADV_NOREUSE)) return -1;
9021 #endif
9022 #ifdef POSIX_FADV_WILLNEED
9023 if (ins(d, "POSIX_FADV_WILLNEED", (long)POSIX_FADV_WILLNEED)) return -1;
9024 #endif
9025 #ifdef POSIX_FADV_DONTNEED
9026 if (ins(d, "POSIX_FADV_DONTNEED", (long)POSIX_FADV_DONTNEED)) return -1;
9027 #endif
9028
9029 /* constants for waitid */
9030 #if defined(HAVE_SYS_WAIT_H) && defined(HAVE_WAITID)
9031 if (ins(d, "P_PID", (long)P_PID)) return -1;
9032 if (ins(d, "P_PGID", (long)P_PGID)) return -1;
9033 if (ins(d, "P_ALL", (long)P_ALL)) return -1;
9034 #endif
9035 #ifdef WEXITED
9036 if (ins(d, "WEXITED", (long)WEXITED)) return -1;
9037 #endif
9038 #ifdef WNOWAIT
9039 if (ins(d, "WNOWAIT", (long)WNOWAIT)) return -1;
9040 #endif
9041 #ifdef WSTOPPED
9042 if (ins(d, "WSTOPPED", (long)WSTOPPED)) return -1;
9043 #endif
9044
9045 /* constants for lockf */
9046 #ifdef F_LOCK
9047 if (ins(d, "F_LOCK", (long)F_LOCK)) return -1;
9048 #endif
9049 #ifdef F_TLOCK
9050 if (ins(d, "F_TLOCK", (long)F_TLOCK)) return -1;
9051 #endif
9052 #ifdef F_ULOCK
9053 if (ins(d, "F_ULOCK", (long)F_ULOCK)) return -1;
9054 #endif
9055 #ifdef F_TEST
9056 if (ins(d, "F_TEST", (long)F_TEST)) return -1;
9057 #endif
9058
9059 /* constants for futimens */
9060 #ifdef UTIME_NOW
9061 if (ins(d, "UTIME_NOW", (long)UTIME_NOW)) return -1;
9062 #endif
9063 #ifdef UTIME_OMIT
9064 if (ins(d, "UTIME_OMIT", (long)UTIME_OMIT)) return -1;
9065 #endif
8361 9066
8362 #ifdef HAVE_SPAWNV 9067 #ifdef HAVE_SPAWNV
8363 #if defined(PYOS_OS2) && defined(PYCC_GCC) 9068 #if defined(PYOS_OS2) && defined(PYCC_GCC)
8364 if (ins(d, "P_WAIT", (long)P_WAIT)) return -1; 9069 if (ins(d, "P_WAIT", (long)P_WAIT)) return -1;
8365 if (ins(d, "P_NOWAIT", (long)P_NOWAIT)) return -1; 9070 if (ins(d, "P_NOWAIT", (long)P_NOWAIT)) return -1;
8366 if (ins(d, "P_OVERLAY", (long)P_OVERLAY)) return -1; 9071 if (ins(d, "P_OVERLAY", (long)P_OVERLAY)) return -1;
8367 if (ins(d, "P_DEBUG", (long)P_DEBUG)) return -1; 9072 if (ins(d, "P_DEBUG", (long)P_DEBUG)) return -1;
8368 if (ins(d, "P_SESSION", (long)P_SESSION)) return -1; 9073 if (ins(d, "P_SESSION", (long)P_SESSION)) return -1;
8369 if (ins(d, "P_DETACH", (long)P_DETACH)) return -1; 9074 if (ins(d, "P_DETACH", (long)P_DETACH)) return -1;
8370 if (ins(d, "P_PM", (long)P_PM)) return -1; 9075 if (ins(d, "P_PM", (long)P_PM)) return -1;
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
8522 9227
8523 9228
8524 #endif /* __APPLE__ */ 9229 #endif /* __APPLE__ */
8525 return m; 9230 return m;
8526 9231
8527 } 9232 }
8528 9233
8529 #ifdef __cplusplus 9234 #ifdef __cplusplus
8530 } 9235 }
8531 #endif 9236 #endif
OLDNEW
« no previous file with comments | « Lib/test/test_posix.py ('k') | configure.in » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld cbc36f91f3f7