Guido van Rossum | 582646a | 1996-05-28 22:30:17 +0000 | [diff] [blame] | 1 | /*********************************************************** |
| 2 | Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam, |
| 3 | The Netherlands. |
| 4 | |
| 5 | All Rights Reserved |
| 6 | |
| 7 | Permission to use, copy, modify, and distribute this software and its |
| 8 | documentation for any purpose and without fee is hereby granted, |
| 9 | provided that the above copyright notice appear in all copies and that |
| 10 | both that copyright notice and this permission notice appear in |
| 11 | supporting documentation, and that the names of Stichting Mathematisch |
| 12 | Centrum or CWI not be used in advertising or publicity pertaining to |
| 13 | distribution of the software without specific, written prior permission. |
| 14 | |
| 15 | STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO |
| 16 | THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND |
| 17 | FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE |
| 18 | FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 19 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 20 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT |
| 21 | OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 22 | |
| 23 | ******************************************************************/ |
| 24 | |
| 25 | /* Return the initial module search path. */ |
| 26 | |
Guido van Rossum | 667d704 | 1995-08-04 04:20:48 +0000 | [diff] [blame] | 27 | #include "Python.h" |
| 28 | #include "osdefs.h" |
| 29 | |
Guido van Rossum | 667d704 | 1995-08-04 04:20:48 +0000 | [diff] [blame] | 30 | |
| 31 | #ifndef PYTHONPATH |
Guido van Rossum | 6e12d56 | 1996-07-30 20:36:12 +0000 | [diff] [blame] | 32 | #define PYTHONPATH "/usr/local/lib/python" |
Guido van Rossum | 667d704 | 1995-08-04 04:20:48 +0000 | [diff] [blame] | 33 | #endif |
| 34 | |
Guido van Rossum | c34c9a5 | 1996-06-12 04:20:27 +0000 | [diff] [blame] | 35 | #ifndef PREFIX |
| 36 | #define PREFIX "/usr/local" |
| 37 | #endif |
| 38 | |
| 39 | #ifndef EXEC_PREFIX |
Guido van Rossum | 6e12d56 | 1996-07-30 20:36:12 +0000 | [diff] [blame] | 40 | #define EXEC_PREFIX PREFIX |
Guido van Rossum | c34c9a5 | 1996-06-12 04:20:27 +0000 | [diff] [blame] | 41 | #endif |
| 42 | |
Guido van Rossum | 667d704 | 1995-08-04 04:20:48 +0000 | [diff] [blame] | 43 | |
Guido van Rossum | 582646a | 1996-05-28 22:30:17 +0000 | [diff] [blame] | 44 | /* This is called once from pythonrun to initialize sys.path. The |
| 45 | environment variable PYTHONPATH is fetched and the default path |
| 46 | appended. The default path may be passed to the preprocessor; if |
| 47 | not, a hardcoded default is used, which only makes (some) sense on |
| 48 | Unix. */ |
Guido van Rossum | 667d704 | 1995-08-04 04:20:48 +0000 | [diff] [blame] | 49 | |
| 50 | char * |
Guido van Rossum | 582646a | 1996-05-28 22:30:17 +0000 | [diff] [blame] | 51 | Py_GetPath() |
Guido van Rossum | 667d704 | 1995-08-04 04:20:48 +0000 | [diff] [blame] | 52 | { |
| 53 | char *path = getenv("PYTHONPATH"); |
| 54 | char *defpath = PYTHONPATH; |
| 55 | static char *buf = NULL; |
| 56 | char *p; |
| 57 | int n; |
| 58 | |
| 59 | if (path == NULL) |
| 60 | path = ""; |
| 61 | n = strlen(path) + strlen(defpath) + 2; |
| 62 | if (buf != NULL) { |
| 63 | free(buf); |
| 64 | buf = NULL; |
| 65 | } |
| 66 | buf = malloc(n); |
| 67 | if (buf == NULL) |
| 68 | Py_FatalError("not enough memory to copy module search path"); |
| 69 | strcpy(buf, path); |
| 70 | p = buf + strlen(buf); |
| 71 | if (p != buf) |
| 72 | *p++ = DELIM; |
| 73 | strcpy(p, defpath); |
| 74 | return buf; |
| 75 | } |
Guido van Rossum | c34c9a5 | 1996-06-12 04:20:27 +0000 | [diff] [blame] | 76 | |
| 77 | |
| 78 | /* Similar for Makefile variables $prefix and $exec_prefix */ |
| 79 | |
| 80 | char * |
| 81 | Py_GetPrefix() |
| 82 | { |
| 83 | return PREFIX; |
| 84 | } |
| 85 | |
| 86 | char * |
| 87 | Py_GetExecPrefix() |
| 88 | { |
| 89 | return EXEC_PREFIX; |
| 90 | } |