mirror of
https://github.com/python/cpython.git
synced 2025-11-02 19:12:55 +00:00
(Merge 3.4) Issue #9246: On POSIX, os.getcwd() now supports paths longer than
1025 bytes. Patch written by William Orr.
This commit is contained in:
commit
cc0bbbc781
2 changed files with 32 additions and 9 deletions
|
|
@ -15,6 +15,9 @@ Core and Builtins
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- Issue #9246: On POSIX, os.getcwd() now supports paths longer than 1025 bytes.
|
||||||
|
Patch written by William Orr.
|
||||||
|
|
||||||
- Issue #17445: add difflib.diff_bytes() to support comparison of
|
- Issue #17445: add difflib.diff_bytes() to support comparison of
|
||||||
byte strings (fixes a regression from Python 2).
|
byte strings (fixes a regression from Python 2).
|
||||||
|
|
||||||
|
|
@ -33,7 +36,7 @@ Library
|
||||||
- Issue #23728: binascii.crc_hqx() could return an integer outside of the range
|
- Issue #23728: binascii.crc_hqx() could return an integer outside of the range
|
||||||
0-0xffff for empty data.
|
0-0xffff for empty data.
|
||||||
|
|
||||||
- Issue #23887: urllib.error.HTTPError now has a proper repr() representation.
|
- Issue #23887: urllib.error.HTTPError now has a proper repr() representation.
|
||||||
Patch by Berker Peksag.
|
Patch by Berker Peksag.
|
||||||
|
|
||||||
Documentation
|
Documentation
|
||||||
|
|
|
||||||
|
|
@ -3267,12 +3267,15 @@ os_lchown_impl(PyModuleDef *module, path_t *path, uid_t uid, gid_t gid)
|
||||||
static PyObject *
|
static PyObject *
|
||||||
posix_getcwd(int use_bytes)
|
posix_getcwd(int use_bytes)
|
||||||
{
|
{
|
||||||
char buf[1026];
|
char *buf, *tmpbuf;
|
||||||
char *res;
|
char *cwd;
|
||||||
|
const size_t chunk = 1024;
|
||||||
|
size_t buflen = 0;
|
||||||
|
PyObject *obj;
|
||||||
|
|
||||||
#ifdef MS_WINDOWS
|
#ifdef MS_WINDOWS
|
||||||
if (!use_bytes) {
|
if (!use_bytes) {
|
||||||
wchar_t wbuf[1026];
|
wchar_t wbuf[MAXPATHLEN];
|
||||||
wchar_t *wbuf2 = wbuf;
|
wchar_t *wbuf2 = wbuf;
|
||||||
PyObject *resobj;
|
PyObject *resobj;
|
||||||
DWORD len;
|
DWORD len;
|
||||||
|
|
@ -3306,14 +3309,31 @@ posix_getcwd(int use_bytes)
|
||||||
return NULL;
|
return NULL;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
buf = cwd = NULL;
|
||||||
Py_BEGIN_ALLOW_THREADS
|
Py_BEGIN_ALLOW_THREADS
|
||||||
res = getcwd(buf, sizeof buf);
|
do {
|
||||||
|
buflen += chunk;
|
||||||
|
tmpbuf = PyMem_RawRealloc(buf, buflen);
|
||||||
|
if (tmpbuf == NULL)
|
||||||
|
break;
|
||||||
|
|
||||||
|
buf = tmpbuf;
|
||||||
|
cwd = getcwd(buf, buflen);
|
||||||
|
} while (cwd == NULL && errno == ERANGE);
|
||||||
Py_END_ALLOW_THREADS
|
Py_END_ALLOW_THREADS
|
||||||
if (res == NULL)
|
|
||||||
|
if (cwd == NULL) {
|
||||||
|
PyMem_RawFree(buf);
|
||||||
return posix_error();
|
return posix_error();
|
||||||
|
}
|
||||||
|
|
||||||
if (use_bytes)
|
if (use_bytes)
|
||||||
return PyBytes_FromStringAndSize(buf, strlen(buf));
|
obj = PyBytes_FromStringAndSize(buf, strlen(buf));
|
||||||
return PyUnicode_DecodeFSDefault(buf);
|
else
|
||||||
|
obj = PyUnicode_DecodeFSDefault(buf);
|
||||||
|
PyMem_RawFree(buf);
|
||||||
|
|
||||||
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -8873,7 +8893,7 @@ os_truncate_impl(PyModuleDef *module, path_t *path, Py_off_t length)
|
||||||
fd = _wopen(path->wide, _O_WRONLY | _O_BINARY | _O_NOINHERIT);
|
fd = _wopen(path->wide, _O_WRONLY | _O_BINARY | _O_NOINHERIT);
|
||||||
else
|
else
|
||||||
fd = _open(path->narrow, _O_WRONLY | _O_BINARY | _O_NOINHERIT);
|
fd = _open(path->narrow, _O_WRONLY | _O_BINARY | _O_NOINHERIT);
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
result = -1;
|
result = -1;
|
||||||
else {
|
else {
|
||||||
result = _chsize_s(fd, length);
|
result = _chsize_s(fd, length);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue