OLD | NEW |
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 475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
486 #else | 486 #else |
487 if (environ == NULL) | 487 if (environ == NULL) |
488 return d; | 488 return d; |
489 /* This part ignores errors */ | 489 /* This part ignores errors */ |
490 for (e = environ; *e != NULL; e++) { | 490 for (e = environ; *e != NULL; e++) { |
491 PyObject *k; | 491 PyObject *k; |
492 PyObject *v; | 492 PyObject *v; |
493 char *p = strchr(*e, '='); | 493 char *p = strchr(*e, '='); |
494 if (p == NULL) | 494 if (p == NULL) |
495 continue; | 495 continue; |
496 » » k = PyUnicode_FromStringAndSize(*e, (int)(p-*e)); | 496 » » k = PyUnicode_Decode(*e, (int)(p-*e), |
| 497 » » » » Py_FileSystemDefaultEncoding, "utf8b"); |
497 if (k == NULL) { | 498 if (k == NULL) { |
498 PyErr_Clear(); | 499 PyErr_Clear(); |
499 continue; | 500 continue; |
500 } | 501 } |
501 » » v = PyUnicode_FromString(p+1); | 502 » » v = PyUnicode_Decode(p+1, strlen(p+1), |
| 503 » » » » Py_FileSystemDefaultEncoding, "utf8b"); |
502 if (v == NULL) { | 504 if (v == NULL) { |
503 PyErr_Clear(); | 505 PyErr_Clear(); |
504 Py_DECREF(k); | 506 Py_DECREF(k); |
505 continue; | 507 continue; |
506 } | 508 } |
507 if (PyDict_GetItem(d, k) == NULL) { | 509 if (PyDict_GetItem(d, k) == NULL) { |
508 if (PyDict_SetItem(d, k, v) != 0) | 510 if (PyDict_SetItem(d, k, v) != 0) |
509 PyErr_Clear(); | 511 PyErr_Clear(); |
510 } | 512 } |
511 Py_DECREF(k); | 513 Py_DECREF(k); |
(...skipping 15 matching lines...) Expand all Loading... |
527 if (rc == NO_ERROR) { /* (not a typo, envname is NOT 'END_LIBPATH') */ | 529 if (rc == NO_ERROR) { /* (not a typo, envname is NOT 'END_LIBPATH') */ |
528 PyObject *v = PyBytes_FromString(buffer); | 530 PyObject *v = PyBytes_FromString(buffer); |
529 PyDict_SetItemString(d, "ENDLIBPATH", v); | 531 PyDict_SetItemString(d, "ENDLIBPATH", v); |
530 Py_DECREF(v); | 532 Py_DECREF(v); |
531 } | 533 } |
532 } | 534 } |
533 #endif | 535 #endif |
534 return d; | 536 return d; |
535 } | 537 } |
536 | 538 |
| 539 /* Convert a bytes object to a char*. Optionally lock the buffer if it is a |
| 540 bytes array. */ |
| 541 |
| 542 static char* |
| 543 bytes2str(PyObject* o, int lock) |
| 544 { |
| 545 if(PyBytes_Check(o)) |
| 546 return PyBytes_AsString(o); |
| 547 else if(PyByteArray_Check(o)) { |
| 548 if (lock && PyObject_GetBuffer(o, NULL, 0) < 0) |
| 549 /* On a bytearray, this should not fail. */ |
| 550 PyErr_BadInternalCall(); |
| 551 return PyByteArray_AsString(o); |
| 552 } else { |
| 553 /* The FS converter should have verified that this |
| 554 is either bytes or bytearray. */ |
| 555 Py_FatalError("bad object passed to bytes2str"); |
| 556 /* not reached. */ |
| 557 return ""; |
| 558 } |
| 559 } |
| 560 |
| 561 /* Release the lock, decref the object. */ |
| 562 static void |
| 563 release_bytes(PyObject* o) |
| 564 { |
| 565 if (PyByteArray_Check(o)) |
| 566 o->ob_type->tp_as_buffer->bf_releasebuffer(NULL, 0); |
| 567 Py_DECREF(o); |
| 568 } |
| 569 |
537 | 570 |
538 /* Set a POSIX-specific error from errno, and return NULL */ | 571 /* Set a POSIX-specific error from errno, and return NULL */ |
539 | 572 |
540 static PyObject * | 573 static PyObject * |
541 posix_error(void) | 574 posix_error(void) |
542 { | 575 { |
543 return PyErr_SetFromErrno(PyExc_OSError); | 576 return PyErr_SetFromErrno(PyExc_OSError); |
544 } | 577 } |
545 static PyObject * | 578 static PyObject * |
546 posix_error_with_filename(char* name) | 579 posix_error_with_filename(char* name) |
547 { | 580 { |
548 return PyErr_SetFromErrnoWithFilename(PyExc_OSError, name); | 581 return PyErr_SetFromErrnoWithFilename(PyExc_OSError, name); |
549 } | 582 } |
550 | 583 |
551 #ifdef Py_WIN_WIDE_FILENAMES | 584 #ifdef Py_WIN_WIDE_FILENAMES |
552 static PyObject * | 585 static PyObject * |
553 posix_error_with_unicode_filename(Py_UNICODE* name) | 586 posix_error_with_unicode_filename(Py_UNICODE* name) |
554 { | 587 { |
555 return PyErr_SetFromErrnoWithUnicodeFilename(PyExc_OSError, name); | 588 return PyErr_SetFromErrnoWithUnicodeFilename(PyExc_OSError, name); |
556 } | 589 } |
557 #endif /* Py_WIN_WIDE_FILENAMES */ | 590 #endif /* Py_WIN_WIDE_FILENAMES */ |
558 | 591 |
559 | 592 |
560 static PyObject * | 593 static PyObject * |
561 posix_error_with_allocated_filename(char* name) | 594 posix_error_with_allocated_filename(PyObject* name) |
562 { | 595 { |
563 » PyObject *rc = PyErr_SetFromErrnoWithFilename(PyExc_OSError, name); | 596 » PyObject *rc = PyErr_SetFromErrnoWithFilename(PyExc_OSError, |
564 » PyMem_Free(name); | 597 » » » » » » bytes2str(name, 0)); |
| 598 » release_bytes(name); |
565 return rc; | 599 return rc; |
566 } | 600 } |
567 | 601 |
568 #ifdef MS_WINDOWS | 602 #ifdef MS_WINDOWS |
569 static PyObject * | 603 static PyObject * |
570 win32_error(char* function, char* filename) | 604 win32_error(char* function, char* filename) |
571 { | 605 { |
572 /* XXX We should pass the function name along in the future. | 606 /* XXX We should pass the function name along in the future. |
573 (winreg.c also wants to pass the function name.) | 607 (winreg.c also wants to pass the function name.) |
574 This would however require an additional param to the | 608 This would however require an additional param to the |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
721 the Windows NT family. */ | 755 the Windows NT family. */ |
722 canusewide = (GetVersion() < 0x80000000) ? 1 : 0; | 756 canusewide = (GetVersion() < 0x80000000) ? 1 : 0; |
723 } | 757 } |
724 return canusewide; | 758 return canusewide; |
725 } | 759 } |
726 #endif | 760 #endif |
727 | 761 |
728 static PyObject * | 762 static PyObject * |
729 posix_1str(PyObject *args, char *format, int (*func)(const char*)) | 763 posix_1str(PyObject *args, char *format, int (*func)(const char*)) |
730 { | 764 { |
731 » char *path1 = NULL; | 765 » PyObject *opath1 = NULL; |
| 766 » char *path1; |
732 int res; | 767 int res; |
733 if (!PyArg_ParseTuple(args, format, | 768 if (!PyArg_ParseTuple(args, format, |
734 » Py_FileSystemDefaultEncoding, &path1)) | 769 » PyUnicode_FSConverter, &opath1)) |
735 return NULL; | 770 return NULL; |
| 771 path1 = bytes2str(opath1, 1); |
736 Py_BEGIN_ALLOW_THREADS | 772 Py_BEGIN_ALLOW_THREADS |
737 res = (*func)(path1); | 773 res = (*func)(path1); |
738 Py_END_ALLOW_THREADS | 774 Py_END_ALLOW_THREADS |
739 if (res < 0) | 775 if (res < 0) |
740 » » return posix_error_with_allocated_filename(path1); | 776 » » return posix_error_with_allocated_filename(opath1); |
741 » PyMem_Free(path1); | 777 » release_bytes(opath1); |
742 Py_INCREF(Py_None); | 778 Py_INCREF(Py_None); |
743 return Py_None; | 779 return Py_None; |
744 } | 780 } |
745 | 781 |
746 static PyObject * | 782 static PyObject * |
747 posix_2str(PyObject *args, | 783 posix_2str(PyObject *args, |
748 char *format, | 784 char *format, |
749 int (*func)(const char *, const char *)) | 785 int (*func)(const char *, const char *)) |
750 { | 786 { |
751 » char *path1 = NULL, *path2 = NULL; | 787 » PyObject *opath1, *opath2; |
| 788 » char *path1, *path2; |
752 int res; | 789 int res; |
753 if (!PyArg_ParseTuple(args, format, | 790 if (!PyArg_ParseTuple(args, format, |
754 » Py_FileSystemDefaultEncoding, &path1, | 791 » PyUnicode_FSConverter, &opath1, |
755 » Py_FileSystemDefaultEncoding, &path2)) | 792 » PyUnicode_FSConverter, &opath2)) |
756 return NULL; | 793 return NULL; |
| 794 path1 = bytes2str(opath1, 1); |
| 795 path2 = bytes2str(opath2, 1); |
757 Py_BEGIN_ALLOW_THREADS | 796 Py_BEGIN_ALLOW_THREADS |
758 res = (*func)(path1, path2); | 797 res = (*func)(path1, path2); |
759 Py_END_ALLOW_THREADS | 798 Py_END_ALLOW_THREADS |
760 » PyMem_Free(path1); | 799 » release_bytes(opath1); |
761 » PyMem_Free(path2); | 800 » release_bytes(opath2); |
762 if (res != 0) | 801 if (res != 0) |
763 /* XXX how to report both path1 and path2??? */ | 802 /* XXX how to report both path1 and path2??? */ |
764 return posix_error(); | 803 return posix_error(); |
765 Py_INCREF(Py_None); | 804 Py_INCREF(Py_None); |
766 return Py_None; | 805 return Py_None; |
767 } | 806 } |
768 | 807 |
769 #ifdef Py_WIN_WIDE_FILENAMES | 808 #ifdef Py_WIN_WIDE_FILENAMES |
770 static PyObject* | 809 static PyObject* |
771 win32_1str(PyObject* args, char* func,· | 810 win32_1str(PyObject* args, char* func,· |
(...skipping 781 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1553 char *format, | 1592 char *format, |
1554 #ifdef __VMS | 1593 #ifdef __VMS |
1555 int (*statfunc)(const char *, STRUCT_STAT *, ...), | 1594 int (*statfunc)(const char *, STRUCT_STAT *, ...), |
1556 #else | 1595 #else |
1557 int (*statfunc)(const char *, STRUCT_STAT *), | 1596 int (*statfunc)(const char *, STRUCT_STAT *), |
1558 #endif | 1597 #endif |
1559 char *wformat, | 1598 char *wformat, |
1560 int (*wstatfunc)(const Py_UNICODE *, STRUCT_STAT *)) | 1599 int (*wstatfunc)(const Py_UNICODE *, STRUCT_STAT *)) |
1561 { | 1600 { |
1562 STRUCT_STAT st; | 1601 STRUCT_STAT st; |
1563 » char *path = NULL;» /* pass this to stat; do not free() it */ | 1602 » PyObject *opath; |
1564 » char *pathfree = NULL; /* this memory must be free'd */ | 1603 » char *path; |
1565 int res; | 1604 int res; |
1566 PyObject *result; | 1605 PyObject *result; |
1567 | 1606 |
1568 #ifdef Py_WIN_WIDE_FILENAMES | 1607 #ifdef Py_WIN_WIDE_FILENAMES |
1569 /* If on wide-character-capable OS see if argument | 1608 /* If on wide-character-capable OS see if argument |
1570 is Unicode and if so use wide API. */ | 1609 is Unicode and if so use wide API. */ |
1571 if (unicode_file_names()) { | 1610 if (unicode_file_names()) { |
1572 PyUnicodeObject *po; | 1611 PyUnicodeObject *po; |
1573 if (PyArg_ParseTuple(args, wformat, &po)) { | 1612 if (PyArg_ParseTuple(args, wformat, &po)) { |
1574 Py_UNICODE *wpath = PyUnicode_AS_UNICODE(po); | 1613 Py_UNICODE *wpath = PyUnicode_AS_UNICODE(po); |
1575 | 1614 |
1576 Py_BEGIN_ALLOW_THREADS | 1615 Py_BEGIN_ALLOW_THREADS |
1577 /* PyUnicode_AS_UNICODE result OK without | 1616 /* PyUnicode_AS_UNICODE result OK without |
1578 thread lock as it is a simple dereference. */ | 1617 thread lock as it is a simple dereference. */ |
1579 res = wstatfunc(wpath, &st); | 1618 res = wstatfunc(wpath, &st); |
1580 Py_END_ALLOW_THREADS | 1619 Py_END_ALLOW_THREADS |
1581 | 1620 |
1582 if (res != 0) | 1621 if (res != 0) |
1583 return win32_error_unicode("stat", wpath); | 1622 return win32_error_unicode("stat", wpath); |
1584 return _pystat_fromstructstat(&st); | 1623 return _pystat_fromstructstat(&st); |
1585 } | 1624 } |
1586 /* Drop the argument parsing error as narrow strings | 1625 /* Drop the argument parsing error as narrow strings |
1587 are also valid. */ | 1626 are also valid. */ |
1588 PyErr_Clear(); | 1627 PyErr_Clear(); |
1589 } | 1628 } |
1590 #endif | 1629 #endif |
1591 | 1630 |
1592 if (!PyArg_ParseTuple(args, format, | 1631 if (!PyArg_ParseTuple(args, format, |
1593 » Py_FileSystemDefaultEncoding, &path)) | 1632 » PyUnicode_FSConverter, &opath)) |
1594 return NULL; | 1633 return NULL; |
1595 » pathfree = path; | 1634 » path = bytes2str(opath, 1); |
1596 | |
1597 Py_BEGIN_ALLOW_THREADS | 1635 Py_BEGIN_ALLOW_THREADS |
1598 res = (*statfunc)(path, &st); | 1636 res = (*statfunc)(path, &st); |
1599 Py_END_ALLOW_THREADS | 1637 Py_END_ALLOW_THREADS |
1600 | 1638 |
1601 if (res != 0) { | 1639 if (res != 0) { |
1602 #ifdef MS_WINDOWS | 1640 #ifdef MS_WINDOWS |
1603 » » result = win32_error("stat", pathfree); | 1641 » » result = win32_error("stat", path); |
1604 #else | 1642 #else |
1605 » » result = posix_error_with_filename(pathfree); | 1643 » » result = posix_error_with_filename(path); |
1606 #endif | 1644 #endif |
1607 }· | 1645 }· |
1608 else | 1646 else |
1609 result = _pystat_fromstructstat(&st); | 1647 result = _pystat_fromstructstat(&st); |
1610 | 1648 |
1611 » PyMem_Free(pathfree); | 1649 » release_bytes(opath); |
1612 return result; | 1650 return result; |
1613 } | 1651 } |
1614 | 1652 |
1615 /* POSIX methods */ | 1653 /* POSIX methods */ |
1616 | 1654 |
1617 PyDoc_STRVAR(posix_access__doc__, | 1655 PyDoc_STRVAR(posix_access__doc__, |
1618 "access(path, mode) -> True if granted, False otherwise\n\n\ | 1656 "access(path, mode) -> True if granted, False otherwise\n\n\ |
1619 Use the real uid/gid to test for access to a path. Note that most\n\ | 1657 Use the real uid/gid to test for access to a path. Note that most\n\ |
1620 operations will use the effective uid/gid, therefore this routine can\n\ | 1658 operations will use the effective uid/gid, therefore this routine can\n\ |
1621 be used in a suid/sgid environment to test if the invoking user has the\n\ | 1659 be used in a suid/sgid environment to test if the invoking user has the\n\ |
1622 specified access to the path. The mode argument can be F_OK to test\n\ | 1660 specified access to the path. The mode argument can be F_OK to test\n\ |
1623 existence, or the inclusive-OR of R_OK, W_OK, and X_OK."); | 1661 existence, or the inclusive-OR of R_OK, W_OK, and X_OK."); |
1624 | 1662 |
1625 static PyObject * | 1663 static PyObject * |
1626 posix_access(PyObject *self, PyObject *args) | 1664 posix_access(PyObject *self, PyObject *args) |
1627 { | 1665 { |
| 1666 PyObject *opath; |
1628 char *path; | 1667 char *path; |
1629 int mode; | 1668 int mode; |
1630 ········ | 1669 ········ |
1631 #ifdef Py_WIN_WIDE_FILENAMES | 1670 #ifdef Py_WIN_WIDE_FILENAMES |
1632 DWORD attr; | 1671 DWORD attr; |
1633 if (unicode_file_names()) { | 1672 if (unicode_file_names()) { |
1634 PyUnicodeObject *po; | 1673 PyUnicodeObject *po; |
1635 if (PyArg_ParseTuple(args, "Ui:access", &po, &mode)) { | 1674 if (PyArg_ParseTuple(args, "Ui:access", &po, &mode)) { |
1636 Py_BEGIN_ALLOW_THREADS | 1675 Py_BEGIN_ALLOW_THREADS |
1637 /* PyUnicode_AS_UNICODE OK without thread lock as | 1676 /* PyUnicode_AS_UNICODE OK without thread lock as |
1638 it is a simple dereference. */ | 1677 it is a simple dereference. */ |
1639 attr = GetFileAttributesW(PyUnicode_AS_UNICODE(po)); | 1678 attr = GetFileAttributesW(PyUnicode_AS_UNICODE(po)); |
1640 Py_END_ALLOW_THREADS | 1679 Py_END_ALLOW_THREADS |
1641 goto finish; | 1680 goto finish; |
1642 } | 1681 } |
1643 /* Drop the argument parsing error as narrow strings | 1682 /* Drop the argument parsing error as narrow strings |
1644 are also valid. */ | 1683 are also valid. */ |
1645 PyErr_Clear(); | 1684 PyErr_Clear(); |
1646 } | 1685 } |
1647 » if (!PyArg_ParseTuple(args, "eti:access", | 1686 » if (!PyArg_ParseTuple(args, "O&i:access", |
1648 » » » Py_FileSystemDefaultEncoding, &path, &mode)) | 1687 » » » PyUnicode_FSConverter, &opath, &mode)) |
1649 return 0; | 1688 return 0; |
| 1689 path = bytes2str(opath); |
1650 Py_BEGIN_ALLOW_THREADS | 1690 Py_BEGIN_ALLOW_THREADS |
1651 attr = GetFileAttributesA(path); | 1691 attr = GetFileAttributesA(path); |
1652 Py_END_ALLOW_THREADS | 1692 Py_END_ALLOW_THREADS |
1653 » PyMem_Free(path); | 1693 » release_bytes(opath); |
1654 finish: | 1694 finish: |
1655 if (attr == 0xFFFFFFFF) | 1695 if (attr == 0xFFFFFFFF) |
1656 /* File does not exist, or cannot read attributes */ | 1696 /* File does not exist, or cannot read attributes */ |
1657 return PyBool_FromLong(0); | 1697 return PyBool_FromLong(0); |
1658 /* Access is possible if either write access wasn't requested, or | 1698 /* Access is possible if either write access wasn't requested, or |
1659 the file isn't read-only, or if it's a directory, as there are | 1699 the file isn't read-only, or if it's a directory, as there are |
1660 no read-only directories on Windows. */ | 1700 no read-only directories on Windows. */ |
1661 return PyBool_FromLong(!(mode & 2)· | 1701 return PyBool_FromLong(!(mode & 2)· |
1662 || !(attr & FILE_ATTRIBUTE_READONLY) | 1702 || !(attr & FILE_ATTRIBUTE_READONLY) |
1663 || (attr & FILE_ATTRIBUTE_DIRECTORY)); | 1703 || (attr & FILE_ATTRIBUTE_DIRECTORY)); |
1664 #else | 1704 #else |
1665 int res; | 1705 int res; |
1666 » if (!PyArg_ParseTuple(args, "eti:access",· | 1706 » if (!PyArg_ParseTuple(args, "O&i:access",· |
1667 » » » Py_FileSystemDefaultEncoding, &path, &mode)) | 1707 » » » PyUnicode_FSConverter, &opath, &mode)) |
1668 return NULL; | 1708 return NULL; |
| 1709 path = bytes2str(opath, 1); |
1669 Py_BEGIN_ALLOW_THREADS | 1710 Py_BEGIN_ALLOW_THREADS |
1670 res = access(path, mode); | 1711 res = access(path, mode); |
1671 Py_END_ALLOW_THREADS | 1712 Py_END_ALLOW_THREADS |
1672 » PyMem_Free(path); | 1713 » release_bytes(opath); |
1673 return PyBool_FromLong(res == 0); | 1714 return PyBool_FromLong(res == 0); |
1674 #endif | 1715 #endif |
1675 } | 1716 } |
1676 | 1717 |
1677 #ifndef F_OK | 1718 #ifndef F_OK |
1678 #define F_OK 0 | 1719 #define F_OK 0 |
1679 #endif | 1720 #endif |
1680 #ifndef R_OK | 1721 #ifndef R_OK |
1681 #define R_OK 4 | 1722 #define R_OK 4 |
1682 #endif | 1723 #endif |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1743 PyDoc_STRVAR(posix_chdir__doc__, | 1784 PyDoc_STRVAR(posix_chdir__doc__, |
1744 "chdir(path)\n\n\ | 1785 "chdir(path)\n\n\ |
1745 Change the current working directory to the specified path."); | 1786 Change the current working directory to the specified path."); |
1746 | 1787 |
1747 static PyObject * | 1788 static PyObject * |
1748 posix_chdir(PyObject *self, PyObject *args) | 1789 posix_chdir(PyObject *self, PyObject *args) |
1749 { | 1790 { |
1750 #ifdef MS_WINDOWS | 1791 #ifdef MS_WINDOWS |
1751 return win32_1str(args, "chdir", "y:chdir", win32_chdir, "U:chdir", win3
2_wchdir); | 1792 return win32_1str(args, "chdir", "y:chdir", win32_chdir, "U:chdir", win3
2_wchdir); |
1752 #elif defined(PYOS_OS2) && defined(PYCC_GCC) | 1793 #elif defined(PYOS_OS2) && defined(PYCC_GCC) |
1753 » return posix_1str(args, "et:chdir", _chdir2); | 1794 » return posix_1str(args, "O&:chdir", _chdir2); |
1754 #elif defined(__VMS) | 1795 #elif defined(__VMS) |
1755 » return posix_1str(args, "et:chdir", (int (*)(const char *))chdir); | 1796 » return posix_1str(args, "O&:chdir", (int (*)(const char *))chdir); |
1756 #else | 1797 #else |
1757 » return posix_1str(args, "et:chdir", chdir); | 1798 » return posix_1str(args, "O&:chdir", chdir); |
1758 #endif | 1799 #endif |
1759 } | 1800 } |
1760 | 1801 |
1761 #ifdef HAVE_FCHDIR | 1802 #ifdef HAVE_FCHDIR |
1762 PyDoc_STRVAR(posix_fchdir__doc__, | 1803 PyDoc_STRVAR(posix_fchdir__doc__, |
1763 "fchdir(fildes)\n\n\ | 1804 "fchdir(fildes)\n\n\ |
1764 Change to the directory of the given file descriptor. fildes must be\n\ | 1805 Change to the directory of the given file descriptor. fildes must be\n\ |
1765 opened on a directory, not a file."); | 1806 opened on a directory, not a file."); |
1766 | 1807 |
1767 static PyObject * | 1808 static PyObject * |
1768 posix_fchdir(PyObject *self, PyObject *fdobj) | 1809 posix_fchdir(PyObject *self, PyObject *fdobj) |
1769 { | 1810 { |
1770 return posix_fildes(fdobj, fchdir); | 1811 return posix_fildes(fdobj, fchdir); |
1771 } | 1812 } |
1772 #endif /* HAVE_FCHDIR */ | 1813 #endif /* HAVE_FCHDIR */ |
1773 | 1814 |
1774 | 1815 |
1775 PyDoc_STRVAR(posix_chmod__doc__, | 1816 PyDoc_STRVAR(posix_chmod__doc__, |
1776 "chmod(path, mode)\n\n\ | 1817 "chmod(path, mode)\n\n\ |
1777 Change the access permissions of a file."); | 1818 Change the access permissions of a file."); |
1778 | 1819 |
1779 static PyObject * | 1820 static PyObject * |
1780 posix_chmod(PyObject *self, PyObject *args) | 1821 posix_chmod(PyObject *self, PyObject *args) |
1781 { | 1822 { |
| 1823 PyObject *opath = NULL; |
1782 char *path = NULL; | 1824 char *path = NULL; |
1783 int i; | 1825 int i; |
1784 int res; | 1826 int res; |
1785 #ifdef Py_WIN_WIDE_FILENAMES | 1827 #ifdef Py_WIN_WIDE_FILENAMES |
1786 DWORD attr; | 1828 DWORD attr; |
1787 if (unicode_file_names()) { | 1829 if (unicode_file_names()) { |
1788 PyUnicodeObject *po; | 1830 PyUnicodeObject *po; |
1789 if (PyArg_ParseTuple(args, "Ui|:chmod", &po, &i)) { | 1831 if (PyArg_ParseTuple(args, "Ui|:chmod", &po, &i)) { |
1790 Py_BEGIN_ALLOW_THREADS | 1832 Py_BEGIN_ALLOW_THREADS |
1791 attr = GetFileAttributesW(PyUnicode_AS_UNICODE(po)); | 1833 attr = GetFileAttributesW(PyUnicode_AS_UNICODE(po)); |
(...skipping 10 matching lines...) Expand all Loading... |
1802 if (!res) | 1844 if (!res) |
1803 return win32_error_unicode("chmod", | 1845 return win32_error_unicode("chmod", |
1804 PyUnicode_AS_UNICODE(po)); | 1846 PyUnicode_AS_UNICODE(po)); |
1805 Py_INCREF(Py_None); | 1847 Py_INCREF(Py_None); |
1806 return Py_None; | 1848 return Py_None; |
1807 } | 1849 } |
1808 /* Drop the argument parsing error as narrow strings | 1850 /* Drop the argument parsing error as narrow strings |
1809 are also valid. */ | 1851 are also valid. */ |
1810 PyErr_Clear(); | 1852 PyErr_Clear(); |
1811 } | 1853 } |
1812 » if (!PyArg_ParseTuple(args, "eti:chmod", Py_FileSystemDefaultEncoding, | 1854 » if (!PyArg_ParseTuple(args, "O&i:chmod", PyUnicode_FSConverter, |
1813 » &path, &i)) | 1855 » &opath, &i)) |
1814 return NULL; | 1856 return NULL; |
| 1857 path = bytes2str(opath, 1); |
1815 Py_BEGIN_ALLOW_THREADS | 1858 Py_BEGIN_ALLOW_THREADS |
1816 attr = GetFileAttributesA(path); | 1859 attr = GetFileAttributesA(path); |
1817 if (attr != 0xFFFFFFFF) { | 1860 if (attr != 0xFFFFFFFF) { |
1818 if (i & _S_IWRITE) | 1861 if (i & _S_IWRITE) |
1819 attr &= ~FILE_ATTRIBUTE_READONLY; | 1862 attr &= ~FILE_ATTRIBUTE_READONLY; |
1820 else | 1863 else |
1821 attr |= FILE_ATTRIBUTE_READONLY; | 1864 attr |= FILE_ATTRIBUTE_READONLY; |
1822 res = SetFileAttributesA(path, attr); | 1865 res = SetFileAttributesA(path, attr); |
1823 } | 1866 } |
1824 else | 1867 else |
1825 res = 0; | 1868 res = 0; |
1826 Py_END_ALLOW_THREADS | 1869 Py_END_ALLOW_THREADS |
1827 if (!res) { | 1870 if (!res) { |
1828 win32_error("chmod", path); | 1871 win32_error("chmod", path); |
1829 » » PyMem_Free(path); | 1872 » » release_bytes(opath); |
1830 return NULL; | 1873 return NULL; |
1831 } | 1874 } |
1832 » PyMem_Free(path); | 1875 » release_bytes(opath); |
1833 Py_INCREF(Py_None); | 1876 Py_INCREF(Py_None); |
1834 return Py_None; | 1877 return Py_None; |
1835 #else /* Py_WIN_WIDE_FILENAMES */ | 1878 #else /* Py_WIN_WIDE_FILENAMES */ |
1836 » if (!PyArg_ParseTuple(args, "eti:chmod", Py_FileSystemDefaultEncoding, | 1879 » if (!PyArg_ParseTuple(args, "O&i:chmod", PyUnicode_FSConverter, |
1837 » &path, &i)) | 1880 » &opath, &i)) |
1838 return NULL; | 1881 return NULL; |
| 1882 path = bytes2str(opath, 1); |
1839 Py_BEGIN_ALLOW_THREADS | 1883 Py_BEGIN_ALLOW_THREADS |
1840 res = chmod(path, i); | 1884 res = chmod(path, i); |
1841 Py_END_ALLOW_THREADS | 1885 Py_END_ALLOW_THREADS |
1842 if (res < 0) | 1886 if (res < 0) |
1843 » » return posix_error_with_allocated_filename(path); | 1887 » » return posix_error_with_allocated_filename(opath); |
1844 » PyMem_Free(path); | 1888 » release_bytes(opath); |
1845 Py_INCREF(Py_None); | 1889 Py_INCREF(Py_None); |
1846 return Py_None; | 1890 return Py_None; |
1847 #endif | 1891 #endif |
1848 } | 1892 } |
1849 | 1893 |
1850 #ifdef HAVE_FCHMOD | 1894 #ifdef HAVE_FCHMOD |
1851 PyDoc_STRVAR(posix_fchmod__doc__, | 1895 PyDoc_STRVAR(posix_fchmod__doc__, |
1852 "fchmod(fd, mode)\n\n\ | 1896 "fchmod(fd, mode)\n\n\ |
1853 Change the access permissions of the file given by file\n\ | 1897 Change the access permissions of the file given by file\n\ |
1854 descriptor fd."); | 1898 descriptor fd."); |
(...skipping 15 matching lines...) Expand all Loading... |
1870 | 1914 |
1871 #ifdef HAVE_LCHMOD | 1915 #ifdef HAVE_LCHMOD |
1872 PyDoc_STRVAR(posix_lchmod__doc__, | 1916 PyDoc_STRVAR(posix_lchmod__doc__, |
1873 "lchmod(path, mode)\n\n\ | 1917 "lchmod(path, mode)\n\n\ |
1874 Change the access permissions of a file. If path is a symlink, this\n\ | 1918 Change the access permissions of a file. If path is a symlink, this\n\ |
1875 affects the link itself rather than the target."); | 1919 affects the link itself rather than the target."); |
1876 | 1920 |
1877 static PyObject * | 1921 static PyObject * |
1878 posix_lchmod(PyObject *self, PyObject *args) | 1922 posix_lchmod(PyObject *self, PyObject *args) |
1879 { | 1923 { |
1880 » char *path = NULL; | 1924 » PyObject *opath; |
| 1925 » char *path; |
1881 int i; | 1926 int i; |
1882 int res; | 1927 int res; |
1883 » if (!PyArg_ParseTuple(args, "eti:lchmod", Py_FileSystemDefaultEncoding, | 1928 » if (!PyArg_ParseTuple(args, "O&i:lchmod", PyUnicode_FSConverter, |
1884 » &path, &i)) | 1929 » &opath, &i)) |
1885 return NULL; | 1930 return NULL; |
| 1931 path = bytes2str(opath, 1) |
1886 Py_BEGIN_ALLOW_THREADS | 1932 Py_BEGIN_ALLOW_THREADS |
1887 res = lchmod(path, i); | 1933 res = lchmod(path, i); |
1888 Py_END_ALLOW_THREADS | 1934 Py_END_ALLOW_THREADS |
1889 if (res < 0) | 1935 if (res < 0) |
1890 » » return posix_error_with_allocated_filename(path); | 1936 » » return posix_error_with_allocated_filename(opath); |
1891 » PyMem_Free(path); | 1937 » release_bytes(opath); |
1892 Py_RETURN_NONE; | 1938 Py_RETURN_NONE; |
1893 } | 1939 } |
1894 #endif /* HAVE_LCHMOD */ | 1940 #endif /* HAVE_LCHMOD */ |
1895 | 1941 |
1896 | 1942 |
1897 #ifdef HAVE_CHFLAGS | 1943 #ifdef HAVE_CHFLAGS |
1898 PyDoc_STRVAR(posix_chflags__doc__, | 1944 PyDoc_STRVAR(posix_chflags__doc__, |
1899 "chflags(path, flags)\n\n\ | 1945 "chflags(path, flags)\n\n\ |
1900 Set file flags."); | 1946 Set file flags."); |
1901 | 1947 |
1902 static PyObject * | 1948 static PyObject * |
1903 posix_chflags(PyObject *self, PyObject *args) | 1949 posix_chflags(PyObject *self, PyObject *args) |
1904 { | 1950 { |
| 1951 PyObject *opath; |
1905 char *path; | 1952 char *path; |
1906 unsigned long flags; | 1953 unsigned long flags; |
1907 int res; | 1954 int res; |
1908 » if (!PyArg_ParseTuple(args, "etk:chflags", | 1955 » if (!PyArg_ParseTuple(args, "O&k:chflags", |
1909 » » » Py_FileSystemDefaultEncoding, &path, &flags)) | 1956 » » » PyUnicode_FSConverter, &opath, &flags)) |
1910 return NULL; | 1957 return NULL; |
| 1958 path = bytes2str(opath, 1); |
1911 Py_BEGIN_ALLOW_THREADS | 1959 Py_BEGIN_ALLOW_THREADS |
1912 res = chflags(path, flags); | 1960 res = chflags(path, flags); |
1913 Py_END_ALLOW_THREADS | 1961 Py_END_ALLOW_THREADS |
1914 if (res < 0) | 1962 if (res < 0) |
1915 » » return posix_error_with_allocated_filename(path); | 1963 » » return posix_error_with_allocated_filename(opath); |
1916 » PyMem_Free(path); | 1964 » release_bytes(opath); |
1917 Py_INCREF(Py_None); | 1965 Py_INCREF(Py_None); |
1918 return Py_None; | 1966 return Py_None; |
1919 } | 1967 } |
1920 #endif /* HAVE_CHFLAGS */ | 1968 #endif /* HAVE_CHFLAGS */ |
1921 | 1969 |
1922 #ifdef HAVE_LCHFLAGS | 1970 #ifdef HAVE_LCHFLAGS |
1923 PyDoc_STRVAR(posix_lchflags__doc__, | 1971 PyDoc_STRVAR(posix_lchflags__doc__, |
1924 "lchflags(path, flags)\n\n\ | 1972 "lchflags(path, flags)\n\n\ |
1925 Set file flags.\n\ | 1973 Set file flags.\n\ |
1926 This function will not follow symbolic links."); | 1974 This function will not follow symbolic links."); |
1927 | 1975 |
1928 static PyObject * | 1976 static PyObject * |
1929 posix_lchflags(PyObject *self, PyObject *args) | 1977 posix_lchflags(PyObject *self, PyObject *args) |
1930 { | 1978 { |
| 1979 PyObject *opath; |
1931 char *path; | 1980 char *path; |
1932 unsigned long flags; | 1981 unsigned long flags; |
1933 int res; | 1982 int res; |
1934 » if (!PyArg_ParseTuple(args, "etk:lchflags", | 1983 » if (!PyArg_ParseTuple(args, "O&k:lchflags", |
1935 » » » Py_FileSystemDefaultEncoding, &path, &flags)) | 1984 » » » PyUnicode_FSConverter, &path, &flags)) |
1936 return NULL; | 1985 return NULL; |
| 1986 path = bytes2str(opath, 1); |
1937 Py_BEGIN_ALLOW_THREADS | 1987 Py_BEGIN_ALLOW_THREADS |
1938 res = lchflags(path, flags); | 1988 res = lchflags(path, flags); |
1939 Py_END_ALLOW_THREADS | 1989 Py_END_ALLOW_THREADS |
1940 if (res < 0) | 1990 if (res < 0) |
1941 » » return posix_error_with_allocated_filename(path); | 1991 » » return posix_error_with_allocated_filename(opath); |
1942 » PyMem_Free(path); | 1992 » release_bytes(opath); |
1943 Py_INCREF(Py_None); | 1993 Py_INCREF(Py_None); |
1944 return Py_None; | 1994 return Py_None; |
1945 } | 1995 } |
1946 #endif /* HAVE_LCHFLAGS */ | 1996 #endif /* HAVE_LCHFLAGS */ |
1947 | 1997 |
1948 #ifdef HAVE_CHROOT | 1998 #ifdef HAVE_CHROOT |
1949 PyDoc_STRVAR(posix_chroot__doc__, | 1999 PyDoc_STRVAR(posix_chroot__doc__, |
1950 "chroot(path)\n\n\ | 2000 "chroot(path)\n\n\ |
1951 Change root directory to path."); | 2001 Change root directory to path."); |
1952 | 2002 |
1953 static PyObject * | 2003 static PyObject * |
1954 posix_chroot(PyObject *self, PyObject *args) | 2004 posix_chroot(PyObject *self, PyObject *args) |
1955 { | 2005 { |
1956 » return posix_1str(args, "et:chroot", chroot); | 2006 » return posix_1str(args, "O&:chroot", chroot); |
1957 } | 2007 } |
1958 #endif | 2008 #endif |
1959 | 2009 |
1960 #ifdef HAVE_FSYNC | 2010 #ifdef HAVE_FSYNC |
1961 PyDoc_STRVAR(posix_fsync__doc__, | 2011 PyDoc_STRVAR(posix_fsync__doc__, |
1962 "fsync(fildes)\n\n\ | 2012 "fsync(fildes)\n\n\ |
1963 force write of file with filedescriptor to disk."); | 2013 force write of file with filedescriptor to disk."); |
1964 | 2014 |
1965 static PyObject * | 2015 static PyObject * |
1966 posix_fsync(PyObject *self, PyObject *fdobj) | 2016 posix_fsync(PyObject *self, PyObject *fdobj) |
(...skipping 22 matching lines...) Expand all Loading... |
1989 | 2039 |
1990 | 2040 |
1991 #ifdef HAVE_CHOWN | 2041 #ifdef HAVE_CHOWN |
1992 PyDoc_STRVAR(posix_chown__doc__, | 2042 PyDoc_STRVAR(posix_chown__doc__, |
1993 "chown(path, uid, gid)\n\n\ | 2043 "chown(path, uid, gid)\n\n\ |
1994 Change the owner and group id of path to the numeric uid and gid."); | 2044 Change the owner and group id of path to the numeric uid and gid."); |
1995 | 2045 |
1996 static PyObject * | 2046 static PyObject * |
1997 posix_chown(PyObject *self, PyObject *args) | 2047 posix_chown(PyObject *self, PyObject *args) |
1998 { | 2048 { |
1999 » char *path = NULL; | 2049 » PyObject *opath; |
| 2050 » char *path; |
2000 long uid, gid; | 2051 long uid, gid; |
2001 int res; | 2052 int res; |
2002 » if (!PyArg_ParseTuple(args, "etll:chown", | 2053 » if (!PyArg_ParseTuple(args, "O&ll:chown", |
2003 » Py_FileSystemDefaultEncoding, &path, | 2054 » PyUnicode_FSConverter, &opath, |
2004 &uid, &gid)) | 2055 &uid, &gid)) |
2005 return NULL; | 2056 return NULL; |
| 2057 path = bytes2str(opath, 1); |
2006 Py_BEGIN_ALLOW_THREADS | 2058 Py_BEGIN_ALLOW_THREADS |
2007 res = chown(path, (uid_t) uid, (gid_t) gid); | 2059 res = chown(path, (uid_t) uid, (gid_t) gid); |
2008 Py_END_ALLOW_THREADS | 2060 Py_END_ALLOW_THREADS |
2009 if (res < 0) | 2061 if (res < 0) |
2010 » » return posix_error_with_allocated_filename(path); | 2062 » » return posix_error_with_allocated_filename(opath); |
2011 » PyMem_Free(path); | 2063 » release_bytes(opath); |
2012 Py_INCREF(Py_None); | 2064 Py_INCREF(Py_None); |
2013 return Py_None; | 2065 return Py_None; |
2014 } | 2066 } |
2015 #endif /* HAVE_CHOWN */ | 2067 #endif /* HAVE_CHOWN */ |
2016 | 2068 |
2017 #ifdef HAVE_FCHOWN | 2069 #ifdef HAVE_FCHOWN |
2018 PyDoc_STRVAR(posix_fchown__doc__, | 2070 PyDoc_STRVAR(posix_fchown__doc__, |
2019 "fchown(fd, uid, gid)\n\n\ | 2071 "fchown(fd, uid, gid)\n\n\ |
2020 Change the owner and group id of the file given by file descriptor\n\ | 2072 Change the owner and group id of the file given by file descriptor\n\ |
2021 fd to the numeric uid and gid."); | 2073 fd to the numeric uid and gid."); |
(...skipping 16 matching lines...) Expand all Loading... |
2038 | 2090 |
2039 #ifdef HAVE_LCHOWN | 2091 #ifdef HAVE_LCHOWN |
2040 PyDoc_STRVAR(posix_lchown__doc__, | 2092 PyDoc_STRVAR(posix_lchown__doc__, |
2041 "lchown(path, uid, gid)\n\n\ | 2093 "lchown(path, uid, gid)\n\n\ |
2042 Change the owner and group id of path to the numeric uid and gid.\n\ | 2094 Change the owner and group id of path to the numeric uid and gid.\n\ |
2043 This function will not follow symbolic links."); | 2095 This function will not follow symbolic links."); |
2044 | 2096 |
2045 static PyObject * | 2097 static PyObject * |
2046 posix_lchown(PyObject *self, PyObject *args) | 2098 posix_lchown(PyObject *self, PyObject *args) |
2047 { | 2099 { |
2048 » char *path = NULL; | 2100 » PyObject *opath; |
| 2101 » char *path; |
2049 int uid, gid; | 2102 int uid, gid; |
2050 int res; | 2103 int res; |
2051 » if (!PyArg_ParseTuple(args, "etii:lchown", | 2104 » if (!PyArg_ParseTuple(args, "O&ii:lchown", |
2052 » Py_FileSystemDefaultEncoding, &path, | 2105 » PyUnicode_FSConverter, &opath, |
2053 &uid, &gid)) | 2106 &uid, &gid)) |
2054 return NULL; | 2107 return NULL; |
| 2108 path = bytes2str(opath, 1); |
2055 Py_BEGIN_ALLOW_THREADS | 2109 Py_BEGIN_ALLOW_THREADS |
2056 res = lchown(path, (uid_t) uid, (gid_t) gid); | 2110 res = lchown(path, (uid_t) uid, (gid_t) gid); |
2057 Py_END_ALLOW_THREADS | 2111 Py_END_ALLOW_THREADS |
2058 if (res < 0) | 2112 if (res < 0) |
2059 » » return posix_error_with_allocated_filename(path); | 2113 » » return posix_error_with_allocated_filename(opath); |
2060 » PyMem_Free(path); | 2114 » release_bytes(opath); |
2061 Py_INCREF(Py_None); | 2115 Py_INCREF(Py_None); |
2062 return Py_None; | 2116 return Py_None; |
2063 } | 2117 } |
2064 #endif /* HAVE_LCHOWN */ | 2118 #endif /* HAVE_LCHOWN */ |
2065 | 2119 |
2066 | 2120 |
2067 #ifdef HAVE_GETCWD | 2121 #ifdef HAVE_GETCWD |
2068 static PyObject * | 2122 static PyObject * |
2069 posix_getcwd(int use_bytes) | 2123 posix_getcwd(int use_bytes) |
2070 { | 2124 { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2106 #if defined(PYOS_OS2) && defined(PYCC_GCC) | 2160 #if defined(PYOS_OS2) && defined(PYCC_GCC) |
2107 res = _getcwd2(buf, sizeof buf); | 2161 res = _getcwd2(buf, sizeof buf); |
2108 #else | 2162 #else |
2109 res = getcwd(buf, sizeof buf); | 2163 res = getcwd(buf, sizeof buf); |
2110 #endif | 2164 #endif |
2111 Py_END_ALLOW_THREADS | 2165 Py_END_ALLOW_THREADS |
2112 if (res == NULL) | 2166 if (res == NULL) |
2113 return posix_error(); | 2167 return posix_error(); |
2114 if (use_bytes) | 2168 if (use_bytes) |
2115 return PyBytes_FromStringAndSize(buf, strlen(buf)); | 2169 return PyBytes_FromStringAndSize(buf, strlen(buf)); |
2116 » return PyUnicode_Decode(buf, strlen(buf), Py_FileSystemDefaultEncoding,"
strict"); | 2170 » return PyUnicode_Decode(buf, strlen(buf), Py_FileSystemDefaultEncoding,"
utf8b"); |
2117 } | 2171 } |
2118 | 2172 |
2119 PyDoc_STRVAR(posix_getcwd__doc__, | 2173 PyDoc_STRVAR(posix_getcwd__doc__, |
2120 "getcwd() -> path\n\n\ | 2174 "getcwd() -> path\n\n\ |
2121 Return a unicode string representing the current working directory."); | 2175 Return a unicode string representing the current working directory."); |
2122 | 2176 |
2123 static PyObject * | 2177 static PyObject * |
2124 posix_getcwd_unicode(PyObject *self) | 2178 posix_getcwd_unicode(PyObject *self) |
2125 { | 2179 { |
2126 return posix_getcwd(0); | 2180 return posix_getcwd(0); |
(...skipping 12 matching lines...) Expand all Loading... |
2139 | 2193 |
2140 | 2194 |
2141 #ifdef HAVE_LINK | 2195 #ifdef HAVE_LINK |
2142 PyDoc_STRVAR(posix_link__doc__, | 2196 PyDoc_STRVAR(posix_link__doc__, |
2143 "link(src, dst)\n\n\ | 2197 "link(src, dst)\n\n\ |
2144 Create a hard link to a file."); | 2198 Create a hard link to a file."); |
2145 | 2199 |
2146 static PyObject * | 2200 static PyObject * |
2147 posix_link(PyObject *self, PyObject *args) | 2201 posix_link(PyObject *self, PyObject *args) |
2148 { | 2202 { |
2149 » return posix_2str(args, "etet:link", link); | 2203 » return posix_2str(args, "O&O&:link", link); |
2150 } | 2204 } |
2151 #endif /* HAVE_LINK */ | 2205 #endif /* HAVE_LINK */ |
2152 | 2206 |
2153 | 2207 |
2154 PyDoc_STRVAR(posix_listdir__doc__, | 2208 PyDoc_STRVAR(posix_listdir__doc__, |
2155 "listdir(path) -> list_of_strings\n\n\ | 2209 "listdir(path) -> list_of_strings\n\n\ |
2156 Return a list containing the names of the entries in the directory.\n\ | 2210 Return a list containing the names of the entries in the directory.\n\ |
2157 \n\ | 2211 \n\ |
2158 path: path of directory to list\n\ | 2212 path: path of directory to list\n\ |
2159 \n\ | 2213 \n\ |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2252 } | 2306 } |
2253 free(wnamebuf); | 2307 free(wnamebuf); |
2254 return d; | 2308 return d; |
2255 } | 2309 } |
2256 /* Drop the argument parsing error as narrow strings | 2310 /* Drop the argument parsing error as narrow strings |
2257 are also valid. */ | 2311 are also valid. */ |
2258 PyErr_Clear(); | 2312 PyErr_Clear(); |
2259 } | 2313 } |
2260 #endif | 2314 #endif |
2261 | 2315 |
2262 » if (!PyArg_ParseTuple(args, "et#:listdir", | 2316 » if (!PyArg_ParseTuple(args, "O&:listdir", |
2263 » Py_FileSystemDefaultEncoding, &bufptr, &len)) | 2317 » PyUnicode_FSConverter, &opath)) |
2264 return NULL; | 2318 return NULL; |
| 2319 if (PyObject_Size(opath)+1 > MAX_PATH) { |
| 2320 PyErr_SetString(PyExc_ValueError, "path too long"); |
| 2321 Py_DECREF(opath); |
| 2322 return NULL; |
| 2323 } |
| 2324 strcpy(namebuf, bytes2str(opath, 0)); |
| 2325 len = PyObject_Size(opath); |
2265 if (len > 0) { | 2326 if (len > 0) { |
2266 char ch = namebuf[len-1]; | 2327 char ch = namebuf[len-1]; |
2267 if (ch != SEP && ch != ALTSEP && ch != ':') | 2328 if (ch != SEP && ch != ALTSEP && ch != ':') |
2268 namebuf[len++] = '/'; | 2329 namebuf[len++] = '/'; |
2269 } | 2330 } |
2270 strcpy(namebuf + len, "*.*"); | 2331 strcpy(namebuf + len, "*.*"); |
2271 | 2332 |
2272 if ((d = PyList_New(0)) == NULL) | 2333 if ((d = PyList_New(0)) == NULL) |
2273 return NULL; | 2334 return NULL; |
2274 | 2335 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2316 return win32_error("FindClose", namebuf); | 2377 return win32_error("FindClose", namebuf); |
2317 } | 2378 } |
2318 | 2379 |
2319 return d; | 2380 return d; |
2320 | 2381 |
2321 #elif defined(PYOS_OS2) | 2382 #elif defined(PYOS_OS2) |
2322 | 2383 |
2323 #ifndef MAX_PATH | 2384 #ifndef MAX_PATH |
2324 #define MAX_PATH CCHMAXPATH | 2385 #define MAX_PATH CCHMAXPATH |
2325 #endif | 2386 #endif |
| 2387 PyObject *oname; |
2326 char *name, *pt; | 2388 char *name, *pt; |
2327 Py_ssize_t len; | 2389 Py_ssize_t len; |
2328 PyObject *d, *v; | 2390 PyObject *d, *v; |
2329 char namebuf[MAX_PATH+5]; | 2391 char namebuf[MAX_PATH+5]; |
2330 HDIR hdir = 1; | 2392 HDIR hdir = 1; |
2331 ULONG srchcnt = 1; | 2393 ULONG srchcnt = 1; |
2332 FILEFINDBUF3 ep; | 2394 FILEFINDBUF3 ep; |
2333 APIRET rc; | 2395 APIRET rc; |
2334 | 2396 |
2335 if (!PyArg_ParseTuple(args, "et#:listdir",· | 2397 if (!PyArg_ParseTuple(args, "O&:listdir",· |
2336 Py_FileSystemDefaultEncoding, &name, &len)) | 2398 PyUnicode_FSConverter, &oname)) |
2337 return NULL; | 2399 return NULL; |
| 2400 name = bytes2str(oname); |
| 2401 len = PyObject_Size(oname); |
2338 if (len >= MAX_PATH) { | 2402 if (len >= MAX_PATH) { |
2339 PyMem_Free(name); | 2403 release_bytes(oname); |
2340 PyErr_SetString(PyExc_ValueError, "path too long"); | 2404 PyErr_SetString(PyExc_ValueError, "path too long"); |
2341 return NULL; | 2405 return NULL; |
2342 } | 2406 } |
2343 strcpy(namebuf, name); | 2407 strcpy(namebuf, name); |
2344 for (pt = namebuf; *pt; pt++) | 2408 for (pt = namebuf; *pt; pt++) |
2345 if (*pt == ALTSEP) | 2409 if (*pt == ALTSEP) |
2346 *pt = SEP; | 2410 *pt = SEP; |
2347 if (namebuf[len-1] != SEP) | 2411 if (namebuf[len-1] != SEP) |
2348 namebuf[len++] = SEP; | 2412 namebuf[len++] = SEP; |
2349 strcpy(namebuf + len, "*.*"); | 2413 strcpy(namebuf + len, "*.*"); |
2350 | 2414 |
2351 if ((d = PyList_New(0)) == NULL) { | 2415 if ((d = PyList_New(0)) == NULL) { |
2352 PyMem_Free(name); | 2416 release_bytes(oname); |
2353 return NULL; | 2417 return NULL; |
2354 } | 2418 } |
2355 | 2419 |
2356 rc = DosFindFirst(namebuf, /* Wildcard Pattern to Match */ | 2420 rc = DosFindFirst(namebuf, /* Wildcard Pattern to Match */ |
2357 &hdir, /* Handle to Use While Search Directory *
/ | 2421 &hdir, /* Handle to Use While Search Directory *
/ |
2358 FILE_READONLY | FILE_HIDDEN | FILE_SYSTEM | FILE_DIRECTORY
, | 2422 FILE_READONLY | FILE_HIDDEN | FILE_SYSTEM | FILE_DIRECTORY
, |
2359 &ep, sizeof(ep), /* Structure to Receive Directory Entry *
/ | 2423 &ep, sizeof(ep), /* Structure to Receive Directory Entry *
/ |
2360 &srchcnt, /* Max and Actual Count of Entries Per It
eration */ | 2424 &srchcnt, /* Max and Actual Count of Entries Per It
eration */ |
2361 FIL_STANDARD); /* Format of Entry (EAs or Not) */ | 2425 FIL_STANDARD); /* Format of Entry (EAs or Not) */ |
2362 | 2426 |
2363 if (rc != NO_ERROR) { | 2427 if (rc != NO_ERROR) { |
2364 errno = ENOENT; | 2428 errno = ENOENT; |
2365 return posix_error_with_allocated_filename(name); | 2429 return posix_error_with_allocated_filename(oname); |
2366 } | 2430 } |
2367 | 2431 |
2368 if (srchcnt > 0) { /* If Directory is NOT Totally Empty, */ | 2432 if (srchcnt > 0) { /* If Directory is NOT Totally Empty, */ |
2369 do { | 2433 do { |
2370 if (ep.achName[0] == '.' | 2434 if (ep.achName[0] == '.' |
2371 && (ep.achName[1] == '\0' || (ep.achName[1] == '.' && ep.achName[2]
== '\0'))) | 2435 && (ep.achName[1] == '\0' || (ep.achName[1] == '.' && ep.achName[2]
== '\0'))) |
2372 continue; /* Skip Over "." and ".." Names */ | 2436 continue; /* Skip Over "." and ".." Names */ |
2373 | 2437 |
2374 strcpy(namebuf, ep.achName); | 2438 strcpy(namebuf, ep.achName); |
2375 | 2439 |
2376 /* Leave Case of Name Alone -- In Native Form */ | 2440 /* Leave Case of Name Alone -- In Native Form */ |
2377 /* (Removed Forced Lowercasing Code) */ | 2441 /* (Removed Forced Lowercasing Code) */ |
2378 | 2442 |
2379 v = PyBytes_FromString(namebuf); | 2443 v = PyBytes_FromString(namebuf); |
2380 if (v == NULL) { | 2444 if (v == NULL) { |
2381 Py_DECREF(d); | 2445 Py_DECREF(d); |
2382 d = NULL; | 2446 d = NULL; |
2383 break; | 2447 break; |
2384 } | 2448 } |
2385 if (PyList_Append(d, v) != 0) { | 2449 if (PyList_Append(d, v) != 0) { |
2386 Py_DECREF(v); | 2450 Py_DECREF(v); |
2387 Py_DECREF(d); | 2451 Py_DECREF(d); |
2388 d = NULL; | 2452 d = NULL; |
2389 break; | 2453 break; |
2390 } | 2454 } |
2391 Py_DECREF(v); | 2455 Py_DECREF(v); |
2392 } while (DosFindNext(hdir, &ep, sizeof(ep), &srchcnt) == NO_ERROR && src
hcnt > 0); | 2456 } while (DosFindNext(hdir, &ep, sizeof(ep), &srchcnt) == NO_ERROR && src
hcnt > 0); |
2393 } | 2457 } |
2394 | 2458 |
2395 PyMem_Free(name); | 2459 release_bytes(oname); |
2396 return d; | 2460 return d; |
2397 #else | 2461 #else |
2398 | 2462 » PyObject *oname; |
2399 » char *name = NULL; | 2463 » char *name; |
2400 PyObject *d, *v; | 2464 PyObject *d, *v; |
2401 DIR *dirp; | 2465 DIR *dirp; |
2402 struct dirent *ep; | 2466 struct dirent *ep; |
2403 int arg_is_unicode = 1; | 2467 int arg_is_unicode = 1; |
2404 | 2468 |
2405 errno = 0; | 2469 errno = 0; |
2406 if (!PyArg_ParseTuple(args, "U:listdir", &v)) { | 2470 if (!PyArg_ParseTuple(args, "U:listdir", &v)) { |
2407 arg_is_unicode = 0; | 2471 arg_is_unicode = 0; |
2408 PyErr_Clear(); | 2472 PyErr_Clear(); |
2409 } | 2473 } |
2410 » if (!PyArg_ParseTuple(args, "et:listdir", Py_FileSystemDefaultEncoding,
&name)) | 2474 » if (!PyArg_ParseTuple(args, "O&:listdir", PyUnicode_FSConverter, &oname)
) |
2411 return NULL; | 2475 return NULL; |
| 2476 name = bytes2str(oname, 1); |
2412 if ((dirp = opendir(name)) == NULL) { | 2477 if ((dirp = opendir(name)) == NULL) { |
2413 » » return posix_error_with_allocated_filename(name); | 2478 » » return posix_error_with_allocated_filename(oname); |
2414 } | 2479 } |
2415 if ((d = PyList_New(0)) == NULL) { | 2480 if ((d = PyList_New(0)) == NULL) { |
2416 closedir(dirp); | 2481 closedir(dirp); |
2417 » » PyMem_Free(name); | 2482 » » release_bytes(oname); |
2418 return NULL; | 2483 return NULL; |
2419 } | 2484 } |
2420 for (;;) { | 2485 for (;;) { |
2421 errno = 0; | 2486 errno = 0; |
2422 Py_BEGIN_ALLOW_THREADS | 2487 Py_BEGIN_ALLOW_THREADS |
2423 ep = readdir(dirp); | 2488 ep = readdir(dirp); |
2424 Py_END_ALLOW_THREADS | 2489 Py_END_ALLOW_THREADS |
2425 if (ep == NULL) { | 2490 if (ep == NULL) { |
2426 if (errno == 0) { | 2491 if (errno == 0) { |
2427 break; | 2492 break; |
2428 } else { | 2493 } else { |
2429 closedir(dirp); | 2494 closedir(dirp); |
2430 Py_DECREF(d); | 2495 Py_DECREF(d); |
2431 » » » » return posix_error_with_allocated_filename(name)
; | 2496 » » » » return posix_error_with_allocated_filename(oname
); |
2432 } | 2497 } |
2433 } | 2498 } |
2434 if (ep->d_name[0] == '.' && | 2499 if (ep->d_name[0] == '.' && |
2435 (NAMLEN(ep) == 1 || | 2500 (NAMLEN(ep) == 1 || |
2436 (ep->d_name[1] == '.' && NAMLEN(ep) == 2))) | 2501 (ep->d_name[1] == '.' && NAMLEN(ep) == 2))) |
2437 continue; | 2502 continue; |
2438 v = PyBytes_FromStringAndSize(ep->d_name, NAMLEN(ep)); | 2503 v = PyBytes_FromStringAndSize(ep->d_name, NAMLEN(ep)); |
2439 if (v == NULL) { | 2504 if (v == NULL) { |
2440 Py_DECREF(d); | 2505 Py_DECREF(d); |
2441 d = NULL; | 2506 d = NULL; |
2442 break; | 2507 break; |
2443 } | 2508 } |
2444 if (arg_is_unicode) { | 2509 if (arg_is_unicode) { |
2445 PyObject *w; | 2510 PyObject *w; |
2446 | 2511 |
2447 w = PyUnicode_FromEncodedObject(v, | 2512 w = PyUnicode_FromEncodedObject(v, |
2448 Py_FileSystemDefaultEncoding, | 2513 Py_FileSystemDefaultEncoding, |
2449 » » » » » "strict"); | 2514 » » » » » "utf8b"); |
2450 » » » if (w != NULL) { | 2515 » » » Py_DECREF(v); |
2451 » » » » Py_DECREF(v); | 2516 » » » if (w != NULL) |
2452 v = w; | 2517 v = w; |
2453 } | |
2454 else { | 2518 else { |
2455 » » » » /* Ignore undecodable filenames, as discussed | 2519 » » » » /* Encoding failed to decode ASCII bytes. |
2456 » » » » * in issue 3187. To include these, | 2520 » » » » Raise exception. */ |
2457 » » » » * use getcwdb(). */ | 2521 » » » » Py_DECREF(d); |
2458 » » » » PyErr_Clear(); | 2522 » » » » d = NULL; |
2459 » » » » Py_DECREF(v); | 2523 » » » » break; |
2460 » » » » continue; | |
2461 } | 2524 } |
2462 } | 2525 } |
2463 if (PyList_Append(d, v) != 0) { | 2526 if (PyList_Append(d, v) != 0) { |
2464 Py_DECREF(v); | 2527 Py_DECREF(v); |
2465 Py_DECREF(d); | 2528 Py_DECREF(d); |
2466 d = NULL; | 2529 d = NULL; |
2467 break; | 2530 break; |
2468 } | 2531 } |
2469 Py_DECREF(v); | 2532 Py_DECREF(v); |
2470 } | 2533 } |
2471 closedir(dirp); | 2534 closedir(dirp); |
2472 » PyMem_Free(name); | 2535 » release_bytes(oname); |
2473 | 2536 |
2474 return d; | 2537 return d; |
2475 | 2538 |
2476 #endif /* which OS */ | 2539 #endif /* which OS */ |
2477 } /* end of posix_listdir */ | 2540 } /* end of posix_listdir */ |
2478 | 2541 |
2479 #ifdef MS_WINDOWS | 2542 #ifdef MS_WINDOWS |
2480 /* A helper function for abspath on win32 */ | 2543 /* A helper function for abspath on win32 */ |
2481 static PyObject * | 2544 static PyObject * |
2482 posix__getfullpathname(PyObject *self, PyObject *args) | 2545 posix__getfullpathname(PyObject *self, PyObject *args) |
2483 { | 2546 { |
2484 » /* assume encoded strings won't more than double no of chars */ | 2547 » PyObject *opath; |
2485 » char inbuf[MAX_PATH*2]; | 2548 » char *path; |
2486 » char *inbufp = inbuf; | |
2487 » Py_ssize_t insize = sizeof(inbuf); | |
2488 char outbuf[MAX_PATH*2]; | 2549 char outbuf[MAX_PATH*2]; |
2489 char *temp; | 2550 char *temp; |
2490 #ifdef Py_WIN_WIDE_FILENAMES | 2551 #ifdef Py_WIN_WIDE_FILENAMES |
2491 if (unicode_file_names()) { | 2552 if (unicode_file_names()) { |
2492 PyUnicodeObject *po; | 2553 PyUnicodeObject *po; |
2493 if (PyArg_ParseTuple(args, "U|:_getfullpathname", &po)) { | 2554 if (PyArg_ParseTuple(args, "U|:_getfullpathname", &po)) { |
2494 Py_UNICODE *wpath = PyUnicode_AS_UNICODE(po); | 2555 Py_UNICODE *wpath = PyUnicode_AS_UNICODE(po); |
2495 Py_UNICODE woutbuf[MAX_PATH*2], *woutbufp = woutbuf; | 2556 Py_UNICODE woutbuf[MAX_PATH*2], *woutbufp = woutbuf; |
2496 Py_UNICODE *wtemp; | 2557 Py_UNICODE *wtemp; |
2497 DWORD result; | 2558 DWORD result; |
(...skipping 13 matching lines...) Expand all Loading... |
2511 v = win32_error_unicode("GetFullPathNameW", wpat
h); | 2572 v = win32_error_unicode("GetFullPathNameW", wpat
h); |
2512 if (woutbufp != woutbuf) | 2573 if (woutbufp != woutbuf) |
2513 free(woutbufp); | 2574 free(woutbufp); |
2514 return v; | 2575 return v; |
2515 } | 2576 } |
2516 /* Drop the argument parsing error as narrow strings | 2577 /* Drop the argument parsing error as narrow strings |
2517 are also valid. */ | 2578 are also valid. */ |
2518 PyErr_Clear(); | 2579 PyErr_Clear(); |
2519 } | 2580 } |
2520 #endif | 2581 #endif |
2521 » if (!PyArg_ParseTuple (args, "et#:_getfullpathname", | 2582 » if (!PyArg_ParseTuple (args, "O&:_getfullpathname", |
2522 » Py_FileSystemDefaultEncoding, &inbufp, | 2583 » PyUnicode_FSConverter, &opath)) |
2523 » &insize)) | |
2524 return NULL; | 2584 return NULL; |
2525 » if (!GetFullPathName(inbuf, sizeof(outbuf)/sizeof(outbuf[0]), | 2585 » path = bytes2str(opath, 1); |
2526 » outbuf, &temp)) | 2586 » if (!GetFullPathName(path, sizeof(outbuf)/sizeof(outbuf[0]), |
2527 » » return win32_error("GetFullPathName", inbuf); | 2587 » outbuf, &temp)) { |
| 2588 » » win32_error("GetFullPathName", path); |
| 2589 » » release_bytes(opath); |
| 2590 » » return NULL; |
| 2591 » } |
| 2592 » release_bytes(path); |
2528 if (PyUnicode_Check(PyTuple_GetItem(args, 0))) { | 2593 if (PyUnicode_Check(PyTuple_GetItem(args, 0))) { |
2529 return PyUnicode_Decode(outbuf, strlen(outbuf), | 2594 return PyUnicode_Decode(outbuf, strlen(outbuf), |
2530 Py_FileSystemDefaultEncoding, NULL); | 2595 Py_FileSystemDefaultEncoding, NULL); |
2531 } | 2596 } |
2532 return PyBytes_FromString(outbuf); | 2597 return PyBytes_FromString(outbuf); |
2533 } /* end of posix__getfullpathname */ | 2598 } /* end of posix__getfullpathname */ |
2534 #endif /* MS_WINDOWS */ | 2599 #endif /* MS_WINDOWS */ |
2535 | 2600 |
2536 PyDoc_STRVAR(posix_mkdir__doc__, | 2601 PyDoc_STRVAR(posix_mkdir__doc__, |
2537 "mkdir(path [, mode=0777])\n\n\ | 2602 "mkdir(path [, mode=0777])\n\n\ |
2538 Create a directory."); | 2603 Create a directory."); |
2539 | 2604 |
2540 static PyObject * | 2605 static PyObject * |
2541 posix_mkdir(PyObject *self, PyObject *args) | 2606 posix_mkdir(PyObject *self, PyObject *args) |
2542 { | 2607 { |
2543 int res; | 2608 int res; |
2544 » char *path = NULL; | 2609 » PyObject *opath; |
| 2610 » char *path; |
2545 int mode = 0777; | 2611 int mode = 0777; |
2546 | 2612 |
2547 #ifdef Py_WIN_WIDE_FILENAMES | 2613 #ifdef Py_WIN_WIDE_FILENAMES |
2548 if (unicode_file_names()) { | 2614 if (unicode_file_names()) { |
2549 PyUnicodeObject *po; | 2615 PyUnicodeObject *po; |
2550 if (PyArg_ParseTuple(args, "U|i:mkdir", &po, &mode)) { | 2616 if (PyArg_ParseTuple(args, "U|i:mkdir", &po, &mode)) { |
2551 Py_BEGIN_ALLOW_THREADS | 2617 Py_BEGIN_ALLOW_THREADS |
2552 /* PyUnicode_AS_UNICODE OK without thread lock as | 2618 /* PyUnicode_AS_UNICODE OK without thread lock as |
2553 it is a simple dereference. */ | 2619 it is a simple dereference. */ |
2554 res = CreateDirectoryW(PyUnicode_AS_UNICODE(po), NULL); | 2620 res = CreateDirectoryW(PyUnicode_AS_UNICODE(po), NULL); |
2555 Py_END_ALLOW_THREADS | 2621 Py_END_ALLOW_THREADS |
2556 if (!res) | 2622 if (!res) |
2557 return win32_error_unicode("mkdir", PyUnicode_AS
_UNICODE(po)); | 2623 return win32_error_unicode("mkdir", PyUnicode_AS
_UNICODE(po)); |
2558 Py_INCREF(Py_None); | 2624 Py_INCREF(Py_None); |
2559 return Py_None; | 2625 return Py_None; |
2560 } | 2626 } |
2561 /* Drop the argument parsing error as narrow strings | 2627 /* Drop the argument parsing error as narrow strings |
2562 are also valid. */ | 2628 are also valid. */ |
2563 PyErr_Clear(); | 2629 PyErr_Clear(); |
2564 } | 2630 } |
2565 » if (!PyArg_ParseTuple(args, "et|i:mkdir", | 2631 » if (!PyArg_ParseTuple(args, "O&|i:mkdir", |
2566 » Py_FileSystemDefaultEncoding, &path, &mode)) | 2632 » PyUnicode_FSConverter, &opath, &mode)) |
2567 return NULL; | 2633 return NULL; |
| 2634 path = bytes2str(opath, 1); |
2568 Py_BEGIN_ALLOW_THREADS | 2635 Py_BEGIN_ALLOW_THREADS |
2569 /* PyUnicode_AS_UNICODE OK without thread lock as | 2636 /* PyUnicode_AS_UNICODE OK without thread lock as |
2570 it is a simple dereference. */ | 2637 it is a simple dereference. */ |
2571 res = CreateDirectoryA(path, NULL); | 2638 res = CreateDirectoryA(path, NULL); |
2572 Py_END_ALLOW_THREADS | 2639 Py_END_ALLOW_THREADS |
2573 if (!res) { | 2640 if (!res) { |
2574 win32_error("mkdir", path); | 2641 win32_error("mkdir", path); |
2575 » » PyMem_Free(path); | 2642 » » release_bytes(opath); |
2576 return NULL; | 2643 return NULL; |
2577 } | 2644 } |
2578 » PyMem_Free(path); | 2645 » release_bytes(opath); |
2579 Py_INCREF(Py_None); | 2646 Py_INCREF(Py_None); |
2580 return Py_None; | 2647 return Py_None; |
2581 #else | 2648 #else |
2582 | 2649 |
2583 » if (!PyArg_ParseTuple(args, "et|i:mkdir", | 2650 » if (!PyArg_ParseTuple(args, "O&|i:mkdir", |
2584 » Py_FileSystemDefaultEncoding, &path, &mode)) | 2651 » PyUnicode_FSConverter, &opath, &mode)) |
2585 return NULL; | 2652 return NULL; |
| 2653 path = bytes2str(opath, 1); |
2586 Py_BEGIN_ALLOW_THREADS | 2654 Py_BEGIN_ALLOW_THREADS |
2587 #if ( defined(__WATCOMC__) || defined(PYCC_VACPP) ) && !defined(__QNX__) | 2655 #if ( defined(__WATCOMC__) || defined(PYCC_VACPP) ) && !defined(__QNX__) |
2588 res = mkdir(path); | 2656 res = mkdir(path); |
2589 #else | 2657 #else |
2590 res = mkdir(path, mode); | 2658 res = mkdir(path, mode); |
2591 #endif | 2659 #endif |
2592 Py_END_ALLOW_THREADS | 2660 Py_END_ALLOW_THREADS |
2593 if (res < 0) | 2661 if (res < 0) |
2594 » » return posix_error_with_allocated_filename(path); | 2662 » » return posix_error_with_allocated_filename(opath); |
2595 » PyMem_Free(path); | 2663 » release_bytes(opath); |
2596 Py_INCREF(Py_None); | 2664 Py_INCREF(Py_None); |
2597 return Py_None; | 2665 return Py_None; |
2598 #endif | 2666 #endif |
2599 } | 2667 } |
2600 | 2668 |
2601 | 2669 |
2602 /* sys/resource.h is needed for at least: wait3(), wait4(), broken nice. */ | 2670 /* sys/resource.h is needed for at least: wait3(), wait4(), broken nice. */ |
2603 #if defined(HAVE_SYS_RESOURCE_H) | 2671 #if defined(HAVE_SYS_RESOURCE_H) |
2604 #include <sys/resource.h> | 2672 #include <sys/resource.h> |
2605 #endif | 2673 #endif |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2677 if (!PyArg_ParseTuple(args, "ss:rename", &p1, &p2)) | 2745 if (!PyArg_ParseTuple(args, "ss:rename", &p1, &p2)) |
2678 return NULL; | 2746 return NULL; |
2679 Py_BEGIN_ALLOW_THREADS | 2747 Py_BEGIN_ALLOW_THREADS |
2680 result = MoveFileA(p1, p2); | 2748 result = MoveFileA(p1, p2); |
2681 Py_END_ALLOW_THREADS | 2749 Py_END_ALLOW_THREADS |
2682 if (!result) | 2750 if (!result) |
2683 return win32_error("rename", NULL); | 2751 return win32_error("rename", NULL); |
2684 Py_INCREF(Py_None); | 2752 Py_INCREF(Py_None); |
2685 return Py_None; | 2753 return Py_None; |
2686 #else | 2754 #else |
2687 » return posix_2str(args, "etet:rename", rename); | 2755 » return posix_2str(args, "O&O&:rename", rename); |
2688 #endif | 2756 #endif |
2689 } | 2757 } |
2690 | 2758 |
2691 | 2759 |
2692 PyDoc_STRVAR(posix_rmdir__doc__, | 2760 PyDoc_STRVAR(posix_rmdir__doc__, |
2693 "rmdir(path)\n\n\ | 2761 "rmdir(path)\n\n\ |
2694 Remove a directory."); | 2762 Remove a directory."); |
2695 | 2763 |
2696 static PyObject * | 2764 static PyObject * |
2697 posix_rmdir(PyObject *self, PyObject *args) | 2765 posix_rmdir(PyObject *self, PyObject *args) |
2698 { | 2766 { |
2699 #ifdef MS_WINDOWS | 2767 #ifdef MS_WINDOWS |
2700 return win32_1str(args, "rmdir", "y:rmdir", RemoveDirectoryA, "U:rmdir",
RemoveDirectoryW); | 2768 return win32_1str(args, "rmdir", "y:rmdir", RemoveDirectoryA, "U:rmdir",
RemoveDirectoryW); |
2701 #else | 2769 #else |
2702 » return posix_1str(args, "et:rmdir", rmdir); | 2770 » return posix_1str(args, "O&:rmdir", rmdir); |
2703 #endif | 2771 #endif |
2704 } | 2772 } |
2705 | 2773 |
2706 | 2774 |
2707 PyDoc_STRVAR(posix_stat__doc__, | 2775 PyDoc_STRVAR(posix_stat__doc__, |
2708 "stat(path) -> stat result\n\n\ | 2776 "stat(path) -> stat result\n\n\ |
2709 Perform a stat system call on the given path."); | 2777 Perform a stat system call on the given path."); |
2710 | 2778 |
2711 static PyObject * | 2779 static PyObject * |
2712 posix_stat(PyObject *self, PyObject *args) | 2780 posix_stat(PyObject *self, PyObject *args) |
2713 { | 2781 { |
2714 #ifdef MS_WINDOWS | 2782 #ifdef MS_WINDOWS |
2715 » return posix_do_stat(self, args, "et:stat", STAT, "U:stat", win32_wstat)
; | 2783 » return posix_do_stat(self, args, "O&:stat", STAT, "U:stat", win32_wstat)
; |
2716 #else | 2784 #else |
2717 » return posix_do_stat(self, args, "et:stat", STAT, NULL, NULL); | 2785 » return posix_do_stat(self, args, "O&:stat", STAT, NULL, NULL); |
2718 #endif | 2786 #endif |
2719 } | 2787 } |
2720 | 2788 |
2721 | 2789 |
2722 #ifdef HAVE_SYSTEM | 2790 #ifdef HAVE_SYSTEM |
2723 PyDoc_STRVAR(posix_system__doc__, | 2791 PyDoc_STRVAR(posix_system__doc__, |
2724 "system(command) -> exit_status\n\n\ | 2792 "system(command) -> exit_status\n\n\ |
2725 Execute the command (a string) in a subshell."); | 2793 Execute the command (a string) in a subshell."); |
2726 | 2794 |
2727 static PyObject * | 2795 static PyObject * |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2773 PyDoc_STRVAR(posix_remove__doc__, | 2841 PyDoc_STRVAR(posix_remove__doc__, |
2774 "remove(path)\n\n\ | 2842 "remove(path)\n\n\ |
2775 Remove a file (same as unlink(path))."); | 2843 Remove a file (same as unlink(path))."); |
2776 | 2844 |
2777 static PyObject * | 2845 static PyObject * |
2778 posix_unlink(PyObject *self, PyObject *args) | 2846 posix_unlink(PyObject *self, PyObject *args) |
2779 { | 2847 { |
2780 #ifdef MS_WINDOWS | 2848 #ifdef MS_WINDOWS |
2781 return win32_1str(args, "remove", "y:remove", DeleteFileA, "U:remove", D
eleteFileW); | 2849 return win32_1str(args, "remove", "y:remove", DeleteFileA, "U:remove", D
eleteFileW); |
2782 #else | 2850 #else |
2783 » return posix_1str(args, "et:remove", unlink); | 2851 » return posix_1str(args, "O&:remove", unlink); |
2784 #endif | 2852 #endif |
2785 } | 2853 } |
2786 | 2854 |
2787 | 2855 |
2788 #ifdef HAVE_UNAME | 2856 #ifdef HAVE_UNAME |
2789 PyDoc_STRVAR(posix_uname__doc__, | 2857 PyDoc_STRVAR(posix_uname__doc__, |
2790 "uname() -> (sysname, nodename, release, version, machine)\n\n\ | 2858 "uname() -> (sysname, nodename, release, version, machine)\n\n\ |
2791 Return a tuple identifying the current operating system."); | 2859 Return a tuple identifying the current operating system."); |
2792 | 2860 |
2793 static PyObject * | 2861 static PyObject * |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2845 Set the access and modified time of the file to the given values. If the\n\ | 2913 Set the access and modified time of the file to the given values. If the\n\ |
2846 second form is used, set the access and modified times to the current time."); | 2914 second form is used, set the access and modified times to the current time."); |
2847 | 2915 |
2848 static PyObject * | 2916 static PyObject * |
2849 posix_utime(PyObject *self, PyObject *args) | 2917 posix_utime(PyObject *self, PyObject *args) |
2850 { | 2918 { |
2851 #ifdef Py_WIN_WIDE_FILENAMES | 2919 #ifdef Py_WIN_WIDE_FILENAMES |
2852 PyObject *arg; | 2920 PyObject *arg; |
2853 PyUnicodeObject *obwpath; | 2921 PyUnicodeObject *obwpath; |
2854 wchar_t *wpath = NULL; | 2922 wchar_t *wpath = NULL; |
2855 » char *apath = NULL; | 2923 » PyObject *oapath; |
| 2924 » char *apath; |
2856 HANDLE hFile; | 2925 HANDLE hFile; |
2857 long atimesec, mtimesec, ausec, musec; | 2926 long atimesec, mtimesec, ausec, musec; |
2858 FILETIME atime, mtime; | 2927 FILETIME atime, mtime; |
2859 PyObject *result = NULL; | 2928 PyObject *result = NULL; |
2860 | 2929 |
2861 if (unicode_file_names()) { | 2930 if (unicode_file_names()) { |
2862 if (PyArg_ParseTuple(args, "UO|:utime", &obwpath, &arg)) { | 2931 if (PyArg_ParseTuple(args, "UO|:utime", &obwpath, &arg)) { |
2863 wpath = PyUnicode_AS_UNICODE(obwpath); | 2932 wpath = PyUnicode_AS_UNICODE(obwpath); |
2864 Py_BEGIN_ALLOW_THREADS | 2933 Py_BEGIN_ALLOW_THREADS |
2865 hFile = CreateFileW(wpath, FILE_WRITE_ATTRIBUTES, 0, | 2934 hFile = CreateFileW(wpath, FILE_WRITE_ATTRIBUTES, 0, |
2866 NULL, OPEN_EXISTING, | 2935 NULL, OPEN_EXISTING, |
2867 FILE_FLAG_BACKUP_SEMANTICS, NULL); | 2936 FILE_FLAG_BACKUP_SEMANTICS, NULL); |
2868 Py_END_ALLOW_THREADS | 2937 Py_END_ALLOW_THREADS |
2869 if (hFile == INVALID_HANDLE_VALUE) | 2938 if (hFile == INVALID_HANDLE_VALUE) |
2870 return win32_error_unicode("utime", wpath); | 2939 return win32_error_unicode("utime", wpath); |
2871 } else | 2940 } else |
2872 /* Drop the argument parsing error as narrow strings | 2941 /* Drop the argument parsing error as narrow strings |
2873 are also valid. */ | 2942 are also valid. */ |
2874 PyErr_Clear(); | 2943 PyErr_Clear(); |
2875 } | 2944 } |
2876 if (!wpath) { | 2945 if (!wpath) { |
2877 » » if (!PyArg_ParseTuple(args, "etO:utime", | 2946 » » if (!PyArg_ParseTuple(args, "O&O:utime", |
2878 » » » » Py_FileSystemDefaultEncoding, &apath, &arg)) | 2947 » » » » PyUnicode_FSConverter, &oapath, &arg)) |
2879 return NULL; | 2948 return NULL; |
| 2949 apath = bytes2str(oapath); |
2880 Py_BEGIN_ALLOW_THREADS | 2950 Py_BEGIN_ALLOW_THREADS |
2881 hFile = CreateFileA(apath, FILE_WRITE_ATTRIBUTES, 0, | 2951 hFile = CreateFileA(apath, FILE_WRITE_ATTRIBUTES, 0, |
2882 NULL, OPEN_EXISTING, | 2952 NULL, OPEN_EXISTING, |
2883 FILE_FLAG_BACKUP_SEMANTICS, NULL); | 2953 FILE_FLAG_BACKUP_SEMANTICS, NULL); |
2884 Py_END_ALLOW_THREADS | 2954 Py_END_ALLOW_THREADS |
2885 if (hFile == INVALID_HANDLE_VALUE) { | 2955 if (hFile == INVALID_HANDLE_VALUE) { |
2886 win32_error("utime", apath); | 2956 win32_error("utime", apath); |
2887 » » » PyMem_Free(apath); | 2957 » » » release(oapath); |
2888 return NULL; | 2958 return NULL; |
2889 } | 2959 } |
2890 » » PyMem_Free(apath); | 2960 » » release_bytes(oapath); |
2891 } | 2961 } |
2892 ········ | 2962 ········ |
2893 if (arg == Py_None) { | 2963 if (arg == Py_None) { |
2894 SYSTEMTIME now; | 2964 SYSTEMTIME now; |
2895 GetSystemTime(&now); | 2965 GetSystemTime(&now); |
2896 if (!SystemTimeToFileTime(&now, &mtime) || | 2966 if (!SystemTimeToFileTime(&now, &mtime) || |
2897 !SystemTimeToFileTime(&now, &atime)) { | 2967 !SystemTimeToFileTime(&now, &atime)) { |
2898 win32_error("utime", NULL); | 2968 win32_error("utime", NULL); |
2899 goto done; | 2969 goto done; |
2900 } | 2970 } |
(...skipping 20 matching lines...) Expand all Loading... |
2921 could be the time stamp that gives a problem. */ | 2991 could be the time stamp that gives a problem. */ |
2922 win32_error("utime", NULL); | 2992 win32_error("utime", NULL); |
2923 } | 2993 } |
2924 Py_INCREF(Py_None); | 2994 Py_INCREF(Py_None); |
2925 result = Py_None; | 2995 result = Py_None; |
2926 done: | 2996 done: |
2927 CloseHandle(hFile); | 2997 CloseHandle(hFile); |
2928 return result; | 2998 return result; |
2929 #else /* Py_WIN_WIDE_FILENAMES */ | 2999 #else /* Py_WIN_WIDE_FILENAMES */ |
2930 | 3000 |
2931 » char *path = NULL; | 3001 » PyObject *opath; |
| 3002 » char *path; |
2932 long atime, mtime, ausec, musec; | 3003 long atime, mtime, ausec, musec; |
2933 int res; | 3004 int res; |
2934 PyObject* arg; | 3005 PyObject* arg; |
2935 | 3006 |
2936 #if defined(HAVE_UTIMES) | 3007 #if defined(HAVE_UTIMES) |
2937 struct timeval buf[2]; | 3008 struct timeval buf[2]; |
2938 #define ATIME buf[0].tv_sec | 3009 #define ATIME buf[0].tv_sec |
2939 #define MTIME buf[1].tv_sec | 3010 #define MTIME buf[1].tv_sec |
2940 #elif defined(HAVE_UTIME_H) | 3011 #elif defined(HAVE_UTIME_H) |
2941 /* XXX should define struct utimbuf instead, above */ | 3012 /* XXX should define struct utimbuf instead, above */ |
2942 struct utimbuf buf; | 3013 struct utimbuf buf; |
2943 #define ATIME buf.actime | 3014 #define ATIME buf.actime |
2944 #define MTIME buf.modtime | 3015 #define MTIME buf.modtime |
2945 #define UTIME_ARG &buf | 3016 #define UTIME_ARG &buf |
2946 #else /* HAVE_UTIMES */ | 3017 #else /* HAVE_UTIMES */ |
2947 time_t buf[2]; | 3018 time_t buf[2]; |
2948 #define ATIME buf[0] | 3019 #define ATIME buf[0] |
2949 #define MTIME buf[1] | 3020 #define MTIME buf[1] |
2950 #define UTIME_ARG buf | 3021 #define UTIME_ARG buf |
2951 #endif /* HAVE_UTIMES */ | 3022 #endif /* HAVE_UTIMES */ |
2952 | 3023 |
2953 | 3024 |
2954 » if (!PyArg_ParseTuple(args, "etO:utime", | 3025 » if (!PyArg_ParseTuple(args, "O&O:utime", |
2955 » » » » Py_FileSystemDefaultEncoding, &path, &arg)) | 3026 » » » » PyUnicode_FSConverter, &opath, &arg)) |
2956 return NULL; | 3027 return NULL; |
| 3028 path = bytes2str(opath, 1); |
2957 if (arg == Py_None) { | 3029 if (arg == Py_None) { |
2958 /* optional time values not given */ | 3030 /* optional time values not given */ |
2959 Py_BEGIN_ALLOW_THREADS | 3031 Py_BEGIN_ALLOW_THREADS |
2960 res = utime(path, NULL); | 3032 res = utime(path, NULL); |
2961 Py_END_ALLOW_THREADS | 3033 Py_END_ALLOW_THREADS |
2962 } | 3034 } |
2963 else if (!PyTuple_Check(arg) || PyTuple_Size(arg) != 2) { | 3035 else if (!PyTuple_Check(arg) || PyTuple_Size(arg) != 2) { |
2964 PyErr_SetString(PyExc_TypeError, | 3036 PyErr_SetString(PyExc_TypeError, |
2965 "utime() arg 2 must be a tuple (atime, mtime)"); | 3037 "utime() arg 2 must be a tuple (atime, mtime)"); |
2966 » » PyMem_Free(path); | 3038 » » release_bytes(opath); |
2967 return NULL; | 3039 return NULL; |
2968 } | 3040 } |
2969 else { | 3041 else { |
2970 if (extract_time(PyTuple_GET_ITEM(arg, 0), | 3042 if (extract_time(PyTuple_GET_ITEM(arg, 0), |
2971 &atime, &ausec) == -1) { | 3043 &atime, &ausec) == -1) { |
2972 » » » PyMem_Free(path); | 3044 » » » release_bytes(opath); |
2973 return NULL; | 3045 return NULL; |
2974 } | 3046 } |
2975 if (extract_time(PyTuple_GET_ITEM(arg, 1), | 3047 if (extract_time(PyTuple_GET_ITEM(arg, 1), |
2976 &mtime, &musec) == -1) { | 3048 &mtime, &musec) == -1) { |
2977 » » » PyMem_Free(path); | 3049 » » » release_bytes(opath); |
2978 return NULL; | 3050 return NULL; |
2979 } | 3051 } |
2980 ATIME = atime; | 3052 ATIME = atime; |
2981 MTIME = mtime; | 3053 MTIME = mtime; |
2982 #ifdef HAVE_UTIMES | 3054 #ifdef HAVE_UTIMES |
2983 buf[0].tv_usec = ausec; | 3055 buf[0].tv_usec = ausec; |
2984 buf[1].tv_usec = musec; | 3056 buf[1].tv_usec = musec; |
2985 Py_BEGIN_ALLOW_THREADS | 3057 Py_BEGIN_ALLOW_THREADS |
2986 res = utimes(path, buf); | 3058 res = utimes(path, buf); |
2987 Py_END_ALLOW_THREADS | 3059 Py_END_ALLOW_THREADS |
2988 #else | 3060 #else |
2989 Py_BEGIN_ALLOW_THREADS | 3061 Py_BEGIN_ALLOW_THREADS |
2990 res = utime(path, UTIME_ARG); | 3062 res = utime(path, UTIME_ARG); |
2991 Py_END_ALLOW_THREADS | 3063 Py_END_ALLOW_THREADS |
2992 #endif /* HAVE_UTIMES */ | 3064 #endif /* HAVE_UTIMES */ |
2993 } | 3065 } |
2994 if (res < 0) { | 3066 if (res < 0) { |
2995 » » return posix_error_with_allocated_filename(path); | 3067 » » return posix_error_with_allocated_filename(opath); |
2996 } | 3068 } |
2997 » PyMem_Free(path); | 3069 » release_bytes(opath); |
2998 Py_INCREF(Py_None); | 3070 Py_INCREF(Py_None); |
2999 return Py_None; | 3071 return Py_None; |
3000 #undef UTIME_ARG | 3072 #undef UTIME_ARG |
3001 #undef ATIME | 3073 #undef ATIME |
3002 #undef MTIME | 3074 #undef MTIME |
3003 #endif /* Py_WIN_WIDE_FILENAMES */ | 3075 #endif /* Py_WIN_WIDE_FILENAMES */ |
3004 } | 3076 } |
3005 | 3077 |
3006 | 3078 |
3007 /* Process operations */ | 3079 /* Process operations */ |
(...skipping 14 matching lines...) Expand all Loading... |
3022 | 3094 |
3023 #if defined(HAVE_EXECV) || defined(HAVE_SPAWNV) | 3095 #if defined(HAVE_EXECV) || defined(HAVE_SPAWNV) |
3024 static void | 3096 static void |
3025 free_string_array(char **array, Py_ssize_t count) | 3097 free_string_array(char **array, Py_ssize_t count) |
3026 { | 3098 { |
3027 Py_ssize_t i; | 3099 Py_ssize_t i; |
3028 for (i = 0; i < count; i++) | 3100 for (i = 0; i < count; i++) |
3029 PyMem_Free(array[i]); | 3101 PyMem_Free(array[i]); |
3030 PyMem_DEL(array); | 3102 PyMem_DEL(array); |
3031 } | 3103 } |
| 3104 |
| 3105 int fsconvert_strdup(PyObject *o, char**out) |
| 3106 { |
| 3107 PyObject *bytes; |
| 3108 Py_ssize_t size; |
| 3109 if (!PyUnicode_FSConverter(o, &bytes)) |
| 3110 return 0; |
| 3111 size = PyObject_Size(bytes); |
| 3112 *out = PyMem_Malloc(size+1); |
| 3113 if (!*out) |
| 3114 return 0; |
| 3115 /* Don't lock bytes, as we hold the GIL */ |
| 3116 memcpy(*out, bytes2str(bytes, 0), size+1); |
| 3117 Py_DECREF(bytes); |
| 3118 return 1; |
| 3119 } |
3032 #endif | 3120 #endif |
3033 | 3121 |
3034 | 3122 |
3035 #ifdef HAVE_EXECV | 3123 #ifdef HAVE_EXECV |
3036 PyDoc_STRVAR(posix_execv__doc__, | 3124 PyDoc_STRVAR(posix_execv__doc__, |
3037 "execv(path, args)\n\n\ | 3125 "execv(path, args)\n\n\ |
3038 Execute an executable path with arguments, replacing current process.\n\ | 3126 Execute an executable path with arguments, replacing current process.\n\ |
3039 \n\ | 3127 \n\ |
3040 path: path of executable file\n\ | 3128 path: path of executable file\n\ |
3041 args: tuple or list of strings"); | 3129 args: tuple or list of strings"); |
3042 | 3130 |
3043 static PyObject * | 3131 static PyObject * |
3044 posix_execv(PyObject *self, PyObject *args) | 3132 posix_execv(PyObject *self, PyObject *args) |
3045 { | 3133 { |
| 3134 PyObject *opath; |
3046 char *path; | 3135 char *path; |
3047 PyObject *argv; | 3136 PyObject *argv; |
3048 char **argvlist; | 3137 char **argvlist; |
3049 Py_ssize_t i, argc; | 3138 Py_ssize_t i, argc; |
3050 PyObject *(*getitem)(PyObject *, Py_ssize_t); | 3139 PyObject *(*getitem)(PyObject *, Py_ssize_t); |
3051 | 3140 |
3052 /* execv has two arguments: (path, argv), where | 3141 /* execv has two arguments: (path, argv), where |
3053 argv is a list or tuple of strings. */ | 3142 argv is a list or tuple of strings. */ |
3054 | 3143 |
3055 » if (!PyArg_ParseTuple(args, "etO:execv", | 3144 » if (!PyArg_ParseTuple(args, "O&O:execv", |
3056 Py_FileSystemDefaultEncoding, | 3145 PyUnicode_FSConverter, |
3057 &path, &argv)) | 3146 &opath, &argv)) |
3058 return NULL; | 3147 return NULL; |
| 3148 path = bytes2str(opath, 1); |
3059 if (PyList_Check(argv)) { | 3149 if (PyList_Check(argv)) { |
3060 argc = PyList_Size(argv); | 3150 argc = PyList_Size(argv); |
3061 getitem = PyList_GetItem; | 3151 getitem = PyList_GetItem; |
3062 } | 3152 } |
3063 else if (PyTuple_Check(argv)) { | 3153 else if (PyTuple_Check(argv)) { |
3064 argc = PyTuple_Size(argv); | 3154 argc = PyTuple_Size(argv); |
3065 getitem = PyTuple_GetItem; | 3155 getitem = PyTuple_GetItem; |
3066 } | 3156 } |
3067 else { | 3157 else { |
3068 PyErr_SetString(PyExc_TypeError, "execv() arg 2 must be a tuple
or list"); | 3158 PyErr_SetString(PyExc_TypeError, "execv() arg 2 must be a tuple
or list"); |
3069 PyMem_Free(path); | 3159 release_bytes(opath); |
3070 return NULL; | 3160 return NULL; |
3071 } | 3161 } |
3072 if (argc < 1) { | 3162 if (argc < 1) { |
3073 PyErr_SetString(PyExc_ValueError, "execv() arg 2 must not be emp
ty"); | 3163 PyErr_SetString(PyExc_ValueError, "execv() arg 2 must not be emp
ty"); |
3074 PyMem_Free(path); | 3164 release_bytes(opath); |
3075 return NULL; | 3165 return NULL; |
3076 } | 3166 } |
3077 | 3167 |
3078 argvlist = PyMem_NEW(char *, argc+1); | 3168 argvlist = PyMem_NEW(char *, argc+1); |
3079 if (argvlist == NULL) { | 3169 if (argvlist == NULL) { |
3080 » » PyMem_Free(path); | 3170 » » release_bytes(opath); |
3081 return PyErr_NoMemory(); | 3171 return PyErr_NoMemory(); |
3082 } | 3172 } |
3083 for (i = 0; i < argc; i++) { | 3173 for (i = 0; i < argc; i++) { |
3084 » » if (!PyArg_Parse((*getitem)(argv, i), "et", | 3174 » » if (!fsconvert_strdup((*getitem)(argv, i), |
3085 » » » » Py_FileSystemDefaultEncoding, | 3175 » » » » &argvlist[i])) { |
3086 » » » » &argvlist[i])) { | |
3087 free_string_array(argvlist, i); | 3176 free_string_array(argvlist, i); |
3088 PyErr_SetString(PyExc_TypeError, | 3177 PyErr_SetString(PyExc_TypeError, |
3089 "execv() arg 2 must contain only strings
"); | 3178 "execv() arg 2 must contain only strings
"); |
3090 » » » PyMem_Free(path); | 3179 » » » release_bytes(opath); |
3091 return NULL; | 3180 return NULL; |
3092 | 3181 |
3093 } | 3182 } |
3094 } | 3183 } |
3095 argvlist[argc] = NULL; | 3184 argvlist[argc] = NULL; |
3096 | 3185 |
3097 execv(path, argvlist); | 3186 execv(path, argvlist); |
3098 | 3187 |
3099 /* If we get here it's definitely an error */ | 3188 /* If we get here it's definitely an error */ |
3100 | 3189 |
3101 free_string_array(argvlist, argc); | 3190 free_string_array(argvlist, argc); |
3102 » PyMem_Free(path); | 3191 » release_bytes(opath); |
3103 return posix_error(); | 3192 return posix_error(); |
3104 } | 3193 } |
3105 | 3194 |
3106 | 3195 |
3107 PyDoc_STRVAR(posix_execve__doc__, | 3196 PyDoc_STRVAR(posix_execve__doc__, |
3108 "execve(path, args, env)\n\n\ | 3197 "execve(path, args, env)\n\n\ |
3109 Execute a path with arguments and environment, replacing current process.\n\ | 3198 Execute a path with arguments and environment, replacing current process.\n\ |
3110 \n\ | 3199 \n\ |
3111 path: path of executable file\n\ | 3200 path: path of executable file\n\ |
3112 args: tuple or list of arguments\n\ | 3201 args: tuple or list of arguments\n\ |
3113 env: dictionary of strings mapping to strings"); | 3202 env: dictionary of strings mapping to strings"); |
3114 | 3203 |
3115 static PyObject * | 3204 static PyObject * |
3116 posix_execve(PyObject *self, PyObject *args) | 3205 posix_execve(PyObject *self, PyObject *args) |
3117 { | 3206 { |
| 3207 PyObject *opath; |
3118 char *path; | 3208 char *path; |
3119 PyObject *argv, *env; | 3209 PyObject *argv, *env; |
3120 char **argvlist; | 3210 char **argvlist; |
3121 char **envlist; | 3211 char **envlist; |
3122 PyObject *key, *val, *keys=NULL, *vals=NULL; | 3212 PyObject *key, *val, *keys=NULL, *vals=NULL; |
3123 Py_ssize_t i, pos, argc, envc; | 3213 Py_ssize_t i, pos, argc, envc; |
3124 PyObject *(*getitem)(PyObject *, Py_ssize_t); | 3214 PyObject *(*getitem)(PyObject *, Py_ssize_t); |
3125 Py_ssize_t lastarg = 0; | 3215 Py_ssize_t lastarg = 0; |
3126 | 3216 |
3127 /* execve has three arguments: (path, argv, env), where | 3217 /* execve has three arguments: (path, argv, env), where |
3128 argv is a list or tuple of strings and env is a dictionary | 3218 argv is a list or tuple of strings and env is a dictionary |
3129 like posix.environ. */ | 3219 like posix.environ. */ |
3130 | 3220 |
3131 » if (!PyArg_ParseTuple(args, "etOO:execve", | 3221 » if (!PyArg_ParseTuple(args, "O&OO:execve", |
3132 » » » Py_FileSystemDefaultEncoding, | 3222 » » » PyUnicode_FSConverter, |
3133 » » » &path, &argv, &env)) | 3223 » » » &opath, &argv, &env)) |
3134 return NULL; | 3224 return NULL; |
| 3225 path = bytes2str(opath, 1); |
3135 if (PyList_Check(argv)) { | 3226 if (PyList_Check(argv)) { |
3136 argc = PyList_Size(argv); | 3227 argc = PyList_Size(argv); |
3137 getitem = PyList_GetItem; | 3228 getitem = PyList_GetItem; |
3138 } | 3229 } |
3139 else if (PyTuple_Check(argv)) { | 3230 else if (PyTuple_Check(argv)) { |
3140 argc = PyTuple_Size(argv); | 3231 argc = PyTuple_Size(argv); |
3141 getitem = PyTuple_GetItem; | 3232 getitem = PyTuple_GetItem; |
3142 } | 3233 } |
3143 else { | 3234 else { |
3144 PyErr_SetString(PyExc_TypeError, | 3235 PyErr_SetString(PyExc_TypeError, |
3145 "execve() arg 2 must be a tuple or list"); | 3236 "execve() arg 2 must be a tuple or list"); |
3146 goto fail_0; | 3237 goto fail_0; |
3147 } | 3238 } |
3148 if (!PyMapping_Check(env)) { | 3239 if (!PyMapping_Check(env)) { |
3149 PyErr_SetString(PyExc_TypeError, | 3240 PyErr_SetString(PyExc_TypeError, |
3150 "execve() arg 3 must be a mapping object"); | 3241 "execve() arg 3 must be a mapping object"); |
3151 goto fail_0; | 3242 goto fail_0; |
3152 } | 3243 } |
3153 | 3244 |
3154 argvlist = PyMem_NEW(char *, argc+1); | 3245 argvlist = PyMem_NEW(char *, argc+1); |
3155 if (argvlist == NULL) { | 3246 if (argvlist == NULL) { |
3156 PyErr_NoMemory(); | 3247 PyErr_NoMemory(); |
3157 goto fail_0; | 3248 goto fail_0; |
3158 } | 3249 } |
3159 for (i = 0; i < argc; i++) { | 3250 for (i = 0; i < argc; i++) { |
3160 » » if (!PyArg_Parse((*getitem)(argv, i), | 3251 » » if (!fsconvert_strdup((*getitem)(argv, i), |
3161 » » » » "et;execve() arg 2 must contain only strings", | 3252 » » » » &argvlist[i])) |
3162 » » » » Py_FileSystemDefaultEncoding, | |
3163 » » » » &argvlist[i])) | |
3164 { | 3253 { |
3165 lastarg = i; | 3254 lastarg = i; |
3166 goto fail_1; | 3255 goto fail_1; |
3167 } | 3256 } |
3168 } | 3257 } |
3169 lastarg = argc; | 3258 lastarg = argc; |
3170 argvlist[argc] = NULL; | 3259 argvlist[argc] = NULL; |
3171 | 3260 |
3172 i = PyMapping_Size(env); | 3261 i = PyMapping_Size(env); |
3173 if (i < 0) | 3262 if (i < 0) |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3235 | 3324 |
3236 fail_2: | 3325 fail_2: |
3237 while (--envc >= 0) | 3326 while (--envc >= 0) |
3238 PyMem_DEL(envlist[envc]); | 3327 PyMem_DEL(envlist[envc]); |
3239 PyMem_DEL(envlist); | 3328 PyMem_DEL(envlist); |
3240 fail_1: | 3329 fail_1: |
3241 free_string_array(argvlist, lastarg); | 3330 free_string_array(argvlist, lastarg); |
3242 Py_XDECREF(vals); | 3331 Py_XDECREF(vals); |
3243 Py_XDECREF(keys); | 3332 Py_XDECREF(keys); |
3244 fail_0: | 3333 fail_0: |
3245 » PyMem_Free(path); | 3334 » release_bytes(opath); |
3246 return NULL; | 3335 return NULL; |
3247 } | 3336 } |
3248 #endif /* HAVE_EXECV */ | 3337 #endif /* HAVE_EXECV */ |
3249 | 3338 |
3250 | 3339 |
3251 #ifdef HAVE_SPAWNV | 3340 #ifdef HAVE_SPAWNV |
3252 PyDoc_STRVAR(posix_spawnv__doc__, | 3341 PyDoc_STRVAR(posix_spawnv__doc__, |
3253 "spawnv(mode, path, args)\n\n\ | 3342 "spawnv(mode, path, args)\n\n\ |
3254 Execute the program 'path' in a new process.\n\ | 3343 Execute the program 'path' in a new process.\n\ |
3255 \n\ | 3344 \n\ |
3256 mode: mode of process creation\n\ | 3345 mode: mode of process creation\n\ |
3257 path: path of executable file\n\ | 3346 path: path of executable file\n\ |
3258 args: tuple or list of strings"); | 3347 args: tuple or list of strings"); |
3259 | 3348 |
3260 static PyObject * | 3349 static PyObject * |
3261 posix_spawnv(PyObject *self, PyObject *args) | 3350 posix_spawnv(PyObject *self, PyObject *args) |
3262 { | 3351 { |
| 3352 PyObject *opath; |
3263 char *path; | 3353 char *path; |
3264 PyObject *argv; | 3354 PyObject *argv; |
| 3355 PyObject **oargvlist; |
3265 char **argvlist; | 3356 char **argvlist; |
3266 int mode, i; | 3357 int mode, i; |
3267 Py_ssize_t argc; | 3358 Py_ssize_t argc; |
3268 Py_intptr_t spawnval; | 3359 Py_intptr_t spawnval; |
3269 PyObject *(*getitem)(PyObject *, Py_ssize_t); | 3360 PyObject *(*getitem)(PyObject *, Py_ssize_t); |
3270 | 3361 |
3271 /* spawnv has three arguments: (mode, path, argv), where | 3362 /* spawnv has three arguments: (mode, path, argv), where |
3272 argv is a list or tuple of strings. */ | 3363 argv is a list or tuple of strings. */ |
3273 | 3364 |
3274 » if (!PyArg_ParseTuple(args, "ietO:spawnv", &mode, | 3365 » if (!PyArg_ParseTuple(args, "iO&O:spawnv", &mode, |
3275 » » » Py_FileSystemDefaultEncoding, | 3366 » » » PyUnicode_FSConverter, |
3276 » » » &path, &argv)) | 3367 » » » &opath, &argv)) |
3277 return NULL; | 3368 return NULL; |
| 3369 path = bytes2str(opath); |
3278 if (PyList_Check(argv)) { | 3370 if (PyList_Check(argv)) { |
3279 argc = PyList_Size(argv); | 3371 argc = PyList_Size(argv); |
3280 getitem = PyList_GetItem; | 3372 getitem = PyList_GetItem; |
3281 } | 3373 } |
3282 else if (PyTuple_Check(argv)) { | 3374 else if (PyTuple_Check(argv)) { |
3283 argc = PyTuple_Size(argv); | 3375 argc = PyTuple_Size(argv); |
3284 getitem = PyTuple_GetItem; | 3376 getitem = PyTuple_GetItem; |
3285 } | 3377 } |
3286 else { | 3378 else { |
3287 PyErr_SetString(PyExc_TypeError, | 3379 PyErr_SetString(PyExc_TypeError, |
3288 "spawnv() arg 2 must be a tuple or list"); | 3380 "spawnv() arg 2 must be a tuple or list"); |
3289 » » PyMem_Free(path); | 3381 » » release_bytes(opath); |
3290 return NULL; | 3382 return NULL; |
3291 } | 3383 } |
3292 | 3384 |
3293 argvlist = PyMem_NEW(char *, argc+1); | 3385 argvlist = PyMem_NEW(char *, argc+1); |
3294 if (argvlist == NULL) { | 3386 if (argvlist == NULL) { |
3295 » » PyMem_Free(path); | 3387 » » release_bytes(opath); |
3296 return PyErr_NoMemory(); | 3388 return PyErr_NoMemory(); |
3297 } | 3389 } |
3298 for (i = 0; i < argc; i++) { | 3390 for (i = 0; i < argc; i++) { |
3299 » » if (!PyArg_Parse((*getitem)(argv, i), "et", | 3391 » » if (!fsconvert_strdup((*getitem)(argv, i), |
3300 » » » » Py_FileSystemDefaultEncoding, | 3392 » » » » &oargvlist[i])) { |
3301 » » » » &argvlist[i])) { | |
3302 free_string_array(argvlist, i); | 3393 free_string_array(argvlist, i); |
3303 PyErr_SetString( | 3394 PyErr_SetString( |
3304 PyExc_TypeError, | 3395 PyExc_TypeError, |
3305 "spawnv() arg 2 must contain only strings"); | 3396 "spawnv() arg 2 must contain only strings"); |
3306 » » » PyMem_Free(path); | 3397 » » » release_bytes(opath); |
3307 return NULL; | 3398 return NULL; |
3308 } | 3399 } |
3309 } | 3400 } |
3310 argvlist[argc] = NULL; | 3401 argvlist[argc] = NULL; |
3311 | 3402 |
3312 #if defined(PYOS_OS2) && defined(PYCC_GCC) | 3403 #if defined(PYOS_OS2) && defined(PYCC_GCC) |
3313 Py_BEGIN_ALLOW_THREADS | 3404 Py_BEGIN_ALLOW_THREADS |
3314 spawnval = spawnv(mode, path, argvlist); | 3405 spawnval = spawnv(mode, path, argvlist); |
3315 Py_END_ALLOW_THREADS | 3406 Py_END_ALLOW_THREADS |
3316 #else | 3407 #else |
3317 if (mode == _OLD_P_OVERLAY) | 3408 if (mode == _OLD_P_OVERLAY) |
3318 mode = _P_OVERLAY; | 3409 mode = _P_OVERLAY; |
3319 | 3410 |
3320 Py_BEGIN_ALLOW_THREADS | 3411 Py_BEGIN_ALLOW_THREADS |
3321 spawnval = _spawnv(mode, path, argvlist); | 3412 spawnval = _spawnv(mode, path, argvlist); |
3322 Py_END_ALLOW_THREADS | 3413 Py_END_ALLOW_THREADS |
3323 #endif | 3414 #endif |
3324 | 3415 |
3325 free_string_array(argvlist, argc); | 3416 free_string_array(argvlist, argc); |
3326 » PyMem_Free(path); | 3417 » release_bytes(opath); |
3327 | 3418 |
3328 if (spawnval == -1) | 3419 if (spawnval == -1) |
3329 return posix_error(); | 3420 return posix_error(); |
3330 else | 3421 else |
3331 #if SIZEOF_LONG == SIZEOF_VOID_P | 3422 #if SIZEOF_LONG == SIZEOF_VOID_P |
3332 return Py_BuildValue("l", (long) spawnval); | 3423 return Py_BuildValue("l", (long) spawnval); |
3333 #else | 3424 #else |
3334 return Py_BuildValue("L", (PY_LONG_LONG) spawnval); | 3425 return Py_BuildValue("L", (PY_LONG_LONG) spawnval); |
3335 #endif | 3426 #endif |
3336 } | 3427 } |
3337 | 3428 |
3338 | 3429 |
3339 PyDoc_STRVAR(posix_spawnve__doc__, | 3430 PyDoc_STRVAR(posix_spawnve__doc__, |
3340 "spawnve(mode, path, args, env)\n\n\ | 3431 "spawnve(mode, path, args, env)\n\n\ |
3341 Execute the program 'path' in a new process.\n\ | 3432 Execute the program 'path' in a new process.\n\ |
3342 \n\ | 3433 \n\ |
3343 mode: mode of process creation\n\ | 3434 mode: mode of process creation\n\ |
3344 path: path of executable file\n\ | 3435 path: path of executable file\n\ |
3345 args: tuple or list of arguments\n\ | 3436 args: tuple or list of arguments\n\ |
3346 env: dictionary of strings mapping to strings"); | 3437 env: dictionary of strings mapping to strings"); |
3347 | 3438 |
3348 static PyObject * | 3439 static PyObject * |
3349 posix_spawnve(PyObject *self, PyObject *args) | 3440 posix_spawnve(PyObject *self, PyObject *args) |
3350 { | 3441 { |
| 3442 PyObject *opath; |
3351 char *path; | 3443 char *path; |
3352 PyObject *argv, *env; | 3444 PyObject *argv, *env; |
3353 char **argvlist; | 3445 char **argvlist; |
3354 char **envlist; | 3446 char **envlist; |
3355 PyObject *key, *val, *keys=NULL, *vals=NULL, *res=NULL; | 3447 PyObject *key, *val, *keys=NULL, *vals=NULL, *res=NULL; |
3356 int mode, pos, envc; | 3448 int mode, pos, envc; |
3357 Py_ssize_t argc, i; | 3449 Py_ssize_t argc, i; |
3358 Py_intptr_t spawnval; | 3450 Py_intptr_t spawnval; |
3359 PyObject *(*getitem)(PyObject *, Py_ssize_t); | 3451 PyObject *(*getitem)(PyObject *, Py_ssize_t); |
3360 Py_ssize_t lastarg = 0; | 3452 Py_ssize_t lastarg = 0; |
3361 | 3453 |
3362 /* spawnve has four arguments: (mode, path, argv, env), where | 3454 /* spawnve has four arguments: (mode, path, argv, env), where |
3363 argv is a list or tuple of strings and env is a dictionary | 3455 argv is a list or tuple of strings and env is a dictionary |
3364 like posix.environ. */ | 3456 like posix.environ. */ |
3365 | 3457 |
3366 » if (!PyArg_ParseTuple(args, "ietOO:spawnve", &mode, | 3458 » if (!PyArg_ParseTuple(args, "iO&OO:spawnve", &mode, |
3367 » » » Py_FileSystemDefaultEncoding, | 3459 » » » PyUnicode_FSConverter, |
3368 » » » &path, &argv, &env)) | 3460 » » » &opath, &argv, &env)) |
3369 return NULL; | 3461 return NULL; |
| 3462 path = bytes2str(opath); |
3370 if (PyList_Check(argv)) { | 3463 if (PyList_Check(argv)) { |
3371 argc = PyList_Size(argv); | 3464 argc = PyList_Size(argv); |
3372 getitem = PyList_GetItem; | 3465 getitem = PyList_GetItem; |
3373 } | 3466 } |
3374 else if (PyTuple_Check(argv)) { | 3467 else if (PyTuple_Check(argv)) { |
3375 argc = PyTuple_Size(argv); | 3468 argc = PyTuple_Size(argv); |
3376 getitem = PyTuple_GetItem; | 3469 getitem = PyTuple_GetItem; |
3377 } | 3470 } |
3378 else { | 3471 else { |
3379 PyErr_SetString(PyExc_TypeError, | 3472 PyErr_SetString(PyExc_TypeError, |
3380 "spawnve() arg 2 must be a tuple or list"); | 3473 "spawnve() arg 2 must be a tuple or list"); |
3381 goto fail_0; | 3474 goto fail_0; |
3382 } | 3475 } |
3383 if (!PyMapping_Check(env)) { | 3476 if (!PyMapping_Check(env)) { |
3384 PyErr_SetString(PyExc_TypeError, | 3477 PyErr_SetString(PyExc_TypeError, |
3385 "spawnve() arg 3 must be a mapping object"); | 3478 "spawnve() arg 3 must be a mapping object"); |
3386 goto fail_0; | 3479 goto fail_0; |
3387 } | 3480 } |
3388 | 3481 |
3389 argvlist = PyMem_NEW(char *, argc+1); | 3482 argvlist = PyMem_NEW(char *, argc+1); |
3390 if (argvlist == NULL) { | 3483 if (argvlist == NULL) { |
3391 PyErr_NoMemory(); | 3484 PyErr_NoMemory(); |
3392 goto fail_0; | 3485 goto fail_0; |
3393 } | 3486 } |
3394 for (i = 0; i < argc; i++) { | 3487 for (i = 0; i < argc; i++) { |
3395 » » if (!PyArg_Parse((*getitem)(argv, i), | 3488 » » if (!fsconvert_strdup((*getitem)(argv, i), |
3396 » » » "et;spawnve() arg 2 must contain only strings", | 3489 » » » » &argvlist[i])) |
3397 » » » » Py_FileSystemDefaultEncoding, | |
3398 » » » » &argvlist[i])) | |
3399 { | 3490 { |
3400 lastarg = i; | 3491 lastarg = i; |
3401 goto fail_1; | 3492 goto fail_1; |
3402 } | 3493 } |
3403 } | 3494 } |
3404 lastarg = argc; | 3495 lastarg = argc; |
3405 argvlist[argc] = NULL; | 3496 argvlist[argc] = NULL; |
3406 | 3497 |
3407 i = PyMapping_Size(env); | 3498 i = PyMapping_Size(env); |
3408 if (i < 0) | 3499 if (i < 0) |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3478 | 3569 |
3479 fail_2: | 3570 fail_2: |
3480 while (--envc >= 0) | 3571 while (--envc >= 0) |
3481 PyMem_DEL(envlist[envc]); | 3572 PyMem_DEL(envlist[envc]); |
3482 PyMem_DEL(envlist); | 3573 PyMem_DEL(envlist); |
3483 fail_1: | 3574 fail_1: |
3484 free_string_array(argvlist, lastarg); | 3575 free_string_array(argvlist, lastarg); |
3485 Py_XDECREF(vals); | 3576 Py_XDECREF(vals); |
3486 Py_XDECREF(keys); | 3577 Py_XDECREF(keys); |
3487 fail_0: | 3578 fail_0: |
3488 » PyMem_Free(path); | 3579 » release_bytes(opath); |
3489 return res; | 3580 return res; |
3490 } | 3581 } |
3491 | 3582 |
3492 /* OS/2 supports spawnvp & spawnvpe natively */ | 3583 /* OS/2 supports spawnvp & spawnvpe natively */ |
3493 #if defined(PYOS_OS2) | 3584 #if defined(PYOS_OS2) |
3494 PyDoc_STRVAR(posix_spawnvp__doc__, | 3585 PyDoc_STRVAR(posix_spawnvp__doc__, |
3495 "spawnvp(mode, file, args)\n\n\ | 3586 "spawnvp(mode, file, args)\n\n\ |
3496 Execute the program 'file' in a new process, using the environment\n\ | 3587 Execute the program 'file' in a new process, using the environment\n\ |
3497 search path to find the file.\n\ | 3588 search path to find the file.\n\ |
3498 \n\ | 3589 \n\ |
3499 mode: mode of process creation\n\ | 3590 mode: mode of process creation\n\ |
3500 file: executable file name\n\ | 3591 file: executable file name\n\ |
3501 args: tuple or list of strings"); | 3592 args: tuple or list of strings"); |
3502 | 3593 |
3503 static PyObject * | 3594 static PyObject * |
3504 posix_spawnvp(PyObject *self, PyObject *args) | 3595 posix_spawnvp(PyObject *self, PyObject *args) |
3505 { | 3596 { |
| 3597 PyObject *opath; |
3506 char *path; | 3598 char *path; |
3507 PyObject *argv; | 3599 PyObject *argv; |
3508 char **argvlist; | 3600 char **argvlist; |
3509 int mode, i, argc; | 3601 int mode, i, argc; |
3510 Py_intptr_t spawnval; | 3602 Py_intptr_t spawnval; |
3511 PyObject *(*getitem)(PyObject *, Py_ssize_t); | 3603 PyObject *(*getitem)(PyObject *, Py_ssize_t); |
3512 | 3604 |
3513 /* spawnvp has three arguments: (mode, path, argv), where | 3605 /* spawnvp has three arguments: (mode, path, argv), where |
3514 argv is a list or tuple of strings. */ | 3606 argv is a list or tuple of strings. */ |
3515 | 3607 |
3516 » if (!PyArg_ParseTuple(args, "ietO:spawnvp", &mode, | 3608 » if (!PyArg_ParseTuple(args, "iO&O:spawnvp", &mode, |
3517 » » » Py_FileSystemDefaultEncoding, | 3609 » » » PyUnicode_FSConverter, |
3518 » » » &path, &argv)) | 3610 » » » &opath, &argv)) |
3519 return NULL; | 3611 return NULL; |
| 3612 path = bytes2str(opath); |
3520 if (PyList_Check(argv)) { | 3613 if (PyList_Check(argv)) { |
3521 argc = PyList_Size(argv); | 3614 argc = PyList_Size(argv); |
3522 getitem = PyList_GetItem; | 3615 getitem = PyList_GetItem; |
3523 } | 3616 } |
3524 else if (PyTuple_Check(argv)) { | 3617 else if (PyTuple_Check(argv)) { |
3525 argc = PyTuple_Size(argv); | 3618 argc = PyTuple_Size(argv); |
3526 getitem = PyTuple_GetItem; | 3619 getitem = PyTuple_GetItem; |
3527 } | 3620 } |
3528 else { | 3621 else { |
3529 PyErr_SetString(PyExc_TypeError, | 3622 PyErr_SetString(PyExc_TypeError, |
3530 "spawnvp() arg 2 must be a tuple or list"); | 3623 "spawnvp() arg 2 must be a tuple or list"); |
3531 » » PyMem_Free(path); | 3624 » » release_bytes(opath); |
3532 return NULL; | 3625 return NULL; |
3533 } | 3626 } |
3534 | 3627 |
3535 argvlist = PyMem_NEW(char *, argc+1); | 3628 argvlist = PyMem_NEW(char *, argc+1); |
3536 if (argvlist == NULL) { | 3629 if (argvlist == NULL) { |
3537 » » PyMem_Free(path); | 3630 » » release_bytes(opath); |
3538 return PyErr_NoMemory(); | 3631 return PyErr_NoMemory(); |
3539 } | 3632 } |
3540 for (i = 0; i < argc; i++) { | 3633 for (i = 0; i < argc; i++) { |
3541 » » if (!PyArg_Parse((*getitem)(argv, i), "et", | 3634 » » if (!fsconvert_strdup((*getitem)(argv, i), |
3542 » » » » Py_FileSystemDefaultEncoding, | 3635 » » » » &argvlist[i])) { |
3543 » » » » &argvlist[i])) { | |
3544 free_string_array(argvlist, i); | 3636 free_string_array(argvlist, i); |
3545 PyErr_SetString( | 3637 PyErr_SetString( |
3546 PyExc_TypeError, | 3638 PyExc_TypeError, |
3547 "spawnvp() arg 2 must contain only strings"); | 3639 "spawnvp() arg 2 must contain only strings"); |
3548 » » » PyMem_Free(path); | 3640 » » » release_bytes(opath); |
3549 return NULL; | 3641 return NULL; |
3550 } | 3642 } |
3551 } | 3643 } |
3552 argvlist[argc] = NULL; | 3644 argvlist[argc] = NULL; |
3553 | 3645 |
3554 Py_BEGIN_ALLOW_THREADS | 3646 Py_BEGIN_ALLOW_THREADS |
3555 #if defined(PYCC_GCC) | 3647 #if defined(PYCC_GCC) |
3556 spawnval = spawnvp(mode, path, argvlist); | 3648 spawnval = spawnvp(mode, path, argvlist); |
3557 #else | 3649 #else |
3558 spawnval = _spawnvp(mode, path, argvlist); | 3650 spawnval = _spawnvp(mode, path, argvlist); |
3559 #endif | 3651 #endif |
3560 Py_END_ALLOW_THREADS | 3652 Py_END_ALLOW_THREADS |
3561 | 3653 |
3562 free_string_array(argvlist, argc); | 3654 free_string_array(argvlist, argc); |
3563 » PyMem_Free(path); | 3655 » release_bytes(opath); |
3564 | 3656 |
3565 if (spawnval == -1) | 3657 if (spawnval == -1) |
3566 return posix_error(); | 3658 return posix_error(); |
3567 else | 3659 else |
3568 return Py_BuildValue("l", (long) spawnval); | 3660 return Py_BuildValue("l", (long) spawnval); |
3569 } | 3661 } |
3570 | 3662 |
3571 | 3663 |
3572 PyDoc_STRVAR(posix_spawnvpe__doc__, | 3664 PyDoc_STRVAR(posix_spawnvpe__doc__, |
3573 "spawnvpe(mode, file, args, env)\n\n\ | 3665 "spawnvpe(mode, file, args, env)\n\n\ |
3574 Execute the program 'file' in a new process, using the environment\n\ | 3666 Execute the program 'file' in a new process, using the environment\n\ |
3575 search path to find the file.\n\ | 3667 search path to find the file.\n\ |
3576 \n\ | 3668 \n\ |
3577 mode: mode of process creation\n\ | 3669 mode: mode of process creation\n\ |
3578 file: executable file name\n\ | 3670 file: executable file name\n\ |
3579 args: tuple or list of arguments\n\ | 3671 args: tuple or list of arguments\n\ |
3580 env: dictionary of strings mapping to strings"); | 3672 env: dictionary of strings mapping to strings"); |
3581 | 3673 |
3582 static PyObject * | 3674 static PyObject * |
3583 posix_spawnvpe(PyObject *self, PyObject *args) | 3675 posix_spawnvpe(PyObject *self, PyObject *args) |
3584 { | 3676 { |
| 3677 PyObject *opath |
3585 char *path; | 3678 char *path; |
3586 PyObject *argv, *env; | 3679 PyObject *argv, *env; |
3587 char **argvlist; | 3680 char **argvlist; |
3588 char **envlist; | 3681 char **envlist; |
3589 PyObject *key, *val, *keys=NULL, *vals=NULL, *res=NULL; | 3682 PyObject *key, *val, *keys=NULL, *vals=NULL, *res=NULL; |
3590 int mode, i, pos, argc, envc; | 3683 int mode, i, pos, argc, envc; |
3591 Py_intptr_t spawnval; | 3684 Py_intptr_t spawnval; |
3592 PyObject *(*getitem)(PyObject *, Py_ssize_t); | 3685 PyObject *(*getitem)(PyObject *, Py_ssize_t); |
3593 int lastarg = 0; | 3686 int lastarg = 0; |
3594 | 3687 |
3595 /* spawnvpe has four arguments: (mode, path, argv, env), where | 3688 /* spawnvpe has four arguments: (mode, path, argv, env), where |
3596 argv is a list or tuple of strings and env is a dictionary | 3689 argv is a list or tuple of strings and env is a dictionary |
3597 like posix.environ. */ | 3690 like posix.environ. */ |
3598 | 3691 |
3599 if (!PyArg_ParseTuple(args, "ietOO:spawnvpe", &mode, | 3692 if (!PyArg_ParseTuple(args, "ietOO:spawnvpe", &mode, |
3600 » » » Py_FileSystemDefaultEncoding, | 3693 » » » PyUnicode_FSConverter, |
3601 » » » &path, &argv, &env)) | 3694 » » » &opath, &argv, &env)) |
3602 return NULL; | 3695 return NULL; |
| 3696 path = bytes2str(opath); |
3603 if (PyList_Check(argv)) { | 3697 if (PyList_Check(argv)) { |
3604 argc = PyList_Size(argv); | 3698 argc = PyList_Size(argv); |
3605 getitem = PyList_GetItem; | 3699 getitem = PyList_GetItem; |
3606 } | 3700 } |
3607 else if (PyTuple_Check(argv)) { | 3701 else if (PyTuple_Check(argv)) { |
3608 argc = PyTuple_Size(argv); | 3702 argc = PyTuple_Size(argv); |
3609 getitem = PyTuple_GetItem; | 3703 getitem = PyTuple_GetItem; |
3610 } | 3704 } |
3611 else { | 3705 else { |
3612 PyErr_SetString(PyExc_TypeError, | 3706 PyErr_SetString(PyExc_TypeError, |
3613 "spawnvpe() arg 2 must be a tuple or list"); | 3707 "spawnvpe() arg 2 must be a tuple or list"); |
3614 goto fail_0; | 3708 goto fail_0; |
3615 } | 3709 } |
3616 if (!PyMapping_Check(env)) { | 3710 if (!PyMapping_Check(env)) { |
3617 PyErr_SetString(PyExc_TypeError, | 3711 PyErr_SetString(PyExc_TypeError, |
3618 "spawnvpe() arg 3 must be a mapping object"); | 3712 "spawnvpe() arg 3 must be a mapping object"); |
3619 goto fail_0; | 3713 goto fail_0; |
3620 } | 3714 } |
3621 | 3715 |
3622 argvlist = PyMem_NEW(char *, argc+1); | 3716 argvlist = PyMem_NEW(char *, argc+1); |
3623 if (argvlist == NULL) { | 3717 if (argvlist == NULL) { |
3624 PyErr_NoMemory(); | 3718 PyErr_NoMemory(); |
3625 goto fail_0; | 3719 goto fail_0; |
3626 } | 3720 } |
3627 for (i = 0; i < argc; i++) { | 3721 for (i = 0; i < argc; i++) { |
3628 » » if (!PyArg_Parse((*getitem)(argv, i), | 3722 » » if (!fsconvert_strdup((*getitem)(argv, i), |
3629 » » » "et;spawnvpe() arg 2 must contain only strings", | 3723 » » » » &argvlist[i])) |
3630 » » » » Py_FileSystemDefaultEncoding, | |
3631 » » » » &argvlist[i])) | |
3632 { | 3724 { |
3633 lastarg = i; | 3725 lastarg = i; |
3634 goto fail_1; | 3726 goto fail_1; |
3635 } | 3727 } |
3636 } | 3728 } |
3637 lastarg = argc; | 3729 lastarg = argc; |
3638 argvlist[argc] = NULL; | 3730 argvlist[argc] = NULL; |
3639 | 3731 |
3640 i = PyMapping_Size(env); | 3732 i = PyMapping_Size(env); |
3641 if (i < 0) | 3733 if (i < 0) |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3702 | 3794 |
3703 fail_2: | 3795 fail_2: |
3704 while (--envc >= 0) | 3796 while (--envc >= 0) |
3705 PyMem_DEL(envlist[envc]); | 3797 PyMem_DEL(envlist[envc]); |
3706 PyMem_DEL(envlist); | 3798 PyMem_DEL(envlist); |
3707 fail_1: | 3799 fail_1: |
3708 free_string_array(argvlist, lastarg); | 3800 free_string_array(argvlist, lastarg); |
3709 Py_XDECREF(vals); | 3801 Py_XDECREF(vals); |
3710 Py_XDECREF(keys); | 3802 Py_XDECREF(keys); |
3711 fail_0: | 3803 fail_0: |
3712 » PyMem_Free(path); | 3804 » release_bytes(opath); |
3713 return res; | 3805 return res; |
3714 } | 3806 } |
3715 #endif /* PYOS_OS2 */ | 3807 #endif /* PYOS_OS2 */ |
3716 #endif /* HAVE_SPAWNV */ | 3808 #endif /* HAVE_SPAWNV */ |
3717 | 3809 |
3718 | 3810 |
3719 #ifdef HAVE_FORK1 | 3811 #ifdef HAVE_FORK1 |
3720 PyDoc_STRVAR(posix_fork1__doc__, | 3812 PyDoc_STRVAR(posix_fork1__doc__, |
3721 "fork1() -> pid\n\n\ | 3813 "fork1() -> pid\n\n\ |
3722 Fork a child process with a single multiplexed (i.e., not bound) thread.\n\ | 3814 Fork a child process with a single multiplexed (i.e., not bound) thread.\n\ |
(...skipping 818 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4541 | 4633 |
4542 | 4634 |
4543 PyDoc_STRVAR(posix_lstat__doc__, | 4635 PyDoc_STRVAR(posix_lstat__doc__, |
4544 "lstat(path) -> stat result\n\n\ | 4636 "lstat(path) -> stat result\n\n\ |
4545 Like stat(path), but do not follow symbolic links."); | 4637 Like stat(path), but do not follow symbolic links."); |
4546 | 4638 |
4547 static PyObject * | 4639 static PyObject * |
4548 posix_lstat(PyObject *self, PyObject *args) | 4640 posix_lstat(PyObject *self, PyObject *args) |
4549 { | 4641 { |
4550 #ifdef HAVE_LSTAT | 4642 #ifdef HAVE_LSTAT |
4551 » return posix_do_stat(self, args, "et:lstat", lstat, NULL, NULL); | 4643 » return posix_do_stat(self, args, "O&:lstat", lstat, NULL, NULL); |
4552 #else /* !HAVE_LSTAT */ | 4644 #else /* !HAVE_LSTAT */ |
4553 #ifdef MS_WINDOWS | 4645 #ifdef MS_WINDOWS |
4554 » return posix_do_stat(self, args, "et:lstat", STAT, "U:lstat", win32_wsta
t); | 4646 » return posix_do_stat(self, args, "O&:lstat", STAT, "U:lstat", win32_wsta
t); |
4555 #else | 4647 #else |
4556 » return posix_do_stat(self, args, "et:lstat", STAT, NULL, NULL); | 4648 » return posix_do_stat(self, args, "O&:lstat", STAT, NULL, NULL); |
4557 #endif | 4649 #endif |
4558 #endif /* !HAVE_LSTAT */ | 4650 #endif /* !HAVE_LSTAT */ |
4559 } | 4651 } |
4560 | 4652 |
4561 | 4653 |
4562 #ifdef HAVE_READLINK | 4654 #ifdef HAVE_READLINK |
4563 PyDoc_STRVAR(posix_readlink__doc__, | 4655 PyDoc_STRVAR(posix_readlink__doc__, |
4564 "readlink(path) -> path\n\n\ | 4656 "readlink(path) -> path\n\n\ |
4565 Return a string representing the path to which the symbolic link points."); | 4657 Return a string representing the path to which the symbolic link points."); |
4566 | 4658 |
4567 static PyObject * | 4659 static PyObject * |
4568 posix_readlink(PyObject *self, PyObject *args) | 4660 posix_readlink(PyObject *self, PyObject *args) |
4569 { | 4661 { |
4570 PyObject* v; | 4662 PyObject* v; |
4571 char buf[MAXPATHLEN]; | 4663 char buf[MAXPATHLEN]; |
| 4664 PyObject *opath; |
4572 char *path; | 4665 char *path; |
4573 int n; | 4666 int n; |
4574 int arg_is_unicode = 0; | 4667 int arg_is_unicode = 0; |
4575 | 4668 |
4576 » if (!PyArg_ParseTuple(args, "et:readlink",· | 4669 » if (!PyArg_ParseTuple(args, "O&:readlink",· |
4577 » » » » Py_FileSystemDefaultEncoding, &path)) | 4670 » » » » PyUnicode_FSConverter, &opath)) |
4578 return NULL; | 4671 return NULL; |
| 4672 path = bytes2str(opath, 1); |
4579 v = PySequence_GetItem(args, 0); | 4673 v = PySequence_GetItem(args, 0); |
4580 if (v == NULL) { | 4674 if (v == NULL) { |
4581 » » PyMem_Free(path); | 4675 » » release_bytes(opath); |
4582 return NULL; | 4676 return NULL; |
4583 } | 4677 } |
4584 | 4678 |
4585 if (PyUnicode_Check(v)) { | 4679 if (PyUnicode_Check(v)) { |
4586 arg_is_unicode = 1; | 4680 arg_is_unicode = 1; |
4587 } | 4681 } |
4588 Py_DECREF(v); | 4682 Py_DECREF(v); |
4589 | 4683 |
4590 Py_BEGIN_ALLOW_THREADS | 4684 Py_BEGIN_ALLOW_THREADS |
4591 n = readlink(path, buf, (int) sizeof buf); | 4685 n = readlink(path, buf, (int) sizeof buf); |
4592 Py_END_ALLOW_THREADS | 4686 Py_END_ALLOW_THREADS |
4593 if (n < 0) | 4687 if (n < 0) |
4594 » » return posix_error_with_allocated_filename(path); | 4688 » » return posix_error_with_allocated_filename(opath); |
4595 | 4689 |
4596 » PyMem_Free(path); | 4690 » release_bytes(opath); |
4597 v = PyBytes_FromStringAndSize(buf, n); | 4691 v = PyBytes_FromStringAndSize(buf, n); |
4598 if (arg_is_unicode) { | 4692 if (arg_is_unicode) { |
4599 PyObject *w; | 4693 PyObject *w; |
4600 | 4694 |
4601 w = PyUnicode_FromEncodedObject(v, | 4695 w = PyUnicode_FromEncodedObject(v, |
4602 Py_FileSystemDefaultEncoding, | 4696 Py_FileSystemDefaultEncoding, |
4603 » » » » "strict"); | 4697 » » » » "utf8b"); |
4604 if (w != NULL) { | 4698 if (w != NULL) { |
4605 Py_DECREF(v); | 4699 Py_DECREF(v); |
4606 v = w; | 4700 v = w; |
4607 } | 4701 } |
4608 else { | 4702 else { |
4609 v = NULL; | 4703 v = NULL; |
4610 } | 4704 } |
4611 } | 4705 } |
4612 return v; | 4706 return v; |
4613 } | 4707 } |
4614 #endif /* HAVE_READLINK */ | 4708 #endif /* HAVE_READLINK */ |
4615 | 4709 |
4616 | 4710 |
4617 #ifdef HAVE_SYMLINK | 4711 #ifdef HAVE_SYMLINK |
4618 PyDoc_STRVAR(posix_symlink__doc__, | 4712 PyDoc_STRVAR(posix_symlink__doc__, |
4619 "symlink(src, dst)\n\n\ | 4713 "symlink(src, dst)\n\n\ |
4620 Create a symbolic link pointing to src named dst."); | 4714 Create a symbolic link pointing to src named dst."); |
4621 | 4715 |
4622 static PyObject * | 4716 static PyObject * |
4623 posix_symlink(PyObject *self, PyObject *args) | 4717 posix_symlink(PyObject *self, PyObject *args) |
4624 { | 4718 { |
4625 » return posix_2str(args, "etet:symlink", symlink); | 4719 » return posix_2str(args, "O&O&:symlink", symlink); |
4626 } | 4720 } |
4627 #endif /* HAVE_SYMLINK */ | 4721 #endif /* HAVE_SYMLINK */ |
4628 | 4722 |
4629 | 4723 |
4630 #ifdef HAVE_TIMES | 4724 #ifdef HAVE_TIMES |
4631 #if defined(PYCC_VACPP) && defined(PYOS_OS2) | 4725 #if defined(PYCC_VACPP) && defined(PYOS_OS2) |
4632 static long | 4726 static long |
4633 system_uptime(void) | 4727 system_uptime(void) |
4634 { | 4728 { |
4635 ULONG value = 0; | 4729 ULONG value = 0; |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4803 | 4897 |
4804 /* Functions acting on file descriptors */ | 4898 /* Functions acting on file descriptors */ |
4805 | 4899 |
4806 PyDoc_STRVAR(posix_open__doc__, | 4900 PyDoc_STRVAR(posix_open__doc__, |
4807 "open(filename, flag [, mode=0777]) -> fd\n\n\ | 4901 "open(filename, flag [, mode=0777]) -> fd\n\n\ |
4808 Open a file (for low level IO)."); | 4902 Open a file (for low level IO)."); |
4809 | 4903 |
4810 static PyObject * | 4904 static PyObject * |
4811 posix_open(PyObject *self, PyObject *args) | 4905 posix_open(PyObject *self, PyObject *args) |
4812 { | 4906 { |
4813 » char *file = NULL; | 4907 » PyObject *ofile; |
| 4908 » char *file; |
4814 int flag; | 4909 int flag; |
4815 int mode = 0777; | 4910 int mode = 0777; |
4816 int fd; | 4911 int fd; |
4817 | 4912 |
4818 #ifdef MS_WINDOWS | 4913 #ifdef MS_WINDOWS |
4819 if (unicode_file_names()) { | 4914 if (unicode_file_names()) { |
4820 PyUnicodeObject *po; | 4915 PyUnicodeObject *po; |
4821 if (PyArg_ParseTuple(args, "Ui|i:mkdir", &po, &flag, &mode)) { | 4916 if (PyArg_ParseTuple(args, "Ui|i:mkdir", &po, &flag, &mode)) { |
4822 Py_BEGIN_ALLOW_THREADS | 4917 Py_BEGIN_ALLOW_THREADS |
4823 /* PyUnicode_AS_UNICODE OK without thread | 4918 /* PyUnicode_AS_UNICODE OK without thread |
4824 lock as it is a simple dereference. */ | 4919 lock as it is a simple dereference. */ |
4825 fd = _wopen(PyUnicode_AS_UNICODE(po), flag, mode); | 4920 fd = _wopen(PyUnicode_AS_UNICODE(po), flag, mode); |
4826 Py_END_ALLOW_THREADS | 4921 Py_END_ALLOW_THREADS |
4827 if (fd < 0) | 4922 if (fd < 0) |
4828 return posix_error(); | 4923 return posix_error(); |
4829 return PyLong_FromLong((long)fd); | 4924 return PyLong_FromLong((long)fd); |
4830 } | 4925 } |
4831 /* Drop the argument parsing error as narrow strings | 4926 /* Drop the argument parsing error as narrow strings |
4832 are also valid. */ | 4927 are also valid. */ |
4833 PyErr_Clear(); | 4928 PyErr_Clear(); |
4834 } | 4929 } |
4835 #endif | 4930 #endif |
4836 | 4931 |
4837 » if (!PyArg_ParseTuple(args, "eti|i", | 4932 » if (!PyArg_ParseTuple(args, "O&i|i", |
4838 » Py_FileSystemDefaultEncoding, &file, | 4933 » PyUnicode_FSConverter, &ofile, |
4839 &flag, &mode)) | 4934 &flag, &mode)) |
4840 return NULL; | 4935 return NULL; |
4841 | 4936 » file = bytes2str(ofile, 1); |
4842 Py_BEGIN_ALLOW_THREADS | 4937 Py_BEGIN_ALLOW_THREADS |
4843 fd = open(file, flag, mode); | 4938 fd = open(file, flag, mode); |
4844 Py_END_ALLOW_THREADS | 4939 Py_END_ALLOW_THREADS |
4845 if (fd < 0) | 4940 if (fd < 0) |
4846 » » return posix_error_with_allocated_filename(file); | 4941 » » return posix_error_with_allocated_filename(ofile); |
4847 » PyMem_Free(file); | 4942 » release_bytes(ofile); |
4848 return PyLong_FromLong((long)fd); | 4943 return PyLong_FromLong((long)fd); |
4849 } | 4944 } |
4850 | 4945 |
4851 | 4946 |
4852 PyDoc_STRVAR(posix_close__doc__, | 4947 PyDoc_STRVAR(posix_close__doc__, |
4853 "close(fd)\n\n\ | 4948 "close(fd)\n\n\ |
4854 Close a file descriptor (for low level IO)."); | 4949 Close a file descriptor (for low level IO)."); |
4855 | 4950 |
4856 static PyObject * | 4951 static PyObject * |
4857 posix_close(PyObject *self, PyObject *args) | 4952 posix_close(PyObject *self, PyObject *args) |
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5281 * get re-set with another call for the same key. */ | 5376 * get re-set with another call for the same key. */ |
5282 static PyObject *posix_putenv_garbage; | 5377 static PyObject *posix_putenv_garbage; |
5283 | 5378 |
5284 static PyObject * | 5379 static PyObject * |
5285 posix_putenv(PyObject *self, PyObject *args) | 5380 posix_putenv(PyObject *self, PyObject *args) |
5286 { | 5381 { |
5287 #ifdef MS_WINDOWS | 5382 #ifdef MS_WINDOWS |
5288 wchar_t *s1, *s2; | 5383 wchar_t *s1, *s2; |
5289 wchar_t *newenv; | 5384 wchar_t *newenv; |
5290 #else | 5385 #else |
| 5386 PyObject *os1, *os2; |
5291 char *s1, *s2; | 5387 char *s1, *s2; |
5292 char *newenv; | 5388 char *newenv; |
5293 #endif | 5389 #endif |
5294 PyObject *newstr; | 5390 PyObject *newstr; |
5295 size_t len; | 5391 size_t len; |
5296 | 5392 |
| 5393 #ifdef MS_WINDOWS |
5297 if (!PyArg_ParseTuple(args, | 5394 if (!PyArg_ParseTuple(args, |
5298 #ifdef MS_WINDOWS | |
5299 "uu:putenv", | 5395 "uu:putenv", |
5300 #else | |
5301 "ss:putenv", | |
5302 #endif | |
5303 &s1, &s2)) | 5396 &s1, &s2)) |
5304 return NULL; | 5397 return NULL; |
| 5398 #else |
| 5399 if (!PyArg_ParseTuple(args, |
| 5400 "O&O&:putenv", |
| 5401 PyUnicode_FSConverter, &os1,· |
| 5402 PyUnicode_FSConverter, &os2)) |
| 5403 return NULL; |
| 5404 s1 = bytes2str(os1, 1); |
| 5405 s2 = bytes2str(os2, 1); |
| 5406 #endif |
5305 | 5407 |
5306 #if defined(PYOS_OS2) | 5408 #if defined(PYOS_OS2) |
5307 if (stricmp(s1, "BEGINLIBPATH") == 0) { | 5409 if (stricmp(s1, "BEGINLIBPATH") == 0) { |
5308 APIRET rc; | 5410 APIRET rc; |
5309 | 5411 |
5310 rc = DosSetExtLIBPATH(s2, BEGIN_LIBPATH); | 5412 rc = DosSetExtLIBPATH(s2, BEGIN_LIBPATH); |
5311 if (rc != NO_ERROR) | 5413 if (rc != NO_ERROR) |
5312 return os2_error(rc); | 5414 return os2_error(rc); |
5313 | 5415 |
5314 } else if (stricmp(s1, "ENDLIBPATH") == 0) { | 5416 } else if (stricmp(s1, "ENDLIBPATH") == 0) { |
(...skipping 22 matching lines...) Expand all Loading... |
5337 if (_wputenv(newenv)) { | 5439 if (_wputenv(newenv)) { |
5338 Py_DECREF(newstr); | 5440 Py_DECREF(newstr); |
5339 posix_error(); | 5441 posix_error(); |
5340 return NULL; | 5442 return NULL; |
5341 } | 5443 } |
5342 #else | 5444 #else |
5343 newenv = PyBytes_AS_STRING(newstr); | 5445 newenv = PyBytes_AS_STRING(newstr); |
5344 PyOS_snprintf(newenv, len, "%s=%s", s1, s2); | 5446 PyOS_snprintf(newenv, len, "%s=%s", s1, s2); |
5345 if (putenv(newenv)) { | 5447 if (putenv(newenv)) { |
5346 Py_DECREF(newstr); | 5448 Py_DECREF(newstr); |
| 5449 release_bytes(os1); |
| 5450 release_bytes(os2); |
5347 posix_error(); | 5451 posix_error(); |
5348 return NULL; | 5452 return NULL; |
5349 } | 5453 } |
5350 #endif | 5454 #endif |
5351 /* Install the first arg and newstr in posix_putenv_garbage; | 5455 /* Install the first arg and newstr in posix_putenv_garbage; |
5352 * this will cause previous value to be collected. This has to | 5456 * this will cause previous value to be collected. This has to |
5353 * happen after the real putenv() call because the old value | 5457 * happen after the real putenv() call because the old value |
5354 * was still accessible until then. */ | 5458 * was still accessible until then. */ |
5355 if (PyDict_SetItem(posix_putenv_garbage, | 5459 if (PyDict_SetItem(posix_putenv_garbage, |
5356 PyTuple_GET_ITEM(args, 0), newstr)) { | 5460 PyTuple_GET_ITEM(args, 0), newstr)) { |
5357 /* really not much we can do; just leak */ | 5461 /* really not much we can do; just leak */ |
5358 PyErr_Clear(); | 5462 PyErr_Clear(); |
5359 } | 5463 } |
5360 else { | 5464 else { |
5361 Py_DECREF(newstr); | 5465 Py_DECREF(newstr); |
5362 } | 5466 } |
5363 | 5467 |
5364 #if defined(PYOS_OS2) | 5468 #if defined(PYOS_OS2) |
5365 } | 5469 } |
5366 #endif | 5470 #endif |
| 5471 #ifndef MS_WINDOWS |
| 5472 release_bytes(os1); |
| 5473 release_bytes(os2); |
| 5474 #endif |
5367 Py_INCREF(Py_None); | 5475 Py_INCREF(Py_None); |
5368 return Py_None; | 5476 return Py_None; |
5369 } | 5477 } |
5370 #endif /* putenv */ | 5478 #endif /* putenv */ |
5371 | 5479 |
5372 #ifdef HAVE_UNSETENV | 5480 #ifdef HAVE_UNSETENV |
5373 PyDoc_STRVAR(posix_unsetenv__doc__, | 5481 PyDoc_STRVAR(posix_unsetenv__doc__, |
5374 "unsetenv(key)\n\n\ | 5482 "unsetenv(key)\n\n\ |
5375 Delete an environment variable."); | 5483 Delete an environment variable."); |
5376 | 5484 |
(...skipping 1344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6721 PyObject *errval = win32_error_unicode("startfile", | 6829 PyObject *errval = win32_error_unicode("startfile", |
6722 PyUnicode_AS_UNICODE(unipath)); | 6830 PyUnicode_AS_UNICODE(unipath)); |
6723 return errval; | 6831 return errval; |
6724 } | 6832 } |
6725 Py_INCREF(Py_None); | 6833 Py_INCREF(Py_None); |
6726 return Py_None; | 6834 return Py_None; |
6727 } | 6835 } |
6728 #endif | 6836 #endif |
6729 | 6837 |
6730 normal: | 6838 normal: |
6731 » if (!PyArg_ParseTuple(args, "et|s:startfile",· | 6839 » if (!PyArg_ParseTuple(args, "O&|s:startfile",· |
6732 » » » Py_FileSystemDefaultEncoding, &filepath,· | 6840 » » » PyUnicode_FSConverter, &ofilepath,· |
6733 &operation)) | 6841 &operation)) |
6734 return NULL; | 6842 return NULL; |
| 6843 filepath = bytes2str(ofilepath); |
6735 Py_BEGIN_ALLOW_THREADS | 6844 Py_BEGIN_ALLOW_THREADS |
6736 rc = ShellExecute((HWND)0, operation, filepath,· | 6845 rc = ShellExecute((HWND)0, operation, filepath,· |
6737 NULL, NULL, SW_SHOWNORMAL); | 6846 NULL, NULL, SW_SHOWNORMAL); |
6738 Py_END_ALLOW_THREADS | 6847 Py_END_ALLOW_THREADS |
6739 if (rc <= (HINSTANCE)32) { | 6848 if (rc <= (HINSTANCE)32) { |
6740 PyObject *errval = win32_error("startfile", filepath); | 6849 PyObject *errval = win32_error("startfile", filepath); |
6741 » » PyMem_Free(filepath); | 6850 » » release_bytes(ofilepath); |
6742 return errval; | 6851 return errval; |
6743 } | 6852 } |
6744 » PyMem_Free(filepath); | 6853 » release_bytes(ofilepath); |
6745 Py_INCREF(Py_None); | 6854 Py_INCREF(Py_None); |
6746 return Py_None; | 6855 return Py_None; |
6747 } | 6856 } |
6748 #endif | 6857 #endif |
6749 | 6858 |
6750 #ifdef HAVE_GETLOADAVG | 6859 #ifdef HAVE_GETLOADAVG |
6751 PyDoc_STRVAR(posix_getloadavg__doc__, | 6860 PyDoc_STRVAR(posix_getloadavg__doc__, |
6752 "getloadavg() -> (float, float, float)\n\n\ | 6861 "getloadavg() -> (float, float, float)\n\n\ |
6753 Return the number of processes in the system run queue averaged over\n\ | 6862 Return the number of processes in the system run queue averaged over\n\ |
6754 the last 1, 5, and 15 minutes or raises OSError if the load average\n\ | 6863 the last 1, 5, and 15 minutes or raises OSError if the load average\n\ |
(...skipping 855 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7610 | 7719 |
7611 | 7720 |
7612 #endif /* __APPLE__ */ | 7721 #endif /* __APPLE__ */ |
7613 return m; | 7722 return m; |
7614 | 7723 |
7615 } | 7724 } |
7616 | 7725 |
7617 #ifdef __cplusplus | 7726 #ifdef __cplusplus |
7618 } | 7727 } |
7619 #endif | 7728 #endif |
OLD | NEW |