summaryrefslogtreecommitdiffstats
path: root/Modules/getpath.c
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1995-08-04 04:20:48 (GMT)
committerGuido van Rossum <guido@python.org>1995-08-04 04:20:48 (GMT)
commit667d704997f26a1a22f4e981bbb3c2f8399cfc41 (patch)
tree245b91f0451e57625f921f02f6f0d3dfb85d59a0 /Modules/getpath.c
parent37ba0bc50be14b6f2148ebb7f824c8e77f001488 (diff)
downloadcpython-667d704997f26a1a22f4e981bbb3c2f8399cfc41.zip
cpython-667d704997f26a1a22f4e981bbb3c2f8399cfc41.tar.gz
cpython-667d704997f26a1a22f4e981bbb3c2f8399cfc41.tar.bz2
Initial revision
Diffstat (limited to 'Modules/getpath.c')
-rw-r--r--Modules/getpath.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/Modules/getpath.c b/Modules/getpath.c
new file mode 100644
index 0000000..8e1c00d
--- /dev/null
+++ b/Modules/getpath.c
@@ -0,0 +1,41 @@
+#include "Python.h"
+#include "osdefs.h"
+
+
+#ifndef PYTHONPATH
+#define PYTHONPATH ".:/usr/local/lib/python"
+#endif
+
+
+/* Return the initial python search path. This is called once from
+ initsys() to initialize sys.path. The environment variable
+ PYTHONPATH is fetched and the default path appended. The default
+ path may be passed to the preprocessor; if not, a system-dependent
+ default is used. */
+
+char *
+getpythonpath()
+{
+ char *path = getenv("PYTHONPATH");
+ char *defpath = PYTHONPATH;
+ static char *buf = NULL;
+ char *p;
+ int n;
+
+ if (path == NULL)
+ path = "";
+ n = strlen(path) + strlen(defpath) + 2;
+ if (buf != NULL) {
+ free(buf);
+ buf = NULL;
+ }
+ buf = malloc(n);
+ if (buf == NULL)
+ Py_FatalError("not enough memory to copy module search path");
+ strcpy(buf, path);
+ p = buf + strlen(buf);
+ if (p != buf)
+ *p++ = DELIM;
+ strcpy(p, defpath);
+ return buf;
+}