Staging
v0.5.1
https://github.com/python/cpython
Revision 8476d00060b076c1cce4e386566dab1f0d6979b3 authored by Guido van Rossum on 08 October 1995, 01:07:06 UTC, committed by Guido van Rossum on 08 October 1995, 01:07:06 UTC
1 parent 0568d5e
Raw File
Tip revision: 8476d00060b076c1cce4e386566dab1f0d6979b3 authored by Guido van Rossum on 08 October 1995, 01:07:06 UTC
footnote about keyword args
Tip revision: 8476d00
getpath.c
#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;
}
back to top