mirror of
https://github.com/python/cpython.git
synced 2025-08-31 14:07:50 +00:00
Initial revision
This commit is contained in:
parent
37ba0bc50b
commit
667d704997
8 changed files with 1013 additions and 0 deletions
41
Modules/getpath.c
Normal file
41
Modules/getpath.c
Normal file
|
@ -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;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue