blob: e0ebf5abc8ac5cc348489dbd427f57374c0b9242 [file] [log] [blame]
Guido van Rossum582646a1996-05-28 22:30:17 +00001/***********************************************************
2Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
3The Netherlands.
4
5 All Rights Reserved
6
7Permission to use, copy, modify, and distribute this software and its
8documentation for any purpose and without fee is hereby granted,
9provided that the above copyright notice appear in all copies and that
10both that copyright notice and this permission notice appear in
11supporting documentation, and that the names of Stichting Mathematisch
12Centrum or CWI not be used in advertising or publicity pertaining to
13distribution of the software without specific, written prior permission.
14
15STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
16THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
18FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
20ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
21OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22
23******************************************************************/
24
25/* Return the initial module search path. */
26
Guido van Rossum667d7041995-08-04 04:20:48 +000027#include "Python.h"
28#include "osdefs.h"
29
Guido van Rossum667d7041995-08-04 04:20:48 +000030
31#ifndef PYTHONPATH
Guido van Rossum6e12d561996-07-30 20:36:12 +000032#define PYTHONPATH "/usr/local/lib/python"
Guido van Rossum667d7041995-08-04 04:20:48 +000033#endif
34
Guido van Rossumc34c9a51996-06-12 04:20:27 +000035#ifndef PREFIX
36#define PREFIX "/usr/local"
37#endif
38
39#ifndef EXEC_PREFIX
Guido van Rossum6e12d561996-07-30 20:36:12 +000040#define EXEC_PREFIX PREFIX
Guido van Rossumc34c9a51996-06-12 04:20:27 +000041#endif
42
Guido van Rossum667d7041995-08-04 04:20:48 +000043
Guido van Rossum582646a1996-05-28 22:30:17 +000044/* 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 Rossum667d7041995-08-04 04:20:48 +000049
50char *
Guido van Rossum582646a1996-05-28 22:30:17 +000051Py_GetPath()
Guido van Rossum667d7041995-08-04 04:20:48 +000052{
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 Rossumc34c9a51996-06-12 04:20:27 +000076
77
78/* Similar for Makefile variables $prefix and $exec_prefix */
79
80char *
81Py_GetPrefix()
82{
83 return PREFIX;
84}
85
86char *
87Py_GetExecPrefix()
88{
89 return EXEC_PREFIX;
90}