diff options
author | Martin v. Löwis <martin@v.loewis.de> | 2008-04-05 20:41:37 +0000 |
---|---|---|
committer | Martin v. Löwis <martin@v.loewis.de> | 2008-04-05 20:41:37 +0000 |
commit | 157ee125a422cdc9700851050723ac4259c23bec (patch) | |
tree | 512f0a13dc915515f42b2ed712634b6272a3d455 /Python/pythonrun.c | |
parent | 8464b33651d87d0940783fe47d2014abcb9ece50 (diff) | |
download | cpython-157ee125a422cdc9700851050723ac4259c23bec.tar.gz |
Change command line processing API to use wchar_t.
Fixes #2128.
Diffstat (limited to 'Python/pythonrun.c')
-rw-r--r-- | Python/pythonrun.c | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/Python/pythonrun.c b/Python/pythonrun.c index 3207fb8b81..124eaf095d 100644 --- a/Python/pythonrun.c +++ b/Python/pythonrun.c @@ -17,6 +17,7 @@ #include "ast.h" #include "eval.h" #include "marshal.h" +#include "osdefs.h" #ifdef HAVE_SIGNAL_H #include <signal.h> @@ -30,6 +31,7 @@ #ifdef MS_WINDOWS #undef BYTE #include "windows.h" +#define PATH_MAX MAXPATHLEN #endif #ifndef Py_REF_DEBUG @@ -44,7 +46,7 @@ extern "C" { #endif -extern char *Py_GetPath(void); +extern wchar_t *Py_GetPath(void); extern grammar _PyParser_Grammar; /* From graminit.c */ @@ -646,35 +648,43 @@ Py_EndInterpreter(PyThreadState *tstate) PyInterpreterState_Delete(interp); } -static char *progname = "python"; +static wchar_t *progname = L"python"; void -Py_SetProgramName(char *pn) +Py_SetProgramName(wchar_t *pn) { if (pn && *pn) progname = pn; } -char * +wchar_t * Py_GetProgramName(void) { return progname; } -static char *default_home = NULL; +static wchar_t *default_home = NULL; +static wchar_t env_home[PATH_MAX+1]; void -Py_SetPythonHome(char *home) +Py_SetPythonHome(wchar_t *home) { default_home = home; } -char * +wchar_t * Py_GetPythonHome(void) { - char *home = default_home; - if (home == NULL && !Py_IgnoreEnvironmentFlag) - home = Py_GETENV("PYTHONHOME"); + wchar_t *home = default_home; + if (home == NULL && !Py_IgnoreEnvironmentFlag) { + char* chome = Py_GETENV("PYTHONHOME"); + if (chome) { + size_t r = mbstowcs(env_home, chome, PATH_MAX+1); + if (r != (size_t)-1 && r <= PATH_MAX) + home = env_home; + } + + } return home; } |