blob: ce978c6c462a6e30e2293cd9a3f57804efb98947 [file] [log] [blame]
Guido van Rossum228d8072001-03-02 05:58:11 +00001#include "Python.h"
2#include "osdefs.h"
3
Jeremy Hylton35030692001-11-28 21:30:04 +00004static char *prefix, *exec_prefix, *progpath, *module_search_path=NULL;
Guido van Rossum228d8072001-03-02 05:58:11 +00005
6static void
7calculate_path()
Jeremy Hylton35030692001-11-28 21:30:04 +00008{
9 char *pypath = getenv("Python$Path");
10 if (pypath) {
11 int pathlen = strlen(pypath);
12 module_search_path = malloc(pathlen + 1);
13 if (module_search_path)
Tim Peters1422e9d2001-12-15 22:12:47 +000014 strncpy(module_search_path, pypath, pathlen + 1);
Jeremy Hylton35030692001-11-28 21:30:04 +000015 else {
16 fprintf(stderr,
17 "Not enough memory for dynamic PYTHONPATH.\n"
18 "Using default static PYTHONPATH.\n");
19 }
20 }
21 if (!module_search_path)
22 module_search_path = "<Python$Dir>.Lib";
23 prefix = "<Python$Dir>";
24 exec_prefix = prefix;
25 progpath = Py_GetProgramName();
Guido van Rossum228d8072001-03-02 05:58:11 +000026}
27
28/* External interface */
29
30char *
31Py_GetPath()
32{
33 if (!module_search_path)
34 calculate_path();
35 return module_search_path;
36}
37
38char *
39Py_GetPrefix()
40{
41 if (!module_search_path)
42 calculate_path();
43 return prefix;
44}
45
46char *
47Py_GetExecPrefix()
48{
49 if (!module_search_path)
50 calculate_path();
51 return exec_prefix;
52}
53
54char *
55Py_GetProgramFullPath()
56{
57 if (!module_search_path)
58 calculate_path();
59 return progpath;
60}