Mercurial > cpython-lru_cache-weakref
annotate Modules/getpath.c @ 3546:3f7cdf1663f7 legacy-trunk
A version of swed that can import html files. Also demonstrates
implementing object handlers in Python.
| author | Jack Jansen <jack.jansen@cwi.nl> |
|---|---|
| date | Tue, 07 May 1996 15:25:36 +0000 |
| parents | b6c0a41e4a46 |
| children | f158edccc72c |
| rev | line source |
|---|---|
| 2896 | 1 #include "Python.h" |
| 2 #include "osdefs.h" | |
| 3 | |
|
3416
b6c0a41e4a46
Include stdlib.h or declare getenv
Guido van Rossum <guido@python.org>
parents:
2896
diff
changeset
|
4 #ifdef HAVE_STDLIB_H |
|
b6c0a41e4a46
Include stdlib.h or declare getenv
Guido van Rossum <guido@python.org>
parents:
2896
diff
changeset
|
5 #include <stdlib.h> |
|
b6c0a41e4a46
Include stdlib.h or declare getenv
Guido van Rossum <guido@python.org>
parents:
2896
diff
changeset
|
6 #else |
|
b6c0a41e4a46
Include stdlib.h or declare getenv
Guido van Rossum <guido@python.org>
parents:
2896
diff
changeset
|
7 extern char *getenv Py_PROTO((const char *)); |
|
b6c0a41e4a46
Include stdlib.h or declare getenv
Guido van Rossum <guido@python.org>
parents:
2896
diff
changeset
|
8 #endif |
|
b6c0a41e4a46
Include stdlib.h or declare getenv
Guido van Rossum <guido@python.org>
parents:
2896
diff
changeset
|
9 |
| 2896 | 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 } |
