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

Side by Side Diff: Modules/posixmodule.c

Issue 10812: Add some posix functions
Patch Set: Created 2 years, 3 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 int
355 PyParse_off_t(PyObject* arg, void* addr)
gregory.p.smith 2011/03/16 06:15:53 Why can't this be off_t *addr ? Also the function
356 {
357 #if !defined(HAVE_LARGEFILE_SUPPORT)
358 *((off_t*)addr) = PyLong_AsLong(arg);
359 #else
360 *((off_t*)addr) = PyLong_Check(arg) ? PyLong_AsLongLong(arg)
361 : PyLong_AsLong(arg);
362 #endif
363 if (PyErr_Occurred())
364 return 0;
365 return 1;
366 }
349 367
350 #if defined _MSC_VER && _MSC_VER >= 1400 368 #if defined _MSC_VER && _MSC_VER >= 1400
351 /* Microsoft CRT in VS2005 and higher will verify that a filehandle is 369 /* Microsoft CRT in VS2005 and higher will verify that a filehandle is
352 * valid and throw an assertion if it isn't. 370 * valid and throw an assertion if it isn't.
353 * Normally, an invalid fd is likely to be a C program error and therefore 371 * 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 372 * an assertion can be useful, but it does contradict the POSIX standard
355 * which for write(2) states: 373 * which for write(2) states:
356 * "Otherwise, -1 shall be returned and errno set to indicate the error." 374 * "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 375 * "[EBADF] The fildes argument is not a valid file descriptor open for
358 * writing." 376 * writing."
(...skipping 1107 matching lines...) Expand 10 before | Expand all | Expand 10 after
1466 {"f_namemax",}, 1484 {"f_namemax",},
1467 {0} 1485 {0}
1468 }; 1486 };
1469 1487
1470 static PyStructSequence_Desc statvfs_result_desc = { 1488 static PyStructSequence_Desc statvfs_result_desc = {
1471 "statvfs_result", /* name */ 1489 "statvfs_result", /* name */
1472 statvfs_result__doc__, /* doc */ 1490 statvfs_result__doc__, /* doc */
1473 statvfs_result_fields, 1491 statvfs_result_fields,
1474 10 1492 10
1475 }; 1493 };
1494
1495 PyDoc_STRVAR(waitid_result__doc__,
1496 "waitid_result: Result from waitid.\n\n\
1497 This object may be accessed either as a tuple of\n\
1498 (si_pid, si_uid, si_signo, si_status, si_code),\n\
1499 or via the attributes si_pid, si_uid, and so on.\n\
1500 \n\
1501 See os.waitid for more information.");
1502
1503 static PyStructSequence_Field waitid_result_fields[] = {
1504 {"si_pid", },
1505 {"si_uid", },
1506 {"si_signo", },
1507 {"si_status", },
1508 {"si_code", },
1509 {0}
1510 };
1511
1512 static PyStructSequence_Desc waitid_result_desc = {
1513 "waitid_result", /* name */
1514 waitid_result__doc__, /* doc */
1515 waitid_result_fields,
1516 5
1517 };
1518 static PyTypeObject WaitidResultType;
1476 1519
1477 static int initialized; 1520 static int initialized;
1478 static PyTypeObject StatResultType; 1521 static PyTypeObject StatResultType;
1479 static PyTypeObject StatVFSResultType; 1522 static PyTypeObject StatVFSResultType;
1480 static newfunc structseq_new; 1523 static newfunc structseq_new;
1481 1524
1482 static PyObject * 1525 static PyObject *
1483 statresult_new(PyTypeObject *type, PyObject *args, PyObject *kwds) 1526 statresult_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
1484 { 1527 {
1485 PyStructSequence *result; 1528 PyStructSequence *result;
(...skipping 579 matching lines...) Expand 10 before | Expand all | Expand 10 after
2065 PyDoc_STRVAR(posix_fsync__doc__, 2108 PyDoc_STRVAR(posix_fsync__doc__,
2066 "fsync(fildes)\n\n\ 2109 "fsync(fildes)\n\n\
2067 force write of file with filedescriptor to disk."); 2110 force write of file with filedescriptor to disk.");
2068 2111
2069 static PyObject * 2112 static PyObject *
2070 posix_fsync(PyObject *self, PyObject *fdobj) 2113 posix_fsync(PyObject *self, PyObject *fdobj)
2071 { 2114 {
2072 return posix_fildes(fdobj, fsync); 2115 return posix_fildes(fdobj, fsync);
2073 } 2116 }
2074 #endif /* HAVE_FSYNC */ 2117 #endif /* HAVE_FSYNC */
2118
2119 #ifdef HAVE_SYNC
2120 PyDoc_STRVAR(posix_sync__doc__,
2121 "sync()\n\n\
2122 Force write of everything to disk.");
2123
2124 static PyObject *
2125 posix_sync(PyObject *self, PyObject *noargs)
2126 {
2127 Py_BEGIN_ALLOW_THREADS
2128 sync();
2129 Py_END_ALLOW_THREADS
2130 Py_RETURN_NONE;
2131 }
2132 #endif
2075 2133
2076 #ifdef HAVE_FDATASYNC 2134 #ifdef HAVE_FDATASYNC
2077 2135
2078 #ifdef __hpux 2136 #ifdef __hpux
2079 extern int fdatasync(int); /* On HP-UX, in libc but not in unistd.h */ 2137 extern int fdatasync(int); /* On HP-UX, in libc but not in unistd.h */
2080 #endif 2138 #endif
2081 2139
2082 PyDoc_STRVAR(posix_fdatasync__doc__, 2140 PyDoc_STRVAR(posix_fdatasync__doc__,
2083 "fdatasync(fildes)\n\n\ 2141 "fdatasync(fildes)\n\n\
2084 force write of file with filedescriptor to disk.\n\ 2142 force write of file with filedescriptor to disk.\n\
(...skipping 1250 matching lines...) Expand 10 before | Expand all | Expand 10 after
3335 } 3393 }
3336 Py_DECREF(opath); 3394 Py_DECREF(opath);
3337 Py_INCREF(Py_None); 3395 Py_INCREF(Py_None);
3338 return Py_None; 3396 return Py_None;
3339 #undef UTIME_ARG 3397 #undef UTIME_ARG
3340 #undef ATIME 3398 #undef ATIME
3341 #undef MTIME 3399 #undef MTIME
3342 #endif /* MS_WINDOWS */ 3400 #endif /* MS_WINDOWS */
3343 } 3401 }
3344 3402
3403 #ifdef HAVE_FUTIMES
3404 PyDoc_STRVAR(posix_futimes__doc__,
3405 "futimes(fd, (atime, mtime))\n\
3406 futimes(fd, None)\n\n\
3407 Set the access and modified time of the file specified by the file\n\
3408 descriptor fd to the given values. If the second form is used, set the\n\
3409 access and modified times to the current time.");
3410
3411 static PyObject *
3412 posix_futimes(PyObject *self, PyObject *args)
3413 {
3414 int res, fd;
3415 PyObject* arg;
3416 struct timeval buf[2];
3417
3418 if (!PyArg_ParseTuple(args, "iO:futimes", &fd, &arg))
3419 return NULL;
3420
3421 if (arg == Py_None) {
3422 /* optional time values not given */
3423 Py_BEGIN_ALLOW_THREADS
3424 res = futimes(fd, NULL);
3425 Py_END_ALLOW_THREADS
3426 }
3427 else if (!PyTuple_Check(arg) || PyTuple_Size(arg) != 2) {
3428 PyErr_SetString(PyExc_TypeError,
3429 "futimes() arg 2 must be a tuple (atime, mtime)");
3430 return NULL;
3431 }
3432 else {
3433 if (extract_time(PyTuple_GET_ITEM(arg, 0),
3434 &(buf[0].tv_sec), &(buf[0].tv_usec)) == -1) {
3435 return NULL;
3436 }
3437 if (extract_time(PyTuple_GET_ITEM(arg, 1),
3438 &(buf[1].tv_sec), &(buf[1].tv_usec)) == -1) {
3439 return NULL;
3440 }
3441 Py_BEGIN_ALLOW_THREADS
3442 res = futimes(fd, buf);
3443 Py_END_ALLOW_THREADS
3444 }
3445 if (res < 0)
3446 return posix_error();
3447 Py_RETURN_NONE;
3448 }
3449 #endif
3450
3451 #ifdef HAVE_LUTIMES
3452 PyDoc_STRVAR(posix_lutimes__doc__,
3453 "lutimes(path, (atime, mtime))\n\
3454 lutimes(path, None)\n\n\
3455 Like utime(), but if path is a symbolic link, it is not dereferenced.");
gregory.p.smith 2011/03/16 06:15:53 Like utimes() I think you mean?
3456
3457 static PyObject *
3458 posix_lutimes(PyObject *self, PyObject *args)
3459 {
3460 PyObject *opath, *arg;
3461 const char *path;
3462 int res;
3463 struct timeval buf[2];
3464
3465 if (!PyArg_ParseTuple(args, "O&O:lutimes",
3466 PyUnicode_FSConverter, &opath, &arg))
3467 return NULL;
3468 path = PyBytes_AsString(opath);
3469 if (arg == Py_None) {
3470 /* optional time values not given */
3471 Py_BEGIN_ALLOW_THREADS
3472 res = lutimes(path, NULL);
3473 Py_END_ALLOW_THREADS
3474 }
3475 else if (!PyTuple_Check(arg) || PyTuple_Size(arg) != 2) {
3476 PyErr_SetString(PyExc_TypeError,
3477 "lutimes() arg 2 must be a tuple (atime, mtime)");
3478 Py_DECREF(opath);
3479 return NULL;
3480 }
3481 else {
3482 if (extract_time(PyTuple_GET_ITEM(arg, 0),
3483 &(buf[0].tv_sec), &(buf[0].tv_usec)) == -1) {
3484 Py_DECREF(opath);
3485 return NULL;
3486 }
3487 if (extract_time(PyTuple_GET_ITEM(arg, 1),
3488 &(buf[1].tv_sec), &(buf[1].tv_usec)) == -1) {
3489 Py_DECREF(opath);
3490 return NULL;
3491 }
3492 Py_BEGIN_ALLOW_THREADS
3493 res = lutimes(path, buf);
3494 Py_END_ALLOW_THREADS
3495 }
3496 Py_DECREF(opath);
3497 if (res < 0)
3498 return posix_error();
3499 Py_RETURN_NONE;
3500 }
3501 #endif
3502
3503 #ifdef HAVE_FUTIMENS
3504 PyDoc_STRVAR(posix_futimens__doc__,
3505 "futimens(fd, (atime_sec, atime_nsec), (mtime_sec, mtime_nsec))\n\
3506 futimens(fd, None, None)\n\n\
3507 Updates the timestamps of a file specified by the file descriptor fd, with\n\
3508 nanosecond precision.\n\
3509 The second form sets atime and mtime to the current time.\n\
3510 If *_nsec is specified as UTIME_NOW, the timestamp is updated to the\n\
3511 current time.\n\
3512 If *_nsec is specified as UTIME_OMIT, the timestamp is not updated.");
3513
3514 static PyObject *
3515 posix_futimens(PyObject *self, PyObject *args)
3516 {
3517 int res, fd;
3518 PyObject *atime, *mtime;
3519 struct timespec buf[2];
3520
3521 if (!PyArg_ParseTuple(args, "iOO:futimens",
3522 &fd, &atime, &mtime))
3523 return NULL;
3524 if (atime == Py_None && mtime == Py_None) {
3525 /* optional time values not given */
3526 Py_BEGIN_ALLOW_THREADS
3527 res = futimens(fd, NULL);
3528 Py_END_ALLOW_THREADS
3529 }
3530 else if (!PyTuple_Check(atime) || PyTuple_Size(atime) != 2) {
3531 PyErr_SetString(PyExc_TypeError,
3532 "futimens() arg 2 must be a tuple (atime_sec, atime_nsec)");
3533 return NULL;
3534 }
3535 else if (!PyTuple_Check(mtime) || PyTuple_Size(mtime) != 2) {
3536 PyErr_SetString(PyExc_TypeError,
3537 "futimens() arg 3 must be a tuple (mtime_sec, mtime_nsec)");
3538 return NULL;
3539 }
3540 else {
3541 if (!PyArg_ParseTuple(atime, "ll:futimens",
3542 &(buf[0].tv_sec), &(buf[0].tv_nsec))) {
3543 return NULL;
3544 }
3545 if (!PyArg_ParseTuple(mtime, "ll:futimens",
3546 &(buf[1].tv_sec), &(buf[1].tv_nsec))) {
3547 return NULL;
3548 }
3549 Py_BEGIN_ALLOW_THREADS
3550 res = futimens(fd, buf);
3551 Py_END_ALLOW_THREADS
3552 }
3553 if (res < 0)
3554 return posix_error();
3555 Py_RETURN_NONE;
3556 }
3557 #endif
3345 3558
3346 /* Process operations */ 3559 /* Process operations */
3347 3560
3348 PyDoc_STRVAR(posix__exit__doc__, 3561 PyDoc_STRVAR(posix__exit__doc__,
3349 "_exit(status)\n\n\ 3562 "_exit(status)\n\n\
3350 Exit to the system with specified status, without normal exit processing."); 3563 Exit to the system with specified status, without normal exit processing.");
3351 3564
3352 static PyObject * 3565 static PyObject *
3353 posix__exit(PyObject *self, PyObject *args) 3566 posix__exit(PyObject *self, PyObject *args)
3354 { 3567 {
(...skipping 24 matching lines...) Expand all
3379 size = PyBytes_GET_SIZE(bytes); 3592 size = PyBytes_GET_SIZE(bytes);
3380 *out = PyMem_Malloc(size+1); 3593 *out = PyMem_Malloc(size+1);
3381 if (!*out) 3594 if (!*out)
3382 return 0; 3595 return 0;
3383 memcpy(*out, PyBytes_AsString(bytes), size+1); 3596 memcpy(*out, PyBytes_AsString(bytes), size+1);
3384 Py_DECREF(bytes); 3597 Py_DECREF(bytes);
3385 return 1; 3598 return 1;
3386 } 3599 }
3387 #endif 3600 #endif
3388 3601
3389 3602 #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** 3603 static char**
3463 parse_envlist(PyObject* env, Py_ssize_t *envc_ptr) 3604 parse_envlist(PyObject* env, Py_ssize_t *envc_ptr)
3464 { 3605 {
3465 char **envlist; 3606 char **envlist;
3466 Py_ssize_t i, pos, envc; 3607 Py_ssize_t i, pos, envc;
3467 PyObject *keys=NULL, *vals=NULL; 3608 PyObject *keys=NULL, *vals=NULL;
3468 PyObject *key, *val, *key2, *val2; 3609 PyObject *key, *val, *key2, *val2;
3469 char *p, *k, *v; 3610 char *p, *k, *v;
3470 size_t len; 3611 size_t len;
3471 3612
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
3531 *envc_ptr = envc; 3672 *envc_ptr = envc;
3532 return envlist; 3673 return envlist;
3533 3674
3534 error: 3675 error:
3535 Py_XDECREF(keys); 3676 Py_XDECREF(keys);
3536 Py_XDECREF(vals); 3677 Py_XDECREF(vals);
3537 while (--envc >= 0) 3678 while (--envc >= 0)
3538 PyMem_DEL(envlist[envc]); 3679 PyMem_DEL(envlist[envc]);
3539 PyMem_DEL(envlist); 3680 PyMem_DEL(envlist);
3540 return NULL; 3681 return NULL;
3682 }
3683
3684 static char**
3685 parse_arglist(PyObject* argv, Py_ssize_t *argc)
3686 {
3687 int i;
3688 char **argvlist = PyMem_NEW(char *, *argc+1);
3689 if (argvlist == NULL) {
3690 PyErr_NoMemory();
3691 return NULL;
3692 }
3693 for (i = 0; i < *argc; i++) {
3694 if (!fsconvert_strdup(PySequence_ITEM(argv, i),
3695 &argvlist[i]))
3696 {
3697 *argc = i;
3698 goto fail;
3699 }
3700 }
3701 argvlist[*argc] = NULL;
3702 return argvlist;
3703 fail:
3704 free_string_array(argvlist, *argc);
3705 return NULL;
3706 }
3707 #endif
3708
3709 #ifdef HAVE_EXECV
3710 PyDoc_STRVAR(posix_execv__doc__,
3711 "execv(path, args)\n\n\
3712 Execute an executable path with arguments, replacing current process.\n\
3713 \n\
3714 path: path of executable file\n\
3715 args: tuple or list of strings");
3716
3717 static PyObject *
3718 posix_execv(PyObject *self, PyObject *args)
3719 {
3720 PyObject *opath;
3721 char *path;
3722 PyObject *argv;
3723 char **argvlist;
3724 Py_ssize_t argc;
3725
3726 /* execv has two arguments: (path, argv), where
3727 argv is a list or tuple of strings. */
3728
3729 if (!PyArg_ParseTuple(args, "O&O:execv",
3730 PyUnicode_FSConverter,
3731 &opath, &argv))
3732 return NULL;
3733 path = PyBytes_AsString(opath);
3734 if (!PyList_Check(argv) && !PyTuple_Check(argv)) {
3735 PyErr_SetString(PyExc_TypeError,
3736 "execv() arg 2 must be a tuple or list");
3737 Py_DECREF(opath);
3738 return NULL;
3739 }
3740 argc = PySequence_Size(argv);
3741 if (argc < 1) {
3742 PyErr_SetString(PyExc_ValueError, "execv() arg 2 must not be empty");
3743 Py_DECREF(opath);
3744 return NULL;
3745 }
3746
3747 argvlist = parse_arglist(argv, &argc);
3748 if (argvlist == NULL) {
3749 Py_DECREF(opath);
3750 return NULL;
3751 }
3752
3753 execv(path, argvlist);
3754
3755 /* If we get here it's definitely an error */
3756
3757 free_string_array(argvlist, argc);
3758 Py_DECREF(opath);
3759 return posix_error();
3541 } 3760 }
3542 3761
3543 PyDoc_STRVAR(posix_execve__doc__, 3762 PyDoc_STRVAR(posix_execve__doc__,
3544 "execve(path, args, env)\n\n\ 3763 "execve(path, args, env)\n\n\
3545 Execute a path with arguments and environment, replacing current process.\n\ 3764 Execute a path with arguments and environment, replacing current process.\n\
3546 \n\ 3765 \n\
3547 path: path of executable file\n\ 3766 path: path of executable file\n\
3548 args: tuple or list of arguments\n\ 3767 args: tuple or list of arguments\n\
3549 env: dictionary of strings mapping to strings"); 3768 env: dictionary of strings mapping to strings");
3550 3769
3551 static PyObject * 3770 static PyObject *
3552 posix_execve(PyObject *self, PyObject *args) 3771 posix_execve(PyObject *self, PyObject *args)
3553 { 3772 {
3554 PyObject *opath; 3773 PyObject *opath;
3555 char *path; 3774 char *path;
3556 PyObject *argv, *env; 3775 PyObject *argv, *env;
3557 char **argvlist; 3776 char **argvlist;
3558 char **envlist; 3777 char **envlist;
3559 Py_ssize_t i, argc, envc; 3778 Py_ssize_t argc, envc;
3560 PyObject *(*getitem)(PyObject *, Py_ssize_t);
3561 Py_ssize_t lastarg = 0;
3562 3779
3563 /* execve has three arguments: (path, argv, env), where 3780 /* execve has three arguments: (path, argv, env), where
3564 argv is a list or tuple of strings and env is a dictionary 3781 argv is a list or tuple of strings and env is a dictionary
3565 like posix.environ. */ 3782 like posix.environ. */
3566 3783
3567 if (!PyArg_ParseTuple(args, "O&OO:execve", 3784 if (!PyArg_ParseTuple(args, "O&OO:execve",
3568 PyUnicode_FSConverter, 3785 PyUnicode_FSConverter,
3569 &opath, &argv, &env)) 3786 &opath, &argv, &env))
3570 return NULL; 3787 return NULL;
3571 path = PyBytes_AsString(opath); 3788 path = PyBytes_AsString(opath);
3572 if (PyList_Check(argv)) { 3789 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, 3790 PyErr_SetString(PyExc_TypeError,
3582 "execve() arg 2 must be a tuple or list"); 3791 "execve() arg 2 must be a tuple or list");
3583 goto fail_0; 3792 goto fail_0;
3584 } 3793 }
3794 argc = PySequence_Size(argv);
3585 if (!PyMapping_Check(env)) { 3795 if (!PyMapping_Check(env)) {
3586 PyErr_SetString(PyExc_TypeError, 3796 PyErr_SetString(PyExc_TypeError,
3587 "execve() arg 3 must be a mapping object"); 3797 "execve() arg 3 must be a mapping object");
3588 goto fail_0; 3798 goto fail_0;
3589 } 3799 }
3590 3800
3591 argvlist = PyMem_NEW(char *, argc+1); 3801 argvlist = parse_arglist(argv, &argc);
3592 if (argvlist == NULL) { 3802 if (argvlist == NULL) {
3593 PyErr_NoMemory();
3594 goto fail_0; 3803 goto fail_0;
3595 } 3804 }
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 3805
3607 envlist = parse_envlist(env, &envc); 3806 envlist = parse_envlist(env, &envc);
3608 if (envlist == NULL) 3807 if (envlist == NULL)
3609 goto fail_1; 3808 goto fail_1;
3610 3809
3611 execve(path, argvlist, envlist); 3810 execve(path, argvlist, envlist);
3612 3811
3613 /* If we get here it's definitely an error */ 3812 /* If we get here it's definitely an error */
3614 3813
3615 (void) posix_error(); 3814 (void) posix_error();
3616 3815
3617 while (--envc >= 0) 3816 while (--envc >= 0)
3618 PyMem_DEL(envlist[envc]); 3817 PyMem_DEL(envlist[envc]);
3619 PyMem_DEL(envlist); 3818 PyMem_DEL(envlist);
3620 fail_1: 3819 fail_1:
3621 free_string_array(argvlist, lastarg); 3820 free_string_array(argvlist, argc);
3622 fail_0: 3821 fail_0:
3623 Py_DECREF(opath); 3822 Py_DECREF(opath);
3624 return NULL; 3823 return NULL;
3625 } 3824 }
3626 #endif /* HAVE_EXECV */ 3825 #endif /* HAVE_EXECV */
3627 3826
3827 #ifdef HAVE_FEXECVE
3828 PyDoc_STRVAR(posix_fexecve__doc__,
3829 "fexecve(fd, args, env)\n\n\
3830 Execute the program specified by a file descriptor with arguments and\n\
3831 environment, replacing the current process.\n\
3832 \n\
3833 fd: file descriptor of executable\n\
3834 args: tuple or list of arguments\n\
3835 env: dictionary of strings mapping to strings");
3836
3837 static PyObject *
3838 posix_fexecve(PyObject *self, PyObject *args)
3839 {
3840 int fd;
3841 PyObject *argv, *env;
3842 char **argvlist;
3843 char **envlist;
3844 Py_ssize_t argc, envc;
3845
3846 if (!PyArg_ParseTuple(args, "iOO:fexecve",
3847 &fd, &argv, &env))
3848 return NULL;
3849 if (!PyList_Check(argv) && !PyTuple_Check(argv)) {
3850 PyErr_SetString(PyExc_TypeError,
3851 "fexecve() arg 2 must be a tuple or list");
3852 return NULL;
3853 }
3854 argc = PySequence_Size(argv);
3855 if (!PyMapping_Check(env)) {
3856 PyErr_SetString(PyExc_TypeError,
3857 "fexecve() arg 3 must be a mapping object");
3858 return NULL;
3859 }
3860
3861 argvlist = parse_arglist(argv, &argc);
3862 if (argvlist == NULL)
3863 return NULL;
3864
3865 envlist = parse_envlist(env, &envc);
3866 if (envlist == NULL)
3867 goto fail;
3868
3869 fexecve(fd, argvlist, envlist);
3870
3871 /* If we get here it's definitely an error */
3872
3873 (void) posix_error();
3874
3875 while (--envc >= 0)
3876 PyMem_DEL(envlist[envc]);
3877 PyMem_DEL(envlist);
3878 fail:
3879 free_string_array(argvlist, argc);
3880 return NULL;
3881 }
3882 #endif /* HAVE_FEXECVE */
3628 3883
3629 #ifdef HAVE_SPAWNV 3884 #ifdef HAVE_SPAWNV
3630 PyDoc_STRVAR(posix_spawnv__doc__, 3885 PyDoc_STRVAR(posix_spawnv__doc__,
3631 "spawnv(mode, path, args)\n\n\ 3886 "spawnv(mode, path, args)\n\n\
3632 Execute the program 'path' in a new process.\n\ 3887 Execute the program 'path' in a new process.\n\
3633 \n\ 3888 \n\
3634 mode: mode of process creation\n\ 3889 mode: mode of process creation\n\
3635 path: path of executable file\n\ 3890 path: path of executable file\n\
3636 args: tuple or list of strings"); 3891 args: tuple or list of strings");
3637 3892
(...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after
4181 } 4436 }
4182 if (pid == -1) 4437 if (pid == -1)
4183 return posix_error(); 4438 return posix_error();
4184 if (result < 0) { 4439 if (result < 0) {
4185 /* Don't clobber the OSError if the fork failed. */ 4440 /* Don't clobber the OSError if the fork failed. */
4186 PyErr_SetString(PyExc_RuntimeError, 4441 PyErr_SetString(PyExc_RuntimeError,
4187 "not holding the import lock"); 4442 "not holding the import lock");
4188 return NULL; 4443 return NULL;
4189 } 4444 }
4190 return Py_BuildValue("(Ni)", PyLong_FromPid(pid), master_fd); 4445 return Py_BuildValue("(Ni)", PyLong_FromPid(pid), master_fd);
4446 }
4447 #endif
4448
4449 #ifdef HAVE_GETHOSTID
4450 PyDoc_STRVAR(posix_gethostid__doc__,
4451 "gethostid() -> hostid\n\n\
4452 Gets the host id, a unique 32-bit identifier for the current machine.");
gregory.p.smith 2011/03/16 06:15:53 don't claim that it is unique. :) gethostid and
4453
4454 static PyObject *
4455 posix_gethostid(PyObject *self, PyObject *noargs)
4456 {
4457 long res;
4458 errno = 0;
4459
4460 res = gethostid();
4461 if (errno != 0)
4462 return posix_error();
4463
4464 return PyLong_FromLong(res);
4465 }
4466 #endif
4467
4468 #ifdef HAVE_SETHOSTID
4469 PyDoc_STRVAR(posix_sethostid__doc__,
4470 "sethostid(hostid)\n\n\
4471 Sets the machine's host id to hostid. hostid is expected to be an integer\n\
4472 identifier.");
4473
4474 static PyObject *
4475 posix_sethostid(PyObject *self, PyObject *args)
4476 {
4477 long hostid;
4478 if (!PyArg_ParseTuple(args, "l:sethostid", &hostid))
4479 return NULL;
4480 #ifndef __FreeBSD__
4481 if (sethostid(hostid) == -1)
4482 return posix_error();
4483 #else
4484 errno = 0;
4485 sethostid(hostid);
4486 if (errno != 0)
4487 return posix_error();
4488 #endif
4489
4490 Py_RETURN_NONE;
4191 } 4491 }
4192 #endif 4492 #endif
4193 4493
4194 #ifdef HAVE_GETEGID 4494 #ifdef HAVE_GETEGID
4195 PyDoc_STRVAR(posix_getegid__doc__, 4495 PyDoc_STRVAR(posix_getegid__doc__,
4196 "getegid() -> egid\n\n\ 4496 "getegid() -> egid\n\n\
4197 Return the current process's effective group id."); 4497 Return the current process's effective group id.");
4198 4498
4199 static PyObject * 4499 static PyObject *
4200 posix_getegid(PyObject *self, PyObject *noargs) 4500 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)) 5273 if (!PyArg_ParseTuple(args, _Py_PARSE_PID "i:wait4", &pid, &options))
4974 return NULL; 5274 return NULL;
4975 5275
4976 Py_BEGIN_ALLOW_THREADS 5276 Py_BEGIN_ALLOW_THREADS
4977 pid = wait4(pid, &status, options, &ru); 5277 pid = wait4(pid, &status, options, &ru);
4978 Py_END_ALLOW_THREADS 5278 Py_END_ALLOW_THREADS
4979 5279
4980 return wait_helper(pid, WAIT_STATUS_INT(status), &ru); 5280 return wait_helper(pid, WAIT_STATUS_INT(status), &ru);
4981 } 5281 }
4982 #endif /* HAVE_WAIT4 */ 5282 #endif /* HAVE_WAIT4 */
5283
5284 #ifdef HAVE_WAITID
5285 PyDoc_STRVAR(posix_waitid__doc__,
5286 "waitid(idtype, id, options) -> waitid_result\n\n\
5287 Wait for the completion of one or more child processes.\n\n\
5288 idtype can be P_PID, P_PGID or P_ALL.\n\
5289 id specifies the pid to wait on.\n\
5290 options is constructed from the ORing of one or more of WEXITED, WSTOPPED\n\
5291 or WCONTINUED and additionally may be ORed with WNOHANG or WNOWAIT.\n\
5292 Returns either waitid_result or None if WNOHANG is specified and there are\n\
5293 no children in a waitable state.");
5294
5295 static PyObject *
5296 posix_waitid(PyObject *self, PyObject *args)
5297 {
5298 PyObject *result;
5299 idtype_t idtype;
5300 id_t id;
5301 int options, res;
5302 siginfo_t si;
5303 si.si_pid = 0;
5304 if (!PyArg_ParseTuple(args, "i" _Py_PARSE_PID "i:waitid", &idtype, &id, &opt ions))
5305 return NULL;
5306 Py_BEGIN_ALLOW_THREADS
5307 res = waitid(idtype, id, &si, options);
5308 Py_END_ALLOW_THREADS
5309 if (res == -1)
5310 return posix_error();
5311
5312 if (si.si_pid == 0)
5313 Py_RETURN_NONE;
5314
5315 result = PyStructSequence_New(&WaitidResultType);
5316 if (!result)
5317 return NULL;
5318
5319 PyStructSequence_SET_ITEM(result, 0, PyLong_FromPid(si.si_pid));
5320 PyStructSequence_SET_ITEM(result, 1, PyLong_FromPid(si.si_uid));
5321 PyStructSequence_SET_ITEM(result, 2, PyLong_FromLong((long)(si.si_signo)));
5322 PyStructSequence_SET_ITEM(result, 3, PyLong_FromLong((long)(si.si_status)));
5323 PyStructSequence_SET_ITEM(result, 4, PyLong_FromLong((long)(si.si_code)));
5324 if (PyErr_Occurred()) {
5325 Py_DECREF(result);
5326 return NULL;
5327 }
5328
5329 return result;
5330 }
5331 #endif
4983 5332
4984 #ifdef HAVE_WAITPID 5333 #ifdef HAVE_WAITPID
4985 PyDoc_STRVAR(posix_waitpid__doc__, 5334 PyDoc_STRVAR(posix_waitpid__doc__,
4986 "waitpid(pid, options) -> (pid, status)\n\n\ 5335 "waitpid(pid, options) -> (pid, status)\n\n\
4987 Wait for completion of a given child process."); 5336 Wait for completion of a given child process.");
4988 5337
4989 static PyObject * 5338 static PyObject *
4990 posix_waitpid(PyObject *self, PyObject *args) 5339 posix_waitpid(PyObject *self, PyObject *args)
4991 { 5340 {
4992 pid_t pid; 5341 pid_t pid;
(...skipping 595 matching lines...) Expand 10 before | Expand all | Expand 10 after
5588 if (!_PyVerify_fd_dup2(fd, fd2)) 5937 if (!_PyVerify_fd_dup2(fd, fd2))
5589 return posix_error(); 5938 return posix_error();
5590 Py_BEGIN_ALLOW_THREADS 5939 Py_BEGIN_ALLOW_THREADS
5591 res = dup2(fd, fd2); 5940 res = dup2(fd, fd2);
5592 Py_END_ALLOW_THREADS 5941 Py_END_ALLOW_THREADS
5593 if (res < 0) 5942 if (res < 0)
5594 return posix_error(); 5943 return posix_error();
5595 Py_INCREF(Py_None); 5944 Py_INCREF(Py_None);
5596 return Py_None; 5945 return Py_None;
5597 } 5946 }
5947
5948 #ifdef HAVE_LOCKF
5949 PyDoc_STRVAR(posix_lockf__doc__,
5950 "lockf(fd, cmd, len)\n\n\
5951 Apply, test or remove a POSIX lock on an open file descriptor.\n\n\
5952 fd is an open file descriptor.\n\
5953 cmd specifies the command to use - one of F_LOCK, F_TLOCK, F_ULOCK or\n\
5954 F_TEST.\n\
5955 len specifies the section of the file to lock.");
5956
5957 static PyObject *
5958 posix_lockf(PyObject *self, PyObject *args)
5959 {
5960 int fd, cmd, res;
5961 off_t len;
5962 if (!PyArg_ParseTuple(args, "iiO&:lockf",
5963 &fd, &cmd, PyParse_off_t, &len))
5964 return NULL;
5965
5966 Py_BEGIN_ALLOW_THREADS
5967 res = lockf(fd, cmd, len);
5968 Py_END_ALLOW_THREADS
5969
5970 if (res < 0)
5971 return posix_error();
5972
5973 Py_RETURN_NONE;
5974 }
5975 #endif
5598 5976
5599 5977
5600 PyDoc_STRVAR(posix_lseek__doc__, 5978 PyDoc_STRVAR(posix_lseek__doc__,
5601 "lseek(fd, pos, how) -> newpos\n\n\ 5979 "lseek(fd, pos, how) -> newpos\n\n\
5602 Set the current position of a file descriptor."); 5980 Set the current position of a file descriptor.");
5603 5981
5604 static PyObject * 5982 static PyObject *
5605 posix_lseek(PyObject *self, PyObject *args) 5983 posix_lseek(PyObject *self, PyObject *args)
5606 { 5984 {
5607 int fd, how; 5985 int fd, how;
5608 #if defined(MS_WIN64) || defined(MS_WINDOWS) 5986 #if defined(MS_WIN64) || defined(MS_WINDOWS)
5609 PY_LONG_LONG pos, res; 5987 PY_LONG_LONG pos, res;
5610 #else 5988 #else
5611 off_t pos, res; 5989 off_t pos, res;
5612 #endif 5990 #endif
5613 PyObject *posobj; 5991 if (!PyArg_ParseTuple(args, "iO&i:lseek", &fd, PyParse_off_t, &pos, &how))
5614 if (!PyArg_ParseTuple(args, "iOi:lseek", &fd, &posobj, &how))
5615 return NULL; 5992 return NULL;
5616 #ifdef SEEK_SET 5993 #ifdef SEEK_SET
5617 /* Turn 0, 1, 2 into SEEK_{SET,CUR,END} */ 5994 /* Turn 0, 1, 2 into SEEK_{SET,CUR,END} */
5618 switch (how) { 5995 switch (how) {
5619 case 0: how = SEEK_SET; break; 5996 case 0: how = SEEK_SET; break;
5620 case 1: how = SEEK_CUR; break; 5997 case 1: how = SEEK_CUR; break;
5621 case 2: how = SEEK_END; break; 5998 case 2: how = SEEK_END; break;
5622 } 5999 }
5623 #endif /* SEEK_END */ 6000 #endif /* SEEK_END */
5624
5625 #if !defined(HAVE_LARGEFILE_SUPPORT)
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 6001
5634 if (!_PyVerify_fd(fd)) 6002 if (!_PyVerify_fd(fd))
5635 return posix_error(); 6003 return posix_error();
5636 Py_BEGIN_ALLOW_THREADS 6004 Py_BEGIN_ALLOW_THREADS
5637 #if defined(MS_WIN64) || defined(MS_WINDOWS) 6005 #if defined(MS_WIN64) || defined(MS_WINDOWS)
5638 res = _lseeki64(fd, pos, how); 6006 res = _lseeki64(fd, pos, how);
5639 #else 6007 #else
5640 res = lseek(fd, pos, how); 6008 res = lseek(fd, pos, how);
5641 #endif 6009 #endif
5642 Py_END_ALLOW_THREADS 6010 Py_END_ALLOW_THREADS
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
5679 Py_END_ALLOW_THREADS 6047 Py_END_ALLOW_THREADS
5680 if (n < 0) { 6048 if (n < 0) {
5681 Py_DECREF(buffer); 6049 Py_DECREF(buffer);
5682 return posix_error(); 6050 return posix_error();
5683 } 6051 }
5684 if (n != size) 6052 if (n != size)
5685 _PyBytes_Resize(&buffer, n); 6053 _PyBytes_Resize(&buffer, n);
5686 return buffer; 6054 return buffer;
5687 } 6055 }
5688 6056
6057 #if defined(HAVE_READV) || defined(HAVE_WRITEV)
6058 static int
6059 iov_setup(struct iovec **iov, Py_buffer **buf, PyObject *seq, int cnt, int type)
6060 {
6061 int i, j;
6062 *iov = PyMem_New(struct iovec, cnt);
6063 if (*iov == NULL) {
6064 PyErr_NoMemory();
6065 return 0;
6066 }
6067 *buf = PyMem_New(Py_buffer, cnt);
6068 if (*buf == NULL) {
6069 PyMem_Del(*iov);
6070 PyErr_NoMemory();
6071 return 0;
6072 }
6073
6074 for (i = 0; i < cnt; i++) {
6075 if (PyObject_GetBuffer(PySequence_GetItem(seq, i), &(*buf)[i],
6076 type) == -1) {
6077 PyMem_Del(*iov);
6078 for (j = 0; j < i; j++) {
6079 PyBuffer_Release(&(*buf)[j]);
6080 }
6081 PyMem_Del(*buf);
6082 return 0;
6083 }
6084 (*iov)[i].iov_base = (*buf)[i].buf;
6085 (*iov)[i].iov_len = (*buf)[i].len;
6086 }
6087 return 1;
6088 }
6089
6090 static void
6091 iov_cleanup(struct iovec *iov, Py_buffer *buf, int cnt)
6092 {
6093 int i;
6094 PyMem_Del(iov);
6095 for (i = 0; i < cnt; i++) {
6096 PyBuffer_Release(&buf[i]);
6097 }
6098 PyMem_Del(buf);
6099 }
6100 #endif
6101
6102 #ifdef HAVE_READV
6103 PyDoc_STRVAR(posix_readv__doc__,
6104 "readv(fd, buffers) -> bytesread\n\n\
6105 Read from a file descriptor into a number of writable buffers. buffers\n\
6106 is an arbitrary sequence of writable buffers.\n\
6107 Returns the total number of bytes read.");
6108
6109 static PyObject *
6110 posix_readv(PyObject *self, PyObject *args)
6111 {
6112 int fd, cnt;
6113 Py_ssize_t n;
6114 PyObject *seq;
6115 struct iovec *iov;
6116 Py_buffer *buf;
6117
6118 if (!PyArg_ParseTuple(args, "iO:readv", &fd, &seq))
6119 return NULL;
6120 if (!PySequence_Check(seq)) {
6121 PyErr_SetString(PyExc_TypeError,
6122 "readv() arg 2 must be a sequence");
6123 return NULL;
6124 }
6125 cnt = PySequence_Size(seq);
6126
6127 if (!iov_setup(&iov, &buf, seq, cnt, PyBUF_WRITABLE))
6128 return NULL;
6129
6130 Py_BEGIN_ALLOW_THREADS
6131 n = readv(fd, iov, cnt);
6132 Py_END_ALLOW_THREADS
6133
6134 iov_cleanup(iov, buf, cnt);
6135 return PyLong_FromSsize_t(n);
6136 }
6137 #endif
6138
6139 #ifdef HAVE_PREAD
6140 PyDoc_STRVAR(posix_pread__doc__,
6141 "pread(fd, buffersize, offset) -> string\n\n\
6142 Read from a file descriptor, fd, at a position of offset. It will read up\n\
6143 to buffersize number of bytes. The file offset remains unchanged.");
6144
6145 static PyObject *
6146 posix_pread(PyObject *self, PyObject *args)
6147 {
6148 int fd, size;
6149 off_t offset;
6150 Py_ssize_t n;
6151 PyObject *buffer;
6152 if (!PyArg_ParseTuple(args, "iiO&:pread", &fd, &size, PyParse_off_t, &offset ))
6153 return NULL;
6154
6155 if (size < 0) {
6156 errno = EINVAL;
6157 return posix_error();
6158 }
6159 buffer = PyBytes_FromStringAndSize((char *)NULL, size);
6160 if (buffer == NULL)
6161 return NULL;
6162 if (!_PyVerify_fd(fd)) {
6163 Py_DECREF(buffer);
6164 return posix_error();
6165 }
6166 Py_BEGIN_ALLOW_THREADS
6167 n = pread(fd, PyBytes_AS_STRING(buffer), size, offset);
6168 Py_END_ALLOW_THREADS
6169 if (n < 0) {
6170 Py_DECREF(buffer);
6171 return posix_error();
6172 }
6173 if (n != size)
6174 _PyBytes_Resize(&buffer, n);
6175 return buffer;
6176 }
6177 #endif
5689 6178
5690 PyDoc_STRVAR(posix_write__doc__, 6179 PyDoc_STRVAR(posix_write__doc__,
5691 "write(fd, string) -> byteswritten\n\n\ 6180 "write(fd, string) -> byteswritten\n\n\
5692 Write a string to a file descriptor."); 6181 Write a string to a file descriptor.");
5693 6182
5694 static PyObject * 6183 static PyObject *
5695 posix_write(PyObject *self, PyObject *args) 6184 posix_write(PyObject *self, PyObject *args)
5696 { 6185 {
5697 Py_buffer pbuf; 6186 Py_buffer pbuf;
5698 int fd; 6187 int fd;
(...skipping 14 matching lines...) Expand all
5713 #else 6202 #else
5714 size = write(fd, pbuf.buf, (size_t)len); 6203 size = write(fd, pbuf.buf, (size_t)len);
5715 #endif 6204 #endif
5716 Py_END_ALLOW_THREADS 6205 Py_END_ALLOW_THREADS
5717 PyBuffer_Release(&pbuf); 6206 PyBuffer_Release(&pbuf);
5718 if (size < 0) 6207 if (size < 0)
5719 return posix_error(); 6208 return posix_error();
5720 return PyLong_FromSsize_t(size); 6209 return PyLong_FromSsize_t(size);
5721 } 6210 }
5722 6211
6212 #ifdef HAVE_WRITEV
6213 PyDoc_STRVAR(posix_writev__doc__,
6214 "writev(fd, buffers) -> byteswritten\n\n\
6215 Write the contents of buffers to a file descriptor, where buffers is an\n\
6216 arbitrary sequence of buffers.\n\
6217 Returns the total bytes written.");
6218
6219 static PyObject *
6220 posix_writev(PyObject *self, PyObject *args)
6221 {
6222 int fd, cnt;
6223 Py_ssize_t res;
6224 PyObject *seq;
6225 struct iovec *iov;
6226 Py_buffer *buf;
6227 if (!PyArg_ParseTuple(args, "iO:writev", &fd, &seq))
6228 return NULL;
6229 if (!PySequence_Check(seq)) {
6230 PyErr_SetString(PyExc_TypeError,
6231 "writev() arg 2 must be a sequence");
6232 return NULL;
6233 }
6234 cnt = PySequence_Size(seq);
6235
6236 if (!iov_setup(&iov, &buf, seq, cnt, PyBUF_SIMPLE)) {
6237 return NULL;
6238 }
6239
6240 Py_BEGIN_ALLOW_THREADS
6241 res = writev(fd, iov, cnt);
6242 Py_END_ALLOW_THREADS
6243
6244 iov_cleanup(iov, buf, cnt);
6245 return PyLong_FromSsize_t(res);
6246 }
6247 #endif
6248
6249 #ifdef HAVE_PWRITE
6250 PyDoc_STRVAR(posix_pwrite__doc__,
6251 "pwrite(fd, string, offset) -> byteswritten\n\n\
6252 Write string to a file descriptor, fd, from offset, leaving the file\n\
6253 offset unchanged.");
6254
6255 static PyObject *
6256 posix_pwrite(PyObject *self, PyObject *args)
6257 {
6258 Py_buffer pbuf;
6259 int fd;
6260 off_t offset;
6261 Py_ssize_t size;
6262
6263 if (!PyArg_ParseTuple(args, "iy*O&:pwrite", &fd, &pbuf, PyParse_off_t, &offs et))
6264 return NULL;
6265
6266 if (!_PyVerify_fd(fd)) {
6267 PyBuffer_Release(&pbuf);
6268 return posix_error();
6269 }
6270 Py_BEGIN_ALLOW_THREADS
6271 size = pwrite(fd, pbuf.buf, (size_t)pbuf.len, offset);
6272 Py_END_ALLOW_THREADS
6273 PyBuffer_Release(&pbuf);
6274 if (size < 0)
6275 return posix_error();
6276 return PyLong_FromSsize_t(size);
6277 }
6278 #endif
5723 6279
5724 PyDoc_STRVAR(posix_fstat__doc__, 6280 PyDoc_STRVAR(posix_fstat__doc__,
5725 "fstat(fd) -> stat result\n\n\ 6281 "fstat(fd) -> stat result\n\n\
5726 Like stat(), but for an open file descriptor."); 6282 Like stat(), but for an open file descriptor.");
5727 6283
5728 static PyObject * 6284 static PyObject *
5729 posix_fstat(PyObject *self, PyObject *args) 6285 posix_fstat(PyObject *self, PyObject *args)
5730 { 6286 {
5731 int fd; 6287 int fd;
5732 STRUCT_STAT st; 6288 STRUCT_STAT st;
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
5924 PyDoc_STRVAR(posix_ftruncate__doc__, 6480 PyDoc_STRVAR(posix_ftruncate__doc__,
5925 "ftruncate(fd, length)\n\n\ 6481 "ftruncate(fd, length)\n\n\
5926 Truncate a file to a specified length."); 6482 Truncate a file to a specified length.");
5927 6483
5928 static PyObject * 6484 static PyObject *
5929 posix_ftruncate(PyObject *self, PyObject *args) 6485 posix_ftruncate(PyObject *self, PyObject *args)
5930 { 6486 {
5931 int fd; 6487 int fd;
5932 off_t length; 6488 off_t length;
5933 int res; 6489 int res;
5934 PyObject *lenobj;
5935 6490
5936 if (!PyArg_ParseTuple(args, "iO:ftruncate", &fd, &lenobj)) 6491 if (!PyArg_ParseTuple(args, "iO&:ftruncate", &fd, PyParse_off_t, &length))
5937 return NULL;
5938
5939 #if !defined(HAVE_LARGEFILE_SUPPORT)
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; 6492 return NULL;
5947 6493
5948 Py_BEGIN_ALLOW_THREADS 6494 Py_BEGIN_ALLOW_THREADS
5949 res = ftruncate(fd, length); 6495 res = ftruncate(fd, length);
5950 Py_END_ALLOW_THREADS 6496 Py_END_ALLOW_THREADS
5951 if (res < 0) 6497 if (res < 0)
5952 return posix_error(); 6498 return posix_error();
5953 Py_INCREF(Py_None); 6499 Py_INCREF(Py_None);
5954 return Py_None; 6500 return Py_None;
6501 }
6502 #endif
6503
6504 #ifdef HAVE_TRUNCATE
6505 PyDoc_STRVAR(posix_truncate__doc__,
6506 "truncate(path, length)\n\n\
6507 Truncate the file given by path to length bytes.");
6508
6509 static PyObject *
6510 posix_truncate(PyObject *self, PyObject *args)
6511 {
6512 PyObject *opath;
6513 const char *path;
6514 off_t length;
6515 int res;
6516
6517 if (!PyArg_ParseTuple(args, "O&O&:truncate",
6518 PyUnicode_FSConverter, &opath, PyParse_off_t, &length))
6519 return NULL;
6520 path = PyBytes_AsString(opath);
6521
6522 Py_BEGIN_ALLOW_THREADS
6523 res = truncate(path, length);
6524 Py_END_ALLOW_THREADS
6525 Py_DECREF(opath);
6526 if (res < 0)
6527 return posix_error();
6528 Py_RETURN_NONE;
6529 }
6530 #endif
6531
6532 #ifdef HAVE_POSIX_FALLOCATE
6533 PyDoc_STRVAR(posix_posix_fallocate__doc__,
6534 "posix_fallocate(fd, offset, len)\n\n\
6535 Ensures that enough disk space is allocated for the file specified by fd\n\
6536 starting from offset and continuing for len bytes.");
6537
6538 static PyObject *
6539 posix_posix_fallocate(PyObject *self, PyObject *args)
6540 {
6541 off_t len, offset;
6542 int res, fd;
6543
6544 if (!PyArg_ParseTuple(args, "iO&O&:posix_fallocate",
6545 &fd, PyParse_off_t, &offset, PyParse_off_t, &len))
6546 return NULL;
6547
6548 Py_BEGIN_ALLOW_THREADS
6549 res = posix_fallocate(fd, offset, len);
6550 Py_END_ALLOW_THREADS
6551 if (res != 0) {
6552 errno = res;
6553 return posix_error();
6554 }
6555 Py_RETURN_NONE;
6556 }
6557 #endif
6558
6559 #ifdef HAVE_POSIX_FADVISE
6560 PyDoc_STRVAR(posix_posix_fadvise__doc__,
6561 "posix_fadvise(fd, offset, len, advice)\n\n\
6562 Announces an intention to access data in a specific pattern thus allowing\n\
6563 the kernel to make optimizations.\n\
6564 The advice applies to the region of the file specified by fd starting at\n\
6565 offset and continuing for len bytes.\n\
6566 advice is one of POSIX_FADV_NORMAL, POSIX_FADV_SEQUENTIAL,\n\
6567 POSIX_FADV_RANDOM, POSIX_FADV_NOREUSE, POSIX_FADV_WILLNEED or\n\
6568 POSIX_FADV_DONTNEED.");
6569
6570 static PyObject *
6571 posix_posix_fadvise(PyObject *self, PyObject *args)
6572 {
6573 off_t len, offset;
6574 int res, fd, advice;
6575
6576 if (!PyArg_ParseTuple(args, "iO&O&i:posix_fadvise",
6577 &fd, PyParse_off_t, &offset, PyParse_off_t, &len, &advice))
6578 return NULL;
6579
6580 Py_BEGIN_ALLOW_THREADS
6581 res = posix_fadvise(fd, offset, len, advice);
6582 Py_END_ALLOW_THREADS
6583 if (res != 0) {
6584 errno = res;
6585 return posix_error();
6586 }
6587 Py_RETURN_NONE;
5955 } 6588 }
5956 #endif 6589 #endif
5957 6590
5958 #ifdef HAVE_PUTENV 6591 #ifdef HAVE_PUTENV
5959 PyDoc_STRVAR(posix_putenv__doc__, 6592 PyDoc_STRVAR(posix_putenv__doc__,
5960 "putenv(key, value)\n\n\ 6593 "putenv(key, value)\n\n\
5961 Change or add an environment variable."); 6594 Change or add an environment variable.");
5962 6595
5963 /* Save putenv() parameters as values here, so we can collect them when they 6596 /* Save putenv() parameters as values here, so we can collect them when they
5964 * get re-set with another call for the same key. */ 6597 * 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 8461 #ifdef HAVE_SYSTEM
7829 {"system", posix_system, METH_VARARGS, posix_system__doc__}, 8462 {"system", posix_system, METH_VARARGS, posix_system__doc__},
7830 #endif 8463 #endif
7831 {"umask", posix_umask, METH_VARARGS, posix_umask__doc__}, 8464 {"umask", posix_umask, METH_VARARGS, posix_umask__doc__},
7832 #ifdef HAVE_UNAME 8465 #ifdef HAVE_UNAME
7833 {"uname", posix_uname, METH_NOARGS, posix_uname__doc__}, 8466 {"uname", posix_uname, METH_NOARGS, posix_uname__doc__},
7834 #endif /* HAVE_UNAME */ 8467 #endif /* HAVE_UNAME */
7835 {"unlink", posix_unlink, METH_VARARGS, posix_unlink__doc__}, 8468 {"unlink", posix_unlink, METH_VARARGS, posix_unlink__doc__},
7836 {"remove", posix_unlink, METH_VARARGS, posix_remove__doc__}, 8469 {"remove", posix_unlink, METH_VARARGS, posix_remove__doc__},
7837 {"utime", posix_utime, METH_VARARGS, posix_utime__doc__}, 8470 {"utime", posix_utime, METH_VARARGS, posix_utime__doc__},
8471 #ifdef HAVE_FUTIMES
8472 {"futimes", posix_futimes, METH_VARARGS, posix_futimes__doc__},
8473 #endif
8474 #ifdef HAVE_LUTIMES
8475 {"lutimes", posix_lutimes, METH_VARARGS, posix_lutimes__doc__},
8476 #endif
8477 #ifdef HAVE_FUTIMENS
8478 {"futimens", posix_futimens, METH_VARARGS, posix_futimens__doc__},
8479 #endif
7838 #ifdef HAVE_TIMES 8480 #ifdef HAVE_TIMES
7839 {"times", posix_times, METH_NOARGS, posix_times__doc__}, 8481 {"times", posix_times, METH_NOARGS, posix_times__doc__},
7840 #endif /* HAVE_TIMES */ 8482 #endif /* HAVE_TIMES */
7841 {"_exit", posix__exit, METH_VARARGS, posix__exit__doc__}, 8483 {"_exit", posix__exit, METH_VARARGS, posix__exit__doc__},
7842 #ifdef HAVE_EXECV 8484 #ifdef HAVE_EXECV
7843 {"execv", posix_execv, METH_VARARGS, posix_execv__doc__}, 8485 {"execv", posix_execv, METH_VARARGS, posix_execv__doc__},
7844 {"execve", posix_execve, METH_VARARGS, posix_execve__doc__}, 8486 {"execve", posix_execve, METH_VARARGS, posix_execve__doc__},
7845 #endif /* HAVE_EXECV */ 8487 #endif /* HAVE_EXECV */
8488 #ifdef HAVE_FEXECVE
8489 {"fexecve", posix_fexecve, METH_VARARGS, posix_fexecve__doc__},
8490 #endif
7846 #ifdef HAVE_SPAWNV 8491 #ifdef HAVE_SPAWNV
7847 {"spawnv", posix_spawnv, METH_VARARGS, posix_spawnv__doc__}, 8492 {"spawnv", posix_spawnv, METH_VARARGS, posix_spawnv__doc__},
7848 {"spawnve", posix_spawnve, METH_VARARGS, posix_spawnve__doc__}, 8493 {"spawnve", posix_spawnve, METH_VARARGS, posix_spawnve__doc__},
7849 #if defined(PYOS_OS2) 8494 #if defined(PYOS_OS2)
7850 {"spawnvp", posix_spawnvp, METH_VARARGS, posix_spawnvp__doc__}, 8495 {"spawnvp", posix_spawnvp, METH_VARARGS, posix_spawnvp__doc__},
7851 {"spawnvpe", posix_spawnvpe, METH_VARARGS, posix_spawnvpe__doc__}, 8496 {"spawnvpe", posix_spawnvpe, METH_VARARGS, posix_spawnvpe__doc__},
7852 #endif /* PYOS_OS2 */ 8497 #endif /* PYOS_OS2 */
7853 #endif /* HAVE_SPAWNV */ 8498 #endif /* HAVE_SPAWNV */
7854 #ifdef HAVE_FORK1 8499 #ifdef HAVE_FORK1
7855 {"fork1", posix_fork1, METH_NOARGS, posix_fork1__doc__}, 8500 {"fork1", posix_fork1, METH_NOARGS, posix_fork1__doc__},
7856 #endif /* HAVE_FORK1 */ 8501 #endif /* HAVE_FORK1 */
7857 #ifdef HAVE_FORK 8502 #ifdef HAVE_FORK
7858 {"fork", posix_fork, METH_NOARGS, posix_fork__doc__}, 8503 {"fork", posix_fork, METH_NOARGS, posix_fork__doc__},
7859 #endif /* HAVE_FORK */ 8504 #endif /* HAVE_FORK */
7860 #if defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX) 8505 #if defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX)
7861 {"openpty", posix_openpty, METH_NOARGS, posix_openpty__doc__}, 8506 {"openpty", posix_openpty, METH_NOARGS, posix_openpty__doc__},
7862 #endif /* HAVE_OPENPTY || HAVE__GETPTY || HAVE_DEV_PTMX */ 8507 #endif /* HAVE_OPENPTY || HAVE__GETPTY || HAVE_DEV_PTMX */
7863 #ifdef HAVE_FORKPTY 8508 #ifdef HAVE_FORKPTY
7864 {"forkpty", posix_forkpty, METH_NOARGS, posix_forkpty__doc__}, 8509 {"forkpty", posix_forkpty, METH_NOARGS, posix_forkpty__doc__},
7865 #endif /* HAVE_FORKPTY */ 8510 #endif /* HAVE_FORKPTY */
8511 #ifdef HAVE_GETHOSTID
8512 {"gethostid", posix_gethostid, METH_NOARGS, posix_gethostid__doc__},
8513 #endif
8514 #ifdef HAVE_SETHOSTID
8515 {"sethostid", posix_sethostid, METH_VARARGS, posix_sethostid__doc__},
8516 #endif
7866 #ifdef HAVE_GETEGID 8517 #ifdef HAVE_GETEGID
7867 {"getegid", posix_getegid, METH_NOARGS, posix_getegid__doc__}, 8518 {"getegid", posix_getegid, METH_NOARGS, posix_getegid__doc__},
7868 #endif /* HAVE_GETEGID */ 8519 #endif /* HAVE_GETEGID */
7869 #ifdef HAVE_GETEUID 8520 #ifdef HAVE_GETEUID
7870 {"geteuid", posix_geteuid, METH_NOARGS, posix_geteuid__doc__}, 8521 {"geteuid", posix_geteuid, METH_NOARGS, posix_geteuid__doc__},
7871 #endif /* HAVE_GETEUID */ 8522 #endif /* HAVE_GETEUID */
7872 #ifdef HAVE_GETGID 8523 #ifdef HAVE_GETGID
7873 {"getgid", posix_getgid, METH_NOARGS, posix_getgid__doc__}, 8524 {"getgid", posix_getgid, METH_NOARGS, posix_getgid__doc__},
7874 #endif /* HAVE_GETGID */ 8525 #endif /* HAVE_GETGID */
7875 #ifdef HAVE_GETGROUPS 8526 #ifdef HAVE_GETGROUPS
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
7934 #endif /* HAVE_SETPGRP */ 8585 #endif /* HAVE_SETPGRP */
7935 #ifdef HAVE_WAIT 8586 #ifdef HAVE_WAIT
7936 {"wait", posix_wait, METH_NOARGS, posix_wait__doc__}, 8587 {"wait", posix_wait, METH_NOARGS, posix_wait__doc__},
7937 #endif /* HAVE_WAIT */ 8588 #endif /* HAVE_WAIT */
7938 #ifdef HAVE_WAIT3 8589 #ifdef HAVE_WAIT3
7939 {"wait3", posix_wait3, METH_VARARGS, posix_wait3__doc__}, 8590 {"wait3", posix_wait3, METH_VARARGS, posix_wait3__doc__},
7940 #endif /* HAVE_WAIT3 */ 8591 #endif /* HAVE_WAIT3 */
7941 #ifdef HAVE_WAIT4 8592 #ifdef HAVE_WAIT4
7942 {"wait4", posix_wait4, METH_VARARGS, posix_wait4__doc__}, 8593 {"wait4", posix_wait4, METH_VARARGS, posix_wait4__doc__},
7943 #endif /* HAVE_WAIT4 */ 8594 #endif /* HAVE_WAIT4 */
8595 #ifdef HAVE_WAITID
8596 {"waitid", posix_waitid, METH_VARARGS, posix_waitid__doc__},
8597 #endif
7944 #if defined(HAVE_WAITPID) || defined(HAVE_CWAIT) 8598 #if defined(HAVE_WAITPID) || defined(HAVE_CWAIT)
7945 {"waitpid", posix_waitpid, METH_VARARGS, posix_waitpid__doc__}, 8599 {"waitpid", posix_waitpid, METH_VARARGS, posix_waitpid__doc__},
7946 #endif /* HAVE_WAITPID */ 8600 #endif /* HAVE_WAITPID */
7947 #ifdef HAVE_GETSID 8601 #ifdef HAVE_GETSID
7948 {"getsid", posix_getsid, METH_VARARGS, posix_getsid__doc__}, 8602 {"getsid", posix_getsid, METH_VARARGS, posix_getsid__doc__},
7949 #endif /* HAVE_GETSID */ 8603 #endif /* HAVE_GETSID */
7950 #ifdef HAVE_SETSID 8604 #ifdef HAVE_SETSID
7951 {"setsid", posix_setsid, METH_NOARGS, posix_setsid__doc__}, 8605 {"setsid", posix_setsid, METH_NOARGS, posix_setsid__doc__},
7952 #endif /* HAVE_SETSID */ 8606 #endif /* HAVE_SETSID */
7953 #ifdef HAVE_SETPGID 8607 #ifdef HAVE_SETPGID
7954 {"setpgid", posix_setpgid, METH_VARARGS, posix_setpgid__doc__}, 8608 {"setpgid", posix_setpgid, METH_VARARGS, posix_setpgid__doc__},
7955 #endif /* HAVE_SETPGID */ 8609 #endif /* HAVE_SETPGID */
7956 #ifdef HAVE_TCGETPGRP 8610 #ifdef HAVE_TCGETPGRP
7957 {"tcgetpgrp", posix_tcgetpgrp, METH_VARARGS, posix_tcgetpgrp__doc__}, 8611 {"tcgetpgrp", posix_tcgetpgrp, METH_VARARGS, posix_tcgetpgrp__doc__},
7958 #endif /* HAVE_TCGETPGRP */ 8612 #endif /* HAVE_TCGETPGRP */
7959 #ifdef HAVE_TCSETPGRP 8613 #ifdef HAVE_TCSETPGRP
7960 {"tcsetpgrp", posix_tcsetpgrp, METH_VARARGS, posix_tcsetpgrp__doc__}, 8614 {"tcsetpgrp", posix_tcsetpgrp, METH_VARARGS, posix_tcsetpgrp__doc__},
7961 #endif /* HAVE_TCSETPGRP */ 8615 #endif /* HAVE_TCSETPGRP */
7962 {"open", posix_open, METH_VARARGS, posix_open__doc__}, 8616 {"open", posix_open, METH_VARARGS, posix_open__doc__},
7963 {"close", posix_close, METH_VARARGS, posix_close__doc__}, 8617 {"close", posix_close, METH_VARARGS, posix_close__doc__},
7964 {"closerange", posix_closerange, METH_VARARGS, posix_closerange__doc__} , 8618 {"closerange", posix_closerange, METH_VARARGS, posix_closerange__doc__} ,
7965 {"device_encoding", device_encoding, METH_VARARGS, device_encoding__doc__}, 8619 {"device_encoding", device_encoding, METH_VARARGS, device_encoding__doc__},
7966 {"dup", posix_dup, METH_VARARGS, posix_dup__doc__}, 8620 {"dup", posix_dup, METH_VARARGS, posix_dup__doc__},
7967 {"dup2", posix_dup2, METH_VARARGS, posix_dup2__doc__}, 8621 {"dup2", posix_dup2, METH_VARARGS, posix_dup2__doc__},
8622 #ifdef HAVE_LOCKF
8623 {"lockf", posix_lockf, METH_VARARGS, posix_lockf__doc__},
8624 #endif
7968 {"lseek", posix_lseek, METH_VARARGS, posix_lseek__doc__}, 8625 {"lseek", posix_lseek, METH_VARARGS, posix_lseek__doc__},
7969 {"read", posix_read, METH_VARARGS, posix_read__doc__}, 8626 {"read", posix_read, METH_VARARGS, posix_read__doc__},
8627 #ifdef HAVE_READV
8628 {"readv", posix_readv, METH_VARARGS, posix_readv__doc__},
8629 #endif
8630 #ifdef HAVE_PREAD
8631 {"pread", posix_pread, METH_VARARGS, posix_pread__doc__},
8632 #endif
7970 {"write", posix_write, METH_VARARGS, posix_write__doc__}, 8633 {"write", posix_write, METH_VARARGS, posix_write__doc__},
8634 #ifdef HAVE_WRITEV
8635 {"writev", posix_writev, METH_VARARGS, posix_writev__doc__},
8636 #endif
8637 #ifdef HAVE_PWRITE
8638 {"pwrite", posix_pwrite, METH_VARARGS, posix_pwrite__doc__},
8639 #endif
7971 {"fstat", posix_fstat, METH_VARARGS, posix_fstat__doc__}, 8640 {"fstat", posix_fstat, METH_VARARGS, posix_fstat__doc__},
7972 {"isatty", posix_isatty, METH_VARARGS, posix_isatty__doc__}, 8641 {"isatty", posix_isatty, METH_VARARGS, posix_isatty__doc__},
7973 #ifdef HAVE_PIPE 8642 #ifdef HAVE_PIPE
7974 {"pipe", posix_pipe, METH_NOARGS, posix_pipe__doc__}, 8643 {"pipe", posix_pipe, METH_NOARGS, posix_pipe__doc__},
7975 #endif 8644 #endif
7976 #ifdef HAVE_MKFIFO 8645 #ifdef HAVE_MKFIFO
7977 {"mkfifo", posix_mkfifo, METH_VARARGS, posix_mkfifo__doc__}, 8646 {"mkfifo", posix_mkfifo, METH_VARARGS, posix_mkfifo__doc__},
7978 #endif 8647 #endif
7979 #if defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV) 8648 #if defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV)
7980 {"mknod", posix_mknod, METH_VARARGS, posix_mknod__doc__}, 8649 {"mknod", posix_mknod, METH_VARARGS, posix_mknod__doc__},
7981 #endif 8650 #endif
7982 #ifdef HAVE_DEVICE_MACROS 8651 #ifdef HAVE_DEVICE_MACROS
7983 {"major", posix_major, METH_VARARGS, posix_major__doc__}, 8652 {"major", posix_major, METH_VARARGS, posix_major__doc__},
7984 {"minor", posix_minor, METH_VARARGS, posix_minor__doc__}, 8653 {"minor", posix_minor, METH_VARARGS, posix_minor__doc__},
7985 {"makedev", posix_makedev, METH_VARARGS, posix_makedev__doc__}, 8654 {"makedev", posix_makedev, METH_VARARGS, posix_makedev__doc__},
7986 #endif 8655 #endif
7987 #ifdef HAVE_FTRUNCATE 8656 #ifdef HAVE_FTRUNCATE
7988 {"ftruncate", posix_ftruncate, METH_VARARGS, posix_ftruncate__doc__}, 8657 {"ftruncate", posix_ftruncate, METH_VARARGS, posix_ftruncate__doc__},
8658 #endif
8659 #ifdef HAVE_TRUNCATE
8660 {"truncate", posix_truncate, METH_VARARGS, posix_truncate__doc__},
8661 #endif
8662 #ifdef HAVE_POSIX_FALLOCATE
8663 {"posix_fallocate", posix_posix_fallocate, METH_VARARGS, posix_posix_falloca te__doc__},
8664 #endif
8665 #ifdef HAVE_POSIX_FADVISE
8666 {"posix_fadvise", posix_posix_fadvise, METH_VARARGS, posix_posix_fadvise__ doc__},
7989 #endif 8667 #endif
7990 #ifdef HAVE_PUTENV 8668 #ifdef HAVE_PUTENV
7991 {"putenv", posix_putenv, METH_VARARGS, posix_putenv__doc__}, 8669 {"putenv", posix_putenv, METH_VARARGS, posix_putenv__doc__},
7992 #endif 8670 #endif
7993 #ifdef HAVE_UNSETENV 8671 #ifdef HAVE_UNSETENV
7994 {"unsetenv", posix_unsetenv, METH_VARARGS, posix_unsetenv__doc__}, 8672 {"unsetenv", posix_unsetenv, METH_VARARGS, posix_unsetenv__doc__},
7995 #endif 8673 #endif
7996 {"strerror", posix_strerror, METH_VARARGS, posix_strerror__doc__}, 8674 {"strerror", posix_strerror, METH_VARARGS, posix_strerror__doc__},
7997 #ifdef HAVE_FCHDIR 8675 #ifdef HAVE_FCHDIR
7998 {"fchdir", posix_fchdir, METH_O, posix_fchdir__doc__}, 8676 {"fchdir", posix_fchdir, METH_O, posix_fchdir__doc__},
7999 #endif 8677 #endif
8000 #ifdef HAVE_FSYNC 8678 #ifdef HAVE_FSYNC
8001 {"fsync", posix_fsync, METH_O, posix_fsync__doc__}, 8679 {"fsync", posix_fsync, METH_O, posix_fsync__doc__},
8680 #endif
8681 #ifdef HAVE_SYNC
8682 {"sync", posix_sync, METH_NOARGS, posix_sync__doc__},
8002 #endif 8683 #endif
8003 #ifdef HAVE_FDATASYNC 8684 #ifdef HAVE_FDATASYNC
8004 {"fdatasync", posix_fdatasync, METH_O, posix_fdatasync__doc__}, 8685 {"fdatasync", posix_fdatasync, METH_O, posix_fdatasync__doc__},
8005 #endif 8686 #endif
8006 #ifdef HAVE_SYS_WAIT_H 8687 #ifdef HAVE_SYS_WAIT_H
8007 #ifdef WCOREDUMP 8688 #ifdef WCOREDUMP
8008 {"WCOREDUMP", posix_WCOREDUMP, METH_VARARGS, posix_WCOREDUMP__doc__}, 8689 {"WCOREDUMP", posix_WCOREDUMP, METH_VARARGS, posix_WCOREDUMP__doc__},
8009 #endif /* WCOREDUMP */ 8690 #endif /* WCOREDUMP */
8010 #ifdef WIFCONTINUED 8691 #ifdef WIFCONTINUED
8011 {"WIFCONTINUED",posix_WIFCONTINUED, METH_VARARGS, posix_WIFCONTINUED__doc__} , 8692 {"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; 9032 if (ins(d, "EX_NOTFOUND", (long)EX_NOTFOUND)) return -1;
8352 #endif /* EX_NOTFOUND */ 9033 #endif /* EX_NOTFOUND */
8353 9034
8354 /* statvfs */ 9035 /* statvfs */
8355 #ifdef ST_RDONLY 9036 #ifdef ST_RDONLY
8356 if (ins(d, "ST_RDONLY", (long)ST_RDONLY)) return -1; 9037 if (ins(d, "ST_RDONLY", (long)ST_RDONLY)) return -1;
8357 #endif /* ST_RDONLY */ 9038 #endif /* ST_RDONLY */
8358 #ifdef ST_NOSUID 9039 #ifdef ST_NOSUID
8359 if (ins(d, "ST_NOSUID", (long)ST_NOSUID)) return -1; 9040 if (ins(d, "ST_NOSUID", (long)ST_NOSUID)) return -1;
8360 #endif /* ST_NOSUID */ 9041 #endif /* ST_NOSUID */
9042
9043 /* constants for posix_fadvise */
9044 #ifdef POSIX_FADV_NORMAL
9045 if (ins(d, "POSIX_FADV_NORMAL", (long)POSIX_FADV_NORMAL)) return -1;
9046 #endif
9047 #ifdef POSIX_FADV_SEQUENTIAL
9048 if (ins(d, "POSIX_FADV_SEQUENTIAL", (long)POSIX_FADV_SEQUENTIAL)) return -1;
9049 #endif
9050 #ifdef POSIX_FADV_RANDOM
9051 if (ins(d, "POSIX_FADV_RANDOM", (long)POSIX_FADV_RANDOM)) return -1;
9052 #endif
9053 #ifdef POSIX_FADV_NOREUSE
9054 if (ins(d, "POSIX_FADV_NOREUSE", (long)POSIX_FADV_NOREUSE)) return -1;
9055 #endif
9056 #ifdef POSIX_FADV_WILLNEED
9057 if (ins(d, "POSIX_FADV_WILLNEED", (long)POSIX_FADV_WILLNEED)) return -1;
9058 #endif
9059 #ifdef POSIX_FADV_DONTNEED
9060 if (ins(d, "POSIX_FADV_DONTNEED", (long)POSIX_FADV_DONTNEED)) return -1;
9061 #endif
9062
9063 /* constants for waitid */
9064 #if defined(HAVE_SYS_WAIT_H) && defined(HAVE_WAITID)
9065 if (ins(d, "P_PID", (long)P_PID)) return -1;
9066 if (ins(d, "P_PGID", (long)P_PGID)) return -1;
9067 if (ins(d, "P_ALL", (long)P_ALL)) return -1;
9068 #endif
9069 #ifdef WEXITED
9070 if (ins(d, "WEXITED", (long)WEXITED)) return -1;
9071 #endif
9072 #ifdef WNOWAIT
9073 if (ins(d, "WNOWAIT", (long)WNOWAIT)) return -1;
9074 #endif
9075 #ifdef WSTOPPED
9076 if (ins(d, "WSTOPPED", (long)WSTOPPED)) return -1;
9077 #endif
9078 #ifdef CLD_EXITED
9079 if (ins(d, "CLD_EXITED", (long)CLD_EXITED)) return -1;
9080 #endif
9081 #ifdef CLD_DUMPED
9082 if (ins(d, "CLD_DUMPED", (long)CLD_DUMPED)) return -1;
9083 #endif
9084 #ifdef CLD_TRAPPED
9085 if (ins(d, "CLD_TRAPPED", (long)CLD_TRAPPED)) return -1;
9086 #endif
9087 #ifdef CLD_CONTINUED
9088 if (ins(d, "CLD_CONTINUED", (long)CLD_CONTINUED)) return -1;
9089 #endif
9090
9091 /* constants for lockf */
9092 #ifdef F_LOCK
9093 if (ins(d, "F_LOCK", (long)F_LOCK)) return -1;
9094 #endif
9095 #ifdef F_TLOCK
9096 if (ins(d, "F_TLOCK", (long)F_TLOCK)) return -1;
9097 #endif
9098 #ifdef F_ULOCK
9099 if (ins(d, "F_ULOCK", (long)F_ULOCK)) return -1;
9100 #endif
9101 #ifdef F_TEST
9102 if (ins(d, "F_TEST", (long)F_TEST)) return -1;
9103 #endif
9104
9105 /* constants for futimens */
9106 #ifdef UTIME_NOW
9107 if (ins(d, "UTIME_NOW", (long)UTIME_NOW)) return -1;
9108 #endif
9109 #ifdef UTIME_OMIT
9110 if (ins(d, "UTIME_OMIT", (long)UTIME_OMIT)) return -1;
9111 #endif
8361 9112
8362 #ifdef HAVE_SPAWNV 9113 #ifdef HAVE_SPAWNV
8363 #if defined(PYOS_OS2) && defined(PYCC_GCC) 9114 #if defined(PYOS_OS2) && defined(PYCC_GCC)
8364 if (ins(d, "P_WAIT", (long)P_WAIT)) return -1; 9115 if (ins(d, "P_WAIT", (long)P_WAIT)) return -1;
8365 if (ins(d, "P_NOWAIT", (long)P_NOWAIT)) return -1; 9116 if (ins(d, "P_NOWAIT", (long)P_NOWAIT)) return -1;
8366 if (ins(d, "P_OVERLAY", (long)P_OVERLAY)) return -1; 9117 if (ins(d, "P_OVERLAY", (long)P_OVERLAY)) return -1;
8367 if (ins(d, "P_DEBUG", (long)P_DEBUG)) return -1; 9118 if (ins(d, "P_DEBUG", (long)P_DEBUG)) return -1;
8368 if (ins(d, "P_SESSION", (long)P_SESSION)) return -1; 9119 if (ins(d, "P_SESSION", (long)P_SESSION)) return -1;
8369 if (ins(d, "P_DETACH", (long)P_DETACH)) return -1; 9120 if (ins(d, "P_DETACH", (long)P_DETACH)) return -1;
8370 if (ins(d, "P_PM", (long)P_PM)) return -1; 9121 if (ins(d, "P_PM", (long)P_PM)) return -1;
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
8451 9202
8452 Py_INCREF(PyExc_OSError); 9203 Py_INCREF(PyExc_OSError);
8453 PyModule_AddObject(m, "error", PyExc_OSError); 9204 PyModule_AddObject(m, "error", PyExc_OSError);
8454 9205
8455 #ifdef HAVE_PUTENV 9206 #ifdef HAVE_PUTENV
8456 if (posix_putenv_garbage == NULL) 9207 if (posix_putenv_garbage == NULL)
8457 posix_putenv_garbage = PyDict_New(); 9208 posix_putenv_garbage = PyDict_New();
8458 #endif 9209 #endif
8459 9210
8460 if (!initialized) { 9211 if (!initialized) {
9212 waitid_result_desc.name = MODNAME ".waitid_result";
9213 PyStructSequence_InitType(&WaitidResultType, &waitid_result_desc);
9214
8461 stat_result_desc.name = MODNAME ".stat_result"; 9215 stat_result_desc.name = MODNAME ".stat_result";
8462 stat_result_desc.fields[7].name = PyStructSequence_UnnamedField; 9216 stat_result_desc.fields[7].name = PyStructSequence_UnnamedField;
8463 stat_result_desc.fields[8].name = PyStructSequence_UnnamedField; 9217 stat_result_desc.fields[8].name = PyStructSequence_UnnamedField;
8464 stat_result_desc.fields[9].name = PyStructSequence_UnnamedField; 9218 stat_result_desc.fields[9].name = PyStructSequence_UnnamedField;
8465 PyStructSequence_InitType(&StatResultType, &stat_result_desc); 9219 PyStructSequence_InitType(&StatResultType, &stat_result_desc);
8466 structseq_new = StatResultType.tp_new; 9220 structseq_new = StatResultType.tp_new;
8467 StatResultType.tp_new = statresult_new; 9221 StatResultType.tp_new = statresult_new;
8468 9222
8469 statvfs_result_desc.name = MODNAME ".statvfs_result"; 9223 statvfs_result_desc.name = MODNAME ".statvfs_result";
8470 PyStructSequence_InitType(&StatVFSResultType, &statvfs_result_desc); 9224 PyStructSequence_InitType(&StatVFSResultType, &statvfs_result_desc);
8471 #ifdef NEED_TICKS_PER_SECOND 9225 #ifdef NEED_TICKS_PER_SECOND
8472 # if defined(HAVE_SYSCONF) && defined(_SC_CLK_TCK) 9226 # if defined(HAVE_SYSCONF) && defined(_SC_CLK_TCK)
8473 ticks_per_second = sysconf(_SC_CLK_TCK); 9227 ticks_per_second = sysconf(_SC_CLK_TCK);
8474 # elif defined(HZ) 9228 # elif defined(HZ)
8475 ticks_per_second = HZ; 9229 ticks_per_second = HZ;
8476 # else 9230 # else
8477 ticks_per_second = 60; /* magic fallback value; may be bogus */ 9231 ticks_per_second = 60; /* magic fallback value; may be bogus */
8478 # endif 9232 # endif
8479 #endif 9233 #endif
8480 } 9234 }
9235 Py_INCREF((PyObject*) &WaitidResultType);
9236 PyModule_AddObject(m, "waitid_result", (PyObject*) &WaitidResultType);
8481 Py_INCREF((PyObject*) &StatResultType); 9237 Py_INCREF((PyObject*) &StatResultType);
8482 PyModule_AddObject(m, "stat_result", (PyObject*) &StatResultType); 9238 PyModule_AddObject(m, "stat_result", (PyObject*) &StatResultType);
8483 Py_INCREF((PyObject*) &StatVFSResultType); 9239 Py_INCREF((PyObject*) &StatVFSResultType);
8484 PyModule_AddObject(m, "statvfs_result", 9240 PyModule_AddObject(m, "statvfs_result",
8485 (PyObject*) &StatVFSResultType); 9241 (PyObject*) &StatVFSResultType);
8486 initialized = 1; 9242 initialized = 1;
8487 9243
8488 #ifdef __APPLE__ 9244 #ifdef __APPLE__
8489 /* 9245 /*
8490 * Step 2 of weak-linking support on Mac OS X. 9246 * Step 2 of weak-linking support on Mac OS X.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
8522 9278
8523 9279
8524 #endif /* __APPLE__ */ 9280 #endif /* __APPLE__ */
8525 return m; 9281 return m;
8526 9282
8527 } 9283 }
8528 9284
8529 #ifdef __cplusplus 9285 #ifdef __cplusplus
8530 } 9286 }
8531 #endif 9287 #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