summaryrefslogtreecommitdiff
path: root/Modules/getpath.c
diff options
context:
space:
mode:
authorJeremy Hylton <jeremy@alum.mit.edu>2000-09-25 17:00:24 +0000
committerJeremy Hylton <jeremy@alum.mit.edu>2000-09-25 17:00:24 +0000
commit890d958c72a74e73a4e9ad6180922d584d0a4b3b (patch)
treec8618980330a1e280c00469a9d0ccc3f98d4c222 /Modules/getpath.c
parent144524d3d3a34645cf6d3d6c4cca13c19edee4d1 (diff)
downloadcpython-890d958c72a74e73a4e9ad6180922d584d0a4b3b.tar.gz
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)
Diffstat (limited to 'Modules/getpath.c')
-rw-r--r--Modules/getpath.c21
1 files changed, 19 insertions, 2 deletions
diff --git a/Modules/getpath.c b/Modules/getpath.c
index c295d307cc..7d9a9612be 100644
--- a/Modules/getpath.c
+++ b/Modules/getpath.c
@@ -219,6 +219,23 @@ joinpath(char *buffer, char *stuff)
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_for_prefix(char *argv0_path, char *home)
}
/* 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_for_exec_prefix(char *argv0_path, char *home)
}
/* 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);