summaryrefslogtreecommitdiffstats
path: root/Python/fileutils.c
Commit message (Collapse)AuthorAgeFilesLines
* gh-81057: Move More Globals in Core Code to _PyRuntimeState (gh-99516)Eric Snow2022-11-161-1/+1
| | | https://github.com/python/cpython/issues/81057
* gh-95174: Handle missing dup() and constants in WASI (GH-95229)Christian Heimes2022-07-261-1/+5
| | | | | | | - check for ``dup()`` libc function - handle missing ``F_DUPFD`` in ``dup2()`` replacement function - add workaround for WASI libc bug in MSG_TRUNC - ESHUTDOWN is missing, use EPIPE instead - POLLPRI is missing, define as 0 (no-op)
* gh-93103: Py_DecodeLocale() uses _PyRuntime.preconfig (#93187)Victor Stinner2022-05-241-4/+4
| | | | | | | | | | The Py_DecodeLocale() and Py_EncodeLocale() now use _PyRuntime.preconfig, rather than Py_UTF8Mode and Py_LegacyWindowsFSEncodingFlag global configuration varibles, to decide if the UTF-8 encoding is used or not. As documented, these functions must not be called before Python is preinitialized. The new PyConfig API should now be used, rather than using deprecated functions like Py_SetPath() or PySys_SetArgv().
* gh-92536: PEP 623: Remove wstr and legacy APIs from Unicode (GH-92537)Inada Naoki2022-05-121-14/+1
|
* gh-91731: Replace Py_BUILD_ASSERT() with static_assert() (#91730)Victor Stinner2022-04-201-1/+1
| | | | | | | | | | | | Python 3.11 now uses C11 standard which adds static_assert() to <assert.h>. * In pytime.c, replace Py_BUILD_ASSERT() with preprocessor checks on SIZEOF_TIME_T with #error. * On macOS, py_mach_timebase_info() now accepts timebase members with the same size than _PyTime_t. * py_get_monotonic_clock() now saturates GetTickCount64() to _PyTime_MAX: GetTickCount64() is unsigned, whereas _PyTime_t is signed.
* bpo-47000: Add `locale.getencoding()` (GH-32068)Inada Naoki2022-04-091-9/+9
|
* bpo-47260: Fix os.closerange() potentially being a no-op in a seccomp ↵Alexey Izbyshev2022-04-081-4/+5
| | | | | | | | | | | | | | | | | | sandbox (GH-32418) _Py_closerange() currently assumes that close_range() closes all file descriptors even if it returns an error (other than ENOSYS). This assumption can be wrong on Linux if a seccomp sandbox denies the underlying syscall, pretending that it returns EPERM or EACCES. In this case _Py_closerange() won't close any descriptors at all, which in the worst case can be a security issue. Fix this by falling back to other methods in case of any close_range() error. Note that fallbacks will not be triggered on any problems with closing individual file descriptors because close_range() is documented to ignore such errors on both Linux[1] and FreeBSD[2]. [1] https://man7.org/linux/man-pages/man2/close_range.2.html [2] https://www.freebsd.org/cgi/man.cgi?query=close_range&sektion=2
* Remove trailing spaces (GH-31695)Serhiy Storchaka2022-03-051-1/+1
|
* bpo-46362: Ensure ntpath.abspath() uses the Windows API correctly (GH-30571)neonene2022-01-131-36/+1
| | | This makes ntpath.abspath()/getpath_abspath() follow normpath(), since some WinAPIs such as PathCchSkipRoot() require backslashed paths.
* bpo-46217: Revert use of Windows constant that is newer than what we support ↵Steve Dower2022-01-081-1/+1
| | | | (GH-30473)
* bpo-46208: Fix normalization of relative paths in ↵neonene2022-01-061-9/+16
| | | | _Py_normpath()/os.path.normpath (GH-30362)
* bpo-45582: Port getpath[p].c to Python (GH-29041)Steve Dower2021-12-031-91/+144
| | | | | The getpath.py file is frozen at build time and executed as code over a namespace. It is never imported, nor is it meant to be importable or reusable. However, it should be easier to read, modify, and patch than the previous code. This commit attempts to preserve every previously tested quirk, but these may be changed in the future to better align platforms.
* bpo-45506: Normalize _PyPathConfig.stdlib_dir when calculated. (#29040)Eric Snow2021-10-221-0/+95
| | | | | The recently added PyConfig.stdlib_dir was being set with ".." entries. When __file__ was added for from modules this caused a problem on out-of-tree builds. This PR fixes that by normalizing "stdlib_dir" when it is calculated in getpath.c. https://bugs.python.org/issue45506
* bpo-45020: Default to using frozen modules unless running from source tree. ↵Eric Snow2021-10-161-0/+12
| | | | | | | (gh-28940) The default was "off". Switching it to "on" means users get the benefit of frozen stdlib modules without having to do anything. There's a special-case for running-in-source-tree, so contributors don't get surprised when their stdlib changes don't get used. https://bugs.python.org/issue45020
* bpo-45434: pyport.h no longer includes <stdlib.h> (GH-28914)Victor Stinner2021-10-131-0/+1
| | | | | Include <stdlib.h> explicitly in C files. Python.h includes <wchar.h>.
* Fix typos in the Python directory (GH-28767)Christian Clauss2021-10-061-1/+1
|
* Do not check isabs() on Windows. (gh-28584)Eric Snow2021-09-271-0/+2
| | | | | I missed this in gh-28550. https://bugs.python.org/issue45211
* bpo-45211: Move helpers from getpath.c to internal API. (gh-28550)Eric Snow2021-09-271-4/+98
| | | | | | | | | | | | This accomplishes 2 things: * consolidates some common code between getpath.c and getpathp.c * makes the helpers available to code in other files FWIW, the signature of the join_relfile() function (in fileutils.c) intentionally mirrors that of Windows' PathCchCombineEx(). Note that this change is mostly moving code around. No behavior is meant to change. https://bugs.python.org/issue45211
* bpo-44219: Release the GIL during isatty syscalls (GH-28250)Vincent Michel2021-09-091-2/+14
| | | | | | Release the GIL while performing isatty() system calls on arbitrary file descriptors. In particular, this affects os.isatty(), os.device_encoding() and io.TextIOWrapper. By extension, io.open() in text mode is also affected.
* bpo-44849: Fix os.set_inheritable() on FreeBSD 14 with O_PATH (GH-27623)Victor Stinner2021-08-061-3/+4
| | | | | Fix the os.set_inheritable() function on FreeBSD 14 for file descriptor opened with the O_PATH flag: ignore the EBADF error on ioctl(), fallback on the fcntl() implementation.
* bpo-43667: Fix broken Unicode encoding in non-UTF locales on Solaris (GH-25096)Jakub Kulík2021-04-301-0/+106
|
* bpo-30555: Fix WindowsConsoleIO fails in the presence of fd redirection ↵Segev Finer2021-04-231-16/+45
| | | | | | | | (GH-1927) This works by not caching the handle and instead getting the handle from the file descriptor each time, so that if the actual handle changes by fd redirection closing/opening the console handle beneath our feet, we will keep working correctly.
* bpo-35883: Py_DecodeLocale() escapes invalid Unicode characters (GH-24843)Victor Stinner2021-03-171-39/+79
| | | | | | | | | | Python no longer fails at startup with a fatal error if a command line argument contains an invalid Unicode character. The Py_DecodeLocale() function now escapes byte sequences which would be decoded as Unicode characters outside the [U+0000; U+10ffff] range. Use MAX_UNICODE constant in unicodeobject.c.
* bpo-42780: Fix set_inheritable() for O_PATH file descriptors on Linux (GH-24172)cptpcrd2021-01-201-0/+7
|
* bpo-32381: Remove unused _Py_fopen() function (GH-23711)Victor Stinner2020-12-091-27/+0
| | | | Remove the private _Py_fopen() function which is no longer needed. Use _Py_wfopen() or _Py_fopen_obj() instead.
* bpo-41462: Add os.set_blocking() support for VxWorks RTOS (GH-21713)pxinwr2020-12-071-1/+3
|
* bpo-42236: os.device_encoding() respects UTF-8 Mode (GH-23119)Victor Stinner2020-11-041-11/+7
| | | | On Unix, the os.device_encoding() function now returns 'UTF-8' rather than the device encoding if the Python UTF-8 Mode is enabled.
* bpo-42236: Use UTF-8 encoding if nl_langinfo(CODESET) fails (GH-23086)Victor Stinner2020-11-011-26/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | If the nl_langinfo(CODESET) function returns an empty string, Python now uses UTF-8 as the filesystem encoding. In May 2010 (commit b744ba1d14c5487576c95d0311e357b707600b47), I modified Python to log a warning and use UTF-8 as the filesystem encoding (instead of None) if nl_langinfo(CODESET) returns an empty string. In August 2020 (commit 94908bbc1503df830d1d615e7b57744ae1b41079), I modified Python startup to fail with a fatal error and a specific error message if nl_langinfo(CODESET) returns an empty string. The intent was to prevent guessing the encoding and also investigate user configuration where this case happens. In 10 years (2010 to 2020), I saw zero user report about the error message related to nl_langinfo(CODESET) returning an empty string. Today, UTF-8 became the defacto standard and it's safe to make the assumption that the user expects UTF-8. For example, nl_langinfo(CODESET) can return an empty string on macOS if the LC_CTYPE locale is not supported, and UTF-8 is the default encoding on macOS. While this change is likely to not affect anyone in practice, it should make UTF-8 lover happy ;-) Rewrite also the documentation explaining how Python selects the filesystem encoding and error handler.
* bpo-42236: Enhance _locale._get_locale_encoding() (GH-23083)Victor Stinner2020-11-011-15/+59
| | | | | | | | | * Rename _Py_GetLocaleEncoding() to _Py_GetLocaleEncodingObject() * Add _Py_GetLocaleEncoding() which returns a wchar_t* string to share code between _Py_GetLocaleEncodingObject() and config_get_locale_encoding(). * _Py_GetLocaleEncodingObject() now decodes nl_langinfo(CODESET) from the current locale encoding with surrogateescape, rather than using UTF-8.
* bpo-42208: Add _Py_GetLocaleEncoding() (GH-23050)Victor Stinner2020-10-311-1/+42
| | | | | | | | _io.TextIOWrapper no longer calls getpreferredencoding(False) of _bootlocale to get the locale encoding, but calls _Py_GetLocaleEncoding() instead. Add config_get_fs_encoding() sub-function. Reorganize also config_get_locale_encoding() code.
* bpo-38324: Fix test__locale.py Windows failures (GH-20529)TIGirardi2020-10-201-2/+13
| | | | Use wide-char _W_* fields of lconv structure on Windows Remove "ps_AF" from test__locale.known_numerics on Windows
* bpo-40422: Move _Py_closerange to fileutils.c (GH-22680)Kyle Evans2020-10-131-0/+76
| | | | | | | This API is relatively lightweight and organizationally, given that it's used by multiple modules, it makes sense to move it to fileutils. Requires making sure that _posixsubprocess is compiled with the appropriate Py_BUIILD_CORE_BUILTIN macro.
* bpo-36346: Make using the legacy Unicode C API optional (GH-21437)Serhiy Storchaka2020-07-101-4/+19
| | | | Add compile time option USE_UNICODE_WCHAR_CACHE. Setting it to 0 makes the interpreter not using the wchar_t cache and the legacy Unicode C API.
* bpo-41094: Fix decoding errors with audit when open files. (GH-21095)Serhiy Storchaka2020-06-241-4/+19
|
* bpo-40957: Fix refleak in _Py_fopen_obj() (GH-20827)Christian Heimes2020-06-131-0/+1
| | | Signed-off-by: Christian Heimes <christian@python.org>
* bpo-40268: Remove unused osdefs.h includes (GH-19532)Victor Stinner2020-04-151-1/+1
| | | When the include is needed, add required symbol in a comment.
* bpo-39943: Add the const qualifier to pointers on non-mutable PyBytes data. ↵Serhiy Storchaka2020-04-121-1/+1
| | | | (GH-19472)
* bpo-38353: Add subfunctions to getpath.c (GH-16572)Victor Stinner2019-10-041-4/+6
| | | | | | | | | | | | | | Following symbolic links is now limited to 40 attempts, just to prevent loops. Add subfunctions: * Add resolve_symlinks() * Add calculate_argv0_path_framework() * Add calculate_which() * Add calculate_program_macos() Fix also _Py_wreadlink(): readlink() result type is Py_ssize_t, not int.
* bpo-37549: os.dup() fails for standard streams on Windows 7 (GH-15389)Zackery Spytz2019-08-231-1/+8
|
* bpo-37834: Normalise handling of reparse points on Windows (GH-15231)Steve Dower2019-08-211-1/+6
| | | | | | | | | | bpo-37834: Normalise handling of reparse points on Windows * ntpath.realpath() and nt.stat() will traverse all supported reparse points (previously was mixed) * nt.lstat() will let the OS traverse reparse points that are not name surrogates (previously would not traverse any reparse point) * nt.[l]stat() will only set S_IFLNK for symlinks (previous behaviour) * nt.readlink() will read destinations for symlinks and junction points only bpo-1311: os.path.exists('nul') now returns True on Windows * nt.stat('nul').st_mode is now S_IFCHR (previously was an error)
* bpo-20443: _PyConfig_Read() gets the absolute path of run_filename (GH-14053)Victor Stinner2019-06-251-0/+97
| | | | | | | | | | | | Python now gets the absolute path of the script filename specified on the command line (ex: "python3 script.py"): the __file__ attribute of the __main__ module, sys.argv[0] and sys.path[0] become an absolute path, rather than a relative path. * Add _Py_isabs() and _Py_abspath() functions. * _PyConfig_Read() now tries to get the absolute path of run_filename, but keeps the relative path if _Py_abspath() fails. * Reimplement os._getfullpathname() using _Py_abspath(). * Use _Py_isabs() in getpath.c.
* bpo-37267: Do not check for FILE_TYPE_CHAR in os.dup() on Windows (GH-14051)Zackery Spytz2019-06-171-12/+5
| | | | On Windows, os.dup() no longer creates an inheritable fd when handling a character file.
* bpo-36842: Implement PEP 578 (GH-12613)Steve Dower2019-05-231-0/+18
| | | Adds sys.audit, sys.addaudithook, io.open_code, and associated C APIs.
* bpo-36775: Add _Py_FORCE_UTF8_FS_ENCODING macro (GH-13056)Victor Stinner2019-05-021-8/+8
| | | | | | | Add _Py_FORCE_UTF8_LOCALE and _Py_FORCE_UTF8_FS_ENCODING macros to avoid factorize "#if defined(__ANDROID__) || defined(__VXWORKS__)" and "#if defined(__APPLE__)". Cleanup also config_init_fs_encoding().
* bpo-36352: Avoid hardcoded MAXPATHLEN size in getpath.c (GH-12423)Victor Stinner2019-03-191-1/+1
| | | | * Use Py_ARRAY_LENGTH() rather than hardcoded MAXPATHLEN in getpath.c. * Pass string length to functions modifying strings.
* bpo-36352: Clarify fileutils.h documentation (GH-12406)Victor Stinner2019-03-181-14/+21
| | | | | | | The last parameter of _Py_wreadlink(), _Py_wrealpath() and _Py_wgetcwd() is a length, not a size: number of characters including the trailing NUL character. Enhance also documentation of error conditions.
* bpo-31904: Add encoding support for VxWorks RTOS (GH-12051)pxinwr2019-03-041-3/+3
| | | | | | | | Use UTF-8 as the system encoding on VxWorks. The main reason are: 1. The locale is frequently misconfigured. 2. Missing some functions to deal with locale in VxWorks C library.
* bpo-34523: Fix C locale coercion on FreeBSD CURRENT (GH-10672)Victor Stinner2018-11-231-0/+13
| | | | | | | | bpo-34523, bpo-35290: C locale coercion now resets the Python internal "force ASCII" mode. This change fix the filesystem encoding on FreeBSD CURRENT, which has a new "C.UTF-8" locale, when the UTF-8 mode is disabled. Add _Py_ResetForceASCII(): _Py_SetLocaleFromEnv() now calls it.
* bpo-28604: Fix localeconv() for different LC_MONETARY (GH-10606)Victor Stinner2018-11-201-27/+18
| | | | | | | | | | | | | | | | | | | | | locale.localeconv() now sets temporarily the LC_CTYPE locale to the LC_MONETARY locale if the two locales are different and monetary strings are non-ASCII. This temporary change affects other threads. Changes: * locale.localeconv() can now set LC_CTYPE to LC_MONETARY to decode monetary fields. * Add LocaleInfo.grouping_buffer: copy localeconv() grouping string since it can be replaced anytime if a different thread calls localeconv(). * _Py_GetLocaleconvNumeric() now requires a "struct lconv *" structure, so locale.localeconv() now longer calls localeconv() twice. Moreover, the function now requires all arguments to be non-NULL. * Rename STATIC_LOCALE_INFO_INIT to LocaleInfo_STATIC_INIT. * Move _Py_GetLocaleconvNumeric() definition from fileutils.h to pycore_fileutils.h. pycore_fileutils.h now includes locale.h. * The _locale module is now built with Py_BUILD_CORE defined.
* bpo-35081: Add pycore_fileutils.h (GH-10371)Victor Stinner2018-11-061-0/+1
| | | | Move Py_BUILD_CORE code from Include/fileutils.h to a new Include/internal/pycore_fileutils.h file.