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