-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathpygetpath.c
63 lines (51 loc) · 1.01 KB
/
pygetpath.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include "Python.h"
#include "osdefs.h"
#include <sys/types.h>
#include <string.h>
extern char *Py_GetProgramName(void);
static int pathCalculated = 0;
static char progPath[MAXPATHLEN+1];
static char modulePathes[4*MAXPATHLEN+1];
static char execPrefixPath[2*MAXPATHLEN+1];
static void calcPathes() {
if(pathCalculated) return;
char* p = stpcpy(progPath, Py_GetProgramName());
while(--p > progPath) {
if(*p == '/') {
*p = 0;
break;
}
}
strcpy(modulePathes, progPath);
strcat(modulePathes, "/pylib/lib:");
strcat(modulePathes, progPath);
strcat(modulePathes, "/pylib/otherlibs");
strcpy(execPrefixPath, progPath);
strcat(execPrefixPath, "/pylib/exec");
pathCalculated = 1;
}
/* External interface */
char *
Py_GetPath(void)
{
calcPathes();
return modulePathes;
}
char *
Py_GetPrefix(void)
{
calcPathes();
return "pygetpath.c-PYPREFIX-NOT-SET";
}
char *
Py_GetExecPrefix(void)
{
calcPathes();
return execPrefixPath;
}
char *
Py_GetProgramFullPath(void)
{
calcPathes();
return progPath;
}