Mercurial > cpython-lru_cache-weakref
diff Modules/getpath.c @ 14845:88d3a8974409 legacy-trunk
fix bug #114290: when interpreter's argv[0] has a relative path make
it absolute by joining it with getcwd result. avoid including
unnecessary ./ in path but do not test for ../ (more complicated)
| author | Jeremy Hylton <jeremy@alum.mit.edu> |
|---|---|
| date | Mon, 25 Sep 2000 17:00:24 +0000 |
| parents | 6f6f965c5e2d |
| children | 4bea4f59c4e4 |
line wrap: on
line diff
--- a/Modules/getpath.c Mon Sep 25 15:09:28 2000 +0000 +++ b/Modules/getpath.c Mon Sep 25 17:00:24 2000 +0000 @@ -219,6 +219,23 @@ buffer[n+k] = '\0'; } +static void +init_path_from_argv0(char *path, char *argv0_path) +{ + if (argv0_path[0] == '/') + strcpy(path, argv0_path); + else if (argv0_path[0] == '.') { + getcwd(path, MAXPATHLEN); + if (argv0_path[1] == '/') + joinpath(path, argv0_path + 2); + else + joinpath(path, argv0_path); + } + else { + getcwd(path, MAXPATHLEN); + joinpath(path, argv0_path); + } +} static int search_for_prefix(char *argv0_path, char *home) @@ -264,7 +281,7 @@ } /* Search from argv0_path, until root is found */ - strcpy(prefix, argv0_path); + init_path_from_argv0(prefix, argv0_path); do { n = strlen(prefix); joinpath(prefix, lib_python); @@ -314,7 +331,7 @@ } /* Search from argv0_path, until root is found */ - strcpy(exec_prefix, argv0_path); + init_path_from_argv0(exec_prefix, argv0_path); do { n = strlen(exec_prefix); joinpath(exec_prefix, lib_python);
