summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorKristján Valur Jónsson <kristjan@ccpgames.com>2007-05-07 19:25:38 (GMT)
committerKristján Valur Jónsson <kristjan@ccpgames.com>2007-05-07 19:25:38 (GMT)
commita1392d5ace266878ad6a3ff9dba96336ecde7fb3 (patch)
tree5c07dfc0f59bebaf45d114ff22210316a9430b91 /Modules
parentdffe9a214b243c251dc11f51bf2b7275cbdaff70 (diff)
downloadcpython-a1392d5ace266878ad6a3ff9dba96336ecde7fb3.zip
cpython-a1392d5ace266878ad6a3ff9dba96336ecde7fb3.tar.gz
cpython-a1392d5ace266878ad6a3ff9dba96336ecde7fb3.tar.bz2
Merge change 54982 from the trunk. This fixes the test_subprocess test in the testsuite for VisualStudio2005 builds, by "sanitizing" the "mode" that is used in the posixmodule's fdopen(). In particular the non-standard "U" mode character is removed.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/posixmodule.c20
1 files changed, 14 insertions, 6 deletions
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index 158b12e..b984c30 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -6170,16 +6170,23 @@ static PyObject *
posix_fdopen(PyObject *self, PyObject *args)
{
int fd;
- char *mode = "r";
+ char *orgmode = "r";
int bufsize = -1;
FILE *fp;
PyObject *f;
- if (!PyArg_ParseTuple(args, "i|si", &fd, &mode, &bufsize))
+ char *mode;
+ if (!PyArg_ParseTuple(args, "i|si", &fd, &orgmode, &bufsize))
return NULL;
- if (mode[0] != 'r' && mode[0] != 'w' && mode[0] != 'a') {
- PyErr_Format(PyExc_ValueError,
- "invalid file mode '%s'", mode);
+ /* Sanitize mode. See fileobject.c */
+ mode = PyMem_MALLOC(strlen(orgmode)+3);
+ if (!mode) {
+ PyErr_NoMemory();
+ return NULL;
+ }
+ strcpy(mode, orgmode);
+ if (_PyFile_SanitizeMode(mode)) {
+ PyMem_FREE(mode);
return NULL;
}
Py_BEGIN_ALLOW_THREADS
@@ -6200,10 +6207,11 @@ posix_fdopen(PyObject *self, PyObject *args)
#else
fp = fdopen(fd, mode);
#endif
+ PyMem_FREE(mode);
Py_END_ALLOW_THREADS
if (fp == NULL)
return posix_error();
- f = PyFile_FromFile(fp, "<fdopen>", mode, fclose);
+ f = PyFile_FromFile(fp, "<fdopen>", orgmode, fclose);
if (f != NULL)
PyFile_SetBufSize(f, bufsize);
return f;