blob: 8e1c00d4e74ece2d98d9172436e6b3a053e798fb [file] [log] [blame]
Guido van Rossum667d7041995-08-04 04:20:48 +00001#include "Python.h"
2#include "osdefs.h"
3
4
5#ifndef PYTHONPATH
6#define PYTHONPATH ".:/usr/local/lib/python"
7#endif
8
9
10/* Return the initial python search path. This is called once from
11 initsys() to initialize sys.path. The environment variable
12 PYTHONPATH is fetched and the default path appended. The default
13 path may be passed to the preprocessor; if not, a system-dependent
14 default is used. */
15
16char *
17getpythonpath()
18{
19 char *path = getenv("PYTHONPATH");
20 char *defpath = PYTHONPATH;
21 static char *buf = NULL;
22 char *p;
23 int n;
24
25 if (path == NULL)
26 path = "";
27 n = strlen(path) + strlen(defpath) + 2;
28 if (buf != NULL) {
29 free(buf);
30 buf = NULL;
31 }
32 buf = malloc(n);
33 if (buf == NULL)
34 Py_FatalError("not enough memory to copy module search path");
35 strcpy(buf, path);
36 p = buf + strlen(buf);
37 if (p != buf)
38 *p++ = DELIM;
39 strcpy(p, defpath);
40 return buf;
41}