Guido van Rossum | 667d704 | 1995-08-04 04:20:48 +0000 | [diff] [blame] | 1 | #include "Python.h" |
| 2 | #include "osdefs.h" |
| 3 | |
Guido van Rossum | 468fc6a | 1996-02-25 04:50:31 +0000 | [diff] [blame] | 4 | #ifdef HAVE_STDLIB_H |
| 5 | #include <stdlib.h> |
| 6 | #else |
| 7 | extern char *getenv Py_PROTO((const char *)); |
| 8 | #endif |
| 9 | |
Guido van Rossum | 667d704 | 1995-08-04 04:20:48 +0000 | [diff] [blame] | 10 | |
| 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 | |
| 22 | char * |
| 23 | getpythonpath() |
| 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 | } |