diff options
author | Kristján Valur Jónsson <kristjan@ccpgames.com> | 2007-05-07 19:25:38 +0000 |
---|---|---|
committer | Kristján Valur Jónsson <kristjan@ccpgames.com> | 2007-05-07 19:25:38 +0000 |
commit | a1392d5ace266878ad6a3ff9dba96336ecde7fb3 (patch) | |
tree | 5c07dfc0f59bebaf45d114ff22210316a9430b91 /Objects/fileobject.c | |
parent | dffe9a214b243c251dc11f51bf2b7275cbdaff70 (diff) | |
download | cpython-git-a1392d5ace266878ad6a3ff9dba96336ecde7fb3.tar.gz |
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 'Objects/fileobject.c')
-rw-r--r-- | Objects/fileobject.c | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/Objects/fileobject.c b/Objects/fileobject.c index 869ded916c..f954e36fa5 100644 --- a/Objects/fileobject.c +++ b/Objects/fileobject.c @@ -139,17 +139,16 @@ fill_file_fields(PyFileObject *f, FILE *fp, PyObject *name, char *mode, ignore stuff they don't understand... write or append mode with universal newline support is expressly forbidden by PEP 278. Additionally, remove the 'U' from the mode string as platforms - won't know what it is. */ -/* zero return is kewl - one is un-kewl */ -static int -sanitize_the_mode(char *mode) + won't know what it is. Non-zero return signals an exception */ +int +_PyFile_SanitizeMode(char *mode) { char *upos; size_t len = strlen(mode); if (!len) { PyErr_SetString(PyExc_ValueError, "empty mode string"); - return 1; + return -1; } upos = strchr(mode, 'U'); @@ -160,7 +159,7 @@ sanitize_the_mode(char *mode) PyErr_Format(PyExc_ValueError, "universal newline " "mode can only be used with modes " "starting with 'r'"); - return 1; + return -1; } if (mode[0] != 'r') { @@ -175,7 +174,7 @@ sanitize_the_mode(char *mode) } else if (mode[0] != 'r' && mode[0] != 'w' && mode[0] != 'a') { PyErr_Format(PyExc_ValueError, "mode string must begin with " "one of 'r', 'w', 'a' or 'U', not '%.200s'", mode); - return 1; + return -1; } return 0; @@ -204,7 +203,7 @@ open_the_file(PyFileObject *f, char *name, char *mode) } strcpy(newmode, mode); - if (sanitize_the_mode(newmode)) { + if (_PyFile_SanitizeMode(newmode)) { f = NULL; goto cleanup; } |