Mercurial > cpython-lru_cache-weakref
comparison Python/sysmodule.c @ 65162:39014f0abc32
Create fileutils.c/.h
* _Py_fopen() and _Py_stat() come from Python/import.c
* (_Py)_wrealpath() comes from Python/sysmodule.c
* _Py_char2wchar(), _Py_wchar2char() and _Py_wfopen() come from Modules/main.c
* (_Py)_wstat(), (_Py)_wgetcwd(), _Py_wreadlink() come from Modules/getpath.c
| author | Victor Stinner <victor.stinner@haypocalc.com> |
|---|---|
| date | Thu, 07 Oct 2010 21:45:39 +0000 |
| parents | 071f1f7af522 |
| children | 8fd5d06462e6 |
comparison
equal
deleted
inserted
replaced
| 65161:071f1f7af522 | 65162:39014f0abc32 |
|---|---|
| 1655 } | 1655 } |
| 1656 } | 1656 } |
| 1657 return av; | 1657 return av; |
| 1658 } | 1658 } |
| 1659 | 1659 |
| 1660 #ifdef HAVE_REALPATH | |
| 1661 static wchar_t* | |
| 1662 _wrealpath(const wchar_t *path, wchar_t *resolved_path) | |
| 1663 { | |
| 1664 char *cpath; | |
| 1665 char cresolved_path[PATH_MAX]; | |
| 1666 char *res; | |
| 1667 size_t r; | |
| 1668 cpath = _Py_wchar2char(path); | |
| 1669 if (cpath == NULL) { | |
| 1670 errno = EINVAL; | |
| 1671 return NULL; | |
| 1672 } | |
| 1673 res = realpath(cpath, cresolved_path); | |
| 1674 PyMem_Free(cpath); | |
| 1675 if (res == NULL) | |
| 1676 return NULL; | |
| 1677 r = mbstowcs(resolved_path, cresolved_path, PATH_MAX); | |
| 1678 if (r == (size_t)-1 || r >= PATH_MAX) { | |
| 1679 errno = EINVAL; | |
| 1680 return NULL; | |
| 1681 } | |
| 1682 return resolved_path; | |
| 1683 } | |
| 1684 #endif | |
| 1685 | |
| 1686 #define _HAVE_SCRIPT_ARGUMENT(argc, argv) \ | 1660 #define _HAVE_SCRIPT_ARGUMENT(argc, argv) \ |
| 1687 (argc > 0 && argv0 != NULL && \ | 1661 (argc > 0 && argv0 != NULL && \ |
| 1688 wcscmp(argv0, L"-c") != 0 && wcscmp(argv0, L"-m") != 0) | 1662 wcscmp(argv0, L"-c") != 0 && wcscmp(argv0, L"-m") != 0) |
| 1689 | 1663 |
| 1690 static void | 1664 static void |
| 1694 wchar_t *p = NULL; | 1668 wchar_t *p = NULL; |
| 1695 Py_ssize_t n = 0; | 1669 Py_ssize_t n = 0; |
| 1696 PyObject *a; | 1670 PyObject *a; |
| 1697 PyObject *path; | 1671 PyObject *path; |
| 1698 #ifdef HAVE_READLINK | 1672 #ifdef HAVE_READLINK |
| 1699 extern int _Py_wreadlink(const wchar_t *, wchar_t *, size_t); | |
| 1700 wchar_t link[MAXPATHLEN+1]; | 1673 wchar_t link[MAXPATHLEN+1]; |
| 1701 wchar_t argv0copy[2*MAXPATHLEN+1]; | 1674 wchar_t argv0copy[2*MAXPATHLEN+1]; |
| 1702 int nr = 0; | 1675 int nr = 0; |
| 1703 #endif | 1676 #endif |
| 1704 #if defined(HAVE_REALPATH) | 1677 #if defined(HAVE_REALPATH) |
| 1767 } | 1740 } |
| 1768 } | 1741 } |
| 1769 #else /* All other filename syntaxes */ | 1742 #else /* All other filename syntaxes */ |
| 1770 if (_HAVE_SCRIPT_ARGUMENT(argc, argv)) { | 1743 if (_HAVE_SCRIPT_ARGUMENT(argc, argv)) { |
| 1771 #if defined(HAVE_REALPATH) | 1744 #if defined(HAVE_REALPATH) |
| 1772 if (_wrealpath(argv0, fullpath)) { | 1745 if (_Py_wrealpath(argv0, fullpath)) { |
| 1773 argv0 = fullpath; | 1746 argv0 = fullpath; |
| 1774 } | 1747 } |
| 1775 #endif | 1748 #endif |
| 1776 p = wcsrchr(argv0, SEP); | 1749 p = wcsrchr(argv0, SEP); |
| 1777 } | 1750 } |
