Mercurial > cpython-lru_cache-weakref
annotate Modules/getpath.c @ 17405:afbb65b60fa2 2.0
Inspired by Tim Peters' 1.14->1.15 checkin to asynchat
Quoting orignal message:
'''
Fix from the Madusa mailing list:
http://groups.yahoo.com/group/medusa/message/333
It's clear that Medusa should not be checking for an empty buffer
via "buf is ''". The patch merely changes "is" to "==". However,
there's a mystery here all the same: Python attempts to store null
strings uniquely, so it's unclear why "buf is ''" ever returned
false when buf actually was empty. *Some* string operations produce
non-unique null strings, e.g.
'''
| author | Moshe Zadka <moshez@math.huji.ac.il> |
|---|---|
| date | Wed, 11 Apr 2001 08:06:02 +0000 |
| parents | d01394b0aa69 |
| children | fbf8abec93d1 |
| rev | line source |
|---|---|
|
3621
f158edccc72c
grand renaming; added copyright to some files
Guido van Rossum <guido@python.org>
parents:
3416
diff
changeset
|
1 |
|
f158edccc72c
grand renaming; added copyright to some files
Guido van Rossum <guido@python.org>
parents:
3416
diff
changeset
|
2 /* Return the initial module search path. */ |
|
f158edccc72c
grand renaming; added copyright to some files
Guido van Rossum <guido@python.org>
parents:
3416
diff
changeset
|
3 |
| 2896 | 4 #include "Python.h" |
| 5 #include "osdefs.h" | |
| 6 | |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
7 #include <sys/types.h> |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
8 #include <sys/stat.h> |
|
5698
ba860dc0a585
Use string.h, not strings.h
Guido van Rossum <guido@python.org>
parents:
5568
diff
changeset
|
9 #include <string.h> |
| 2896 | 10 |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
11 #if HAVE_UNISTD_H |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
12 #include <unistd.h> |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
13 #endif /* HAVE_UNISTD_H */ |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
14 |
|
9970
8efa37a770c6
Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents:
8203
diff
changeset
|
15 #ifdef WITH_NEXT_FRAMEWORK |
|
8efa37a770c6
Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents:
8203
diff
changeset
|
16 #include <mach-o/dyld.h> |
|
8efa37a770c6
Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents:
8203
diff
changeset
|
17 #endif |
|
8efa37a770c6
Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents:
8203
diff
changeset
|
18 |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
19 /* Search in some common locations for the associated Python libraries. |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
20 * |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
21 * Two directories must be found, the platform independent directory |
|
5316
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
22 * (prefix), containing the common .py and .pyc files, and the platform |
|
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
23 * dependent directory (exec_prefix), containing the shared library |
|
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
24 * modules. Note that prefix and exec_prefix can be the same directory, |
|
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
25 * but for some installations, they are different. |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
26 * |
|
5316
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
27 * Py_GetPath() carries out separate searches for prefix and exec_prefix. |
|
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
28 * Each search tries a number of different locations until a ``landmark'' |
|
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
29 * file or directory is found. If no prefix or exec_prefix is found, a |
|
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
30 * warning message is issued and the preprocessor defined PREFIX and |
|
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
31 * EXEC_PREFIX are used (even though they will not work); python carries on |
|
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
32 * as best as is possible, but most imports will fail. |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
33 * |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
34 * Before any searches are done, the location of the executable is |
|
5316
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
35 * determined. If argv[0] has one or more slashs in it, it is used |
|
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
36 * unchanged. Otherwise, it must have been invoked from the shell's path, |
|
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
37 * so we search $PATH for the named executable and use that. If the |
|
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
38 * executable was not found on $PATH (or there was no $PATH environment |
|
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
39 * variable), the original argv[0] string is used. |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
40 * |
|
5316
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
41 * Next, the executable location is examined to see if it is a symbolic |
|
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
42 * link. If so, the link is chased (correctly interpreting a relative |
|
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
43 * pathname if one is found) and the directory of the link target is used. |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
44 * |
|
5316
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
45 * Finally, argv0_path is set to the directory containing the executable |
|
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
46 * (i.e. the last component is stripped). |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
47 * |
|
5316
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
48 * With argv0_path in hand, we perform a number of steps. The same steps |
|
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
49 * are performed for prefix and for exec_prefix, but with a different |
|
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
50 * landmark. |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
51 * |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
52 * Step 1. Are we running python out of the build directory? This is |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
53 * checked by looking for a different kind of landmark relative to |
|
5316
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
54 * argv0_path. For prefix, the landmark's path is derived from the VPATH |
|
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
55 * preprocessor variable (taking into account that its value is almost, but |
|
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
56 * not quite, what we need). For exec_prefix, the landmark is |
|
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
57 * Modules/Setup. If the landmark is found, we're done. |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
58 * |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
59 * For the remaining steps, the prefix landmark will always be |
|
12775
8e2b35d386aa
Patch from M.-A. Lemburg:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12576
diff
changeset
|
60 * lib/python$VERSION/os.py and the exec_prefix will always be |
|
6498
4981fd2b3211
Change sharedmodules to lib-dynload.
Guido van Rossum <guido@python.org>
parents:
6121
diff
changeset
|
61 * lib/python$VERSION/lib-dynload, where $VERSION is Python's version |
|
5316
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
62 * number as supplied by the Makefile. Note that this means that no more |
|
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
63 * build directory checking is performed; if the first step did not find |
|
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
64 * the landmarks, the assumption is that python is running from an |
|
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
65 * installed setup. |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
66 * |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
67 * Step 2. See if the $PYTHONHOME environment variable points to the |
|
5316
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
68 * installed location of the Python libraries. If $PYTHONHOME is set, then |
|
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
69 * it points to prefix and exec_prefix. $PYTHONHOME can be a single |
|
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
70 * directory, which is used for both, or the prefix and exec_prefix |
|
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
71 * directories separated by a colon. |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
72 * |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
73 * Step 3. Try to find prefix and exec_prefix relative to argv0_path, |
|
5316
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
74 * backtracking up the path until it is exhausted. This is the most common |
|
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
75 * step to succeed. Note that if prefix and exec_prefix are different, |
|
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
76 * exec_prefix is more likely to be found; however if exec_prefix is a |
|
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
77 * subdirectory of prefix, both will be found. |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
78 * |
|
5316
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
79 * Step 4. Search the directories pointed to by the preprocessor variables |
|
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
80 * PREFIX and EXEC_PREFIX. These are supplied by the Makefile but can be |
|
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
81 * passed in as options to the configure script. |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
82 * |
|
5316
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
83 * That's it! |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
84 * |
|
5316
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
85 * Well, almost. Once we have determined prefix and exec_prefix, the |
|
13620
5b727ab37092
Spelling fixes supplied by Rob W. W. Hooft. All these are fixes in either
Thomas Wouters <thomas@python.org>
parents:
13428
diff
changeset
|
86 * preprocessor variable PYTHONPATH is used to construct a path. Each |
|
5316
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
87 * relative path on PYTHONPATH is prefixed with prefix. Then the directory |
|
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
88 * containing the shared library modules is appended. The environment |
|
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
89 * variable $PYTHONPATH is inserted in front of it all. Finally, the |
|
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
90 * prefix and exec_prefix globals are tweaked so they reflect the values |
|
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
91 * expected by other code, by stripping the "lib/python$VERSION/..." stuff |
|
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
92 * off. If either points to the build directory, the globals are reset to |
|
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
93 * the corresponding preprocessor variables (so sys.prefix will reflect the |
|
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
94 * installation location, even though sys.path points into the build |
|
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
95 * directory). This seems to make more sense given that currently the only |
|
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
96 * known use of sys.prefix and sys.exec_prefix is for the ILU installation |
|
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
97 * process to find the installed Python tree. |
|
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
98 */ |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
99 |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
100 #ifndef VERSION |
|
14898
4bea4f59c4e4
Fix buffer overflow vulnerabilities in calculate_path(). Code used
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14845
diff
changeset
|
101 #define VERSION "2.0" |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
102 #endif |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
103 |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
104 #ifndef VPATH |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
105 #define VPATH "." |
| 2896 | 106 #endif |
| 107 | |
|
3674
3eaf2c673a11
provide access to $(exec_)prefix
Guido van Rossum <guido@python.org>
parents:
3621
diff
changeset
|
108 #ifndef PREFIX |
|
3eaf2c673a11
provide access to $(exec_)prefix
Guido van Rossum <guido@python.org>
parents:
3621
diff
changeset
|
109 #define PREFIX "/usr/local" |
|
3eaf2c673a11
provide access to $(exec_)prefix
Guido van Rossum <guido@python.org>
parents:
3621
diff
changeset
|
110 #endif |
|
3eaf2c673a11
provide access to $(exec_)prefix
Guido van Rossum <guido@python.org>
parents:
3621
diff
changeset
|
111 |
|
3eaf2c673a11
provide access to $(exec_)prefix
Guido van Rossum <guido@python.org>
parents:
3621
diff
changeset
|
112 #ifndef EXEC_PREFIX |
|
3878
4286910080a9
Don't have "." in the default path.
Guido van Rossum <guido@python.org>
parents:
3674
diff
changeset
|
113 #define EXEC_PREFIX PREFIX |
|
3674
3eaf2c673a11
provide access to $(exec_)prefix
Guido van Rossum <guido@python.org>
parents:
3621
diff
changeset
|
114 #endif |
|
3eaf2c673a11
provide access to $(exec_)prefix
Guido van Rossum <guido@python.org>
parents:
3621
diff
changeset
|
115 |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
116 #ifndef PYTHONPATH |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
117 /* I know this isn't K&R C, but the Makefile specifies it anyway */ |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
118 #define PYTHONPATH PREFIX "/lib/python" VERSION ":" \ |
|
6498
4981fd2b3211
Change sharedmodules to lib-dynload.
Guido van Rossum <guido@python.org>
parents:
6121
diff
changeset
|
119 EXEC_PREFIX "/lib/python" VERSION "/lib-dynload" |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
120 #endif |
| 2896 | 121 |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
122 #ifndef LANDMARK |
|
12775
8e2b35d386aa
Patch from M.-A. Lemburg:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12576
diff
changeset
|
123 #define LANDMARK "os.py" |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
124 #endif |
|
14898
4bea4f59c4e4
Fix buffer overflow vulnerabilities in calculate_path(). Code used
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14845
diff
changeset
|
125 |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
126 static char prefix[MAXPATHLEN+1]; |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
127 static char exec_prefix[MAXPATHLEN+1]; |
|
5568
139ab21d2629
Make delimiter and separator static for K&R C.
Guido van Rossum <guido@python.org>
parents:
5500
diff
changeset
|
128 static char progpath[MAXPATHLEN+1]; |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
129 static char *module_search_path = NULL; |
|
14907
d01394b0aa69
Minor ANSIfication: lib_python no longer needs to be initialized
Fred Drake <fdrake@acm.org>
parents:
14898
diff
changeset
|
130 static char lib_python[] = "lib/python" VERSION; |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
131 |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
132 static void |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
133 reduce(char *dir) |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
134 { |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
135 size_t i = strlen(dir); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
136 while (i > 0 && dir[i] != SEP) |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
137 --i; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
138 dir[i] = '\0'; |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
139 } |
|
7117
419dca2b3a61
Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents:
6823
diff
changeset
|
140 |
|
419dca2b3a61
Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents:
6823
diff
changeset
|
141 |
|
419dca2b3a61
Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents:
6823
diff
changeset
|
142 #ifndef S_ISREG |
|
419dca2b3a61
Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents:
6823
diff
changeset
|
143 #define S_ISREG(x) (((x) & S_IFMT) == S_IFREG) |
|
419dca2b3a61
Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents:
6823
diff
changeset
|
144 #endif |
|
419dca2b3a61
Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents:
6823
diff
changeset
|
145 |
|
419dca2b3a61
Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents:
6823
diff
changeset
|
146 #ifndef S_ISDIR |
|
419dca2b3a61
Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents:
6823
diff
changeset
|
147 #define S_ISDIR(x) (((x) & S_IFMT) == S_IFDIR) |
|
419dca2b3a61
Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents:
6823
diff
changeset
|
148 #endif |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
149 |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
150 static int |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
151 isfile(char *filename) /* Is file, not directory */ |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
152 { |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
153 struct stat buf; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
154 if (stat(filename, &buf) != 0) |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
155 return 0; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
156 if (!S_ISREG(buf.st_mode)) |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
157 return 0; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
158 return 1; |
|
7117
419dca2b3a61
Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents:
6823
diff
changeset
|
159 } |
|
419dca2b3a61
Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents:
6823
diff
changeset
|
160 |
|
419dca2b3a61
Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents:
6823
diff
changeset
|
161 |
|
419dca2b3a61
Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents:
6823
diff
changeset
|
162 static int |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
163 ismodule(char *filename) /* Is module -- check for .pyc/.pyo too */ |
|
7117
419dca2b3a61
Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents:
6823
diff
changeset
|
164 { |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
165 if (isfile(filename)) |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
166 return 1; |
|
7117
419dca2b3a61
Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents:
6823
diff
changeset
|
167 |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
168 /* Check for the compiled version of prefix. */ |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
169 if (strlen(filename) < MAXPATHLEN) { |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
170 strcat(filename, Py_OptimizeFlag ? "o" : "c"); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
171 if (isfile(filename)) |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
172 return 1; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
173 } |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
174 return 0; |
|
7117
419dca2b3a61
Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents:
6823
diff
changeset
|
175 } |
|
419dca2b3a61
Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents:
6823
diff
changeset
|
176 |
|
419dca2b3a61
Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents:
6823
diff
changeset
|
177 |
|
419dca2b3a61
Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents:
6823
diff
changeset
|
178 static int |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
179 isxfile(char *filename) /* Is executable file */ |
|
7117
419dca2b3a61
Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents:
6823
diff
changeset
|
180 { |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
181 struct stat buf; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
182 if (stat(filename, &buf) != 0) |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
183 return 0; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
184 if (!S_ISREG(buf.st_mode)) |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
185 return 0; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
186 if ((buf.st_mode & 0111) == 0) |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
187 return 0; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
188 return 1; |
|
7117
419dca2b3a61
Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents:
6823
diff
changeset
|
189 } |
|
419dca2b3a61
Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents:
6823
diff
changeset
|
190 |
|
419dca2b3a61
Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents:
6823
diff
changeset
|
191 |
|
419dca2b3a61
Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents:
6823
diff
changeset
|
192 static int |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
193 isdir(char *filename) /* Is directory */ |
|
7117
419dca2b3a61
Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents:
6823
diff
changeset
|
194 { |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
195 struct stat buf; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
196 if (stat(filename, &buf) != 0) |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
197 return 0; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
198 if (!S_ISDIR(buf.st_mode)) |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
199 return 0; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
200 return 1; |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
201 } |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
202 |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
203 |
|
14898
4bea4f59c4e4
Fix buffer overflow vulnerabilities in calculate_path(). Code used
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14845
diff
changeset
|
204 /* joinpath requires that any buffer argument passed to it has at |
|
4bea4f59c4e4
Fix buffer overflow vulnerabilities in calculate_path(). Code used
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14845
diff
changeset
|
205 least MAXPATHLEN + 1 bytes allocated. If this requirement is met, |
|
4bea4f59c4e4
Fix buffer overflow vulnerabilities in calculate_path(). Code used
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14845
diff
changeset
|
206 it guarantees that it will never overflow the buffer. If stuff |
|
4bea4f59c4e4
Fix buffer overflow vulnerabilities in calculate_path(). Code used
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14845
diff
changeset
|
207 is too long, buffer will contain a truncated copy of stuff. |
|
4bea4f59c4e4
Fix buffer overflow vulnerabilities in calculate_path(). Code used
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14845
diff
changeset
|
208 */ |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
209 static void |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
210 joinpath(char *buffer, char *stuff) |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
211 { |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
212 size_t n, k; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
213 if (stuff[0] == SEP) |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
214 n = 0; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
215 else { |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
216 n = strlen(buffer); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
217 if (n > 0 && buffer[n-1] != SEP && n < MAXPATHLEN) |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
218 buffer[n++] = SEP; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
219 } |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
220 k = strlen(stuff); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
221 if (n + k > MAXPATHLEN) |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
222 k = MAXPATHLEN - n; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
223 strncpy(buffer+n, stuff, k); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
224 buffer[n+k] = '\0'; |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
225 } |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
226 |
|
14898
4bea4f59c4e4
Fix buffer overflow vulnerabilities in calculate_path(). Code used
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14845
diff
changeset
|
227 /* init_path_from_argv0 requirs that path be allocated at least |
|
4bea4f59c4e4
Fix buffer overflow vulnerabilities in calculate_path(). Code used
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14845
diff
changeset
|
228 MAXPATHLEN + 1 bytes and that argv0_path be no more than MAXPATHLEN |
|
4bea4f59c4e4
Fix buffer overflow vulnerabilities in calculate_path(). Code used
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14845
diff
changeset
|
229 bytes. |
|
4bea4f59c4e4
Fix buffer overflow vulnerabilities in calculate_path(). Code used
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14845
diff
changeset
|
230 */ |
|
14845
88d3a8974409
fix bug #114290: when interpreter's argv[0] has a relative path make
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14375
diff
changeset
|
231 static void |
|
88d3a8974409
fix bug #114290: when interpreter's argv[0] has a relative path make
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14375
diff
changeset
|
232 init_path_from_argv0(char *path, char *argv0_path) |
|
88d3a8974409
fix bug #114290: when interpreter's argv[0] has a relative path make
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14375
diff
changeset
|
233 { |
|
88d3a8974409
fix bug #114290: when interpreter's argv[0] has a relative path make
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14375
diff
changeset
|
234 if (argv0_path[0] == '/') |
|
88d3a8974409
fix bug #114290: when interpreter's argv[0] has a relative path make
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14375
diff
changeset
|
235 strcpy(path, argv0_path); |
|
88d3a8974409
fix bug #114290: when interpreter's argv[0] has a relative path make
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14375
diff
changeset
|
236 else if (argv0_path[0] == '.') { |
|
88d3a8974409
fix bug #114290: when interpreter's argv[0] has a relative path make
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14375
diff
changeset
|
237 getcwd(path, MAXPATHLEN); |
|
88d3a8974409
fix bug #114290: when interpreter's argv[0] has a relative path make
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14375
diff
changeset
|
238 if (argv0_path[1] == '/') |
|
88d3a8974409
fix bug #114290: when interpreter's argv[0] has a relative path make
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14375
diff
changeset
|
239 joinpath(path, argv0_path + 2); |
|
88d3a8974409
fix bug #114290: when interpreter's argv[0] has a relative path make
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14375
diff
changeset
|
240 else |
|
88d3a8974409
fix bug #114290: when interpreter's argv[0] has a relative path make
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14375
diff
changeset
|
241 joinpath(path, argv0_path); |
|
88d3a8974409
fix bug #114290: when interpreter's argv[0] has a relative path make
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14375
diff
changeset
|
242 } |
|
88d3a8974409
fix bug #114290: when interpreter's argv[0] has a relative path make
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14375
diff
changeset
|
243 else { |
|
88d3a8974409
fix bug #114290: when interpreter's argv[0] has a relative path make
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14375
diff
changeset
|
244 getcwd(path, MAXPATHLEN); |
|
88d3a8974409
fix bug #114290: when interpreter's argv[0] has a relative path make
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14375
diff
changeset
|
245 joinpath(path, argv0_path); |
|
88d3a8974409
fix bug #114290: when interpreter's argv[0] has a relative path make
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14375
diff
changeset
|
246 } |
|
88d3a8974409
fix bug #114290: when interpreter's argv[0] has a relative path make
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14375
diff
changeset
|
247 } |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
248 |
|
14898
4bea4f59c4e4
Fix buffer overflow vulnerabilities in calculate_path(). Code used
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14845
diff
changeset
|
249 /* search_for_prefix requires that argv0_path be no more than MAXPATHLEN |
|
4bea4f59c4e4
Fix buffer overflow vulnerabilities in calculate_path(). Code used
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14845
diff
changeset
|
250 bytes long. |
|
4bea4f59c4e4
Fix buffer overflow vulnerabilities in calculate_path(). Code used
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14845
diff
changeset
|
251 */ |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
252 static int |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
253 search_for_prefix(char *argv0_path, char *home) |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
254 { |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
255 size_t n; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
256 char *vpath; |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
257 |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
258 /* If PYTHONHOME is set, we believe it unconditionally */ |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
259 if (home) { |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
260 char *delim; |
|
14898
4bea4f59c4e4
Fix buffer overflow vulnerabilities in calculate_path(). Code used
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14845
diff
changeset
|
261 strncpy(prefix, home, MAXPATHLEN); |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
262 delim = strchr(prefix, DELIM); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
263 if (delim) |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
264 *delim = '\0'; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
265 joinpath(prefix, lib_python); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
266 joinpath(prefix, LANDMARK); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
267 return 1; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
268 } |
|
12775
8e2b35d386aa
Patch from M.-A. Lemburg:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12576
diff
changeset
|
269 |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
270 /* Check to see if argv[0] is in the build directory */ |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
271 strcpy(prefix, argv0_path); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
272 joinpath(prefix, "Modules/Setup"); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
273 if (isfile(prefix)) { |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
274 /* Check VPATH to see if argv0_path is in the build directory. |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
275 * Complication: the VPATH passed in is relative to the |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
276 * Modules build directory and points to the Modules source |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
277 * directory; we need it relative to the build tree and |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
278 * pointing to the source tree. Solution: chop off a leading |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
279 * ".." (but only if it's there -- it could be an absolute |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
280 * path) and chop off the final component (assuming it's |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
281 * "Modules"). |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
282 */ |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
283 vpath = VPATH; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
284 if (vpath[0] == '.' && vpath[1] == '.' && vpath[2] == '/') |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
285 vpath += 3; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
286 strcpy(prefix, argv0_path); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
287 joinpath(prefix, vpath); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
288 reduce(prefix); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
289 joinpath(prefix, "Lib"); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
290 joinpath(prefix, LANDMARK); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
291 if (ismodule(prefix)) |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
292 return -1; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
293 } |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
294 |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
295 /* Search from argv0_path, until root is found */ |
|
14845
88d3a8974409
fix bug #114290: when interpreter's argv[0] has a relative path make
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14375
diff
changeset
|
296 init_path_from_argv0(prefix, argv0_path); |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
297 do { |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
298 n = strlen(prefix); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
299 joinpath(prefix, lib_python); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
300 joinpath(prefix, LANDMARK); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
301 if (ismodule(prefix)) |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
302 return 1; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
303 prefix[n] = '\0'; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
304 reduce(prefix); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
305 } while (prefix[0]); |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
306 |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
307 /* Look at configure's PREFIX */ |
|
14898
4bea4f59c4e4
Fix buffer overflow vulnerabilities in calculate_path(). Code used
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14845
diff
changeset
|
308 strncpy(prefix, PREFIX, MAXPATHLEN); |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
309 joinpath(prefix, lib_python); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
310 joinpath(prefix, LANDMARK); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
311 if (ismodule(prefix)) |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
312 return 1; |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
313 |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
314 /* Fail */ |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
315 return 0; |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
316 } |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
317 |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
318 |
|
14898
4bea4f59c4e4
Fix buffer overflow vulnerabilities in calculate_path(). Code used
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14845
diff
changeset
|
319 /* search_for_exec_prefix requires that argv0_path be no more than |
|
4bea4f59c4e4
Fix buffer overflow vulnerabilities in calculate_path(). Code used
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14845
diff
changeset
|
320 MAXPATHLEN bytes long. |
|
4bea4f59c4e4
Fix buffer overflow vulnerabilities in calculate_path(). Code used
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14845
diff
changeset
|
321 */ |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
322 static int |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
323 search_for_exec_prefix(char *argv0_path, char *home) |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
324 { |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
325 size_t n; |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
326 |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
327 /* If PYTHONHOME is set, we believe it unconditionally */ |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
328 if (home) { |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
329 char *delim; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
330 delim = strchr(home, DELIM); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
331 if (delim) |
|
14898
4bea4f59c4e4
Fix buffer overflow vulnerabilities in calculate_path(). Code used
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14845
diff
changeset
|
332 strncpy(exec_prefix, delim+1, MAXPATHLEN); |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
333 else |
|
14898
4bea4f59c4e4
Fix buffer overflow vulnerabilities in calculate_path(). Code used
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14845
diff
changeset
|
334 strncpy(exec_prefix, home, MAXPATHLEN); |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
335 joinpath(exec_prefix, lib_python); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
336 joinpath(exec_prefix, "lib-dynload"); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
337 return 1; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
338 } |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
339 |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
340 /* Check to see if argv[0] is in the build directory */ |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
341 strcpy(exec_prefix, argv0_path); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
342 joinpath(exec_prefix, "Modules/Setup"); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
343 if (isfile(exec_prefix)) { |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
344 reduce(exec_prefix); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
345 return -1; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
346 } |
|
12775
8e2b35d386aa
Patch from M.-A. Lemburg:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12576
diff
changeset
|
347 |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
348 /* Search from argv0_path, until root is found */ |
|
14845
88d3a8974409
fix bug #114290: when interpreter's argv[0] has a relative path make
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14375
diff
changeset
|
349 init_path_from_argv0(exec_prefix, argv0_path); |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
350 do { |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
351 n = strlen(exec_prefix); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
352 joinpath(exec_prefix, lib_python); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
353 joinpath(exec_prefix, "lib-dynload"); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
354 if (isdir(exec_prefix)) |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
355 return 1; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
356 exec_prefix[n] = '\0'; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
357 reduce(exec_prefix); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
358 } while (exec_prefix[0]); |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
359 |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
360 /* Look at configure's EXEC_PREFIX */ |
|
14898
4bea4f59c4e4
Fix buffer overflow vulnerabilities in calculate_path(). Code used
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14845
diff
changeset
|
361 strncpy(exec_prefix, EXEC_PREFIX, MAXPATHLEN); |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
362 joinpath(exec_prefix, lib_python); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
363 joinpath(exec_prefix, "lib-dynload"); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
364 if (isdir(exec_prefix)) |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
365 return 1; |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
366 |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
367 /* Fail */ |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
368 return 0; |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
369 } |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
370 |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
371 |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
372 static void |
|
13651
8a063423e0b7
Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
373 calculate_path(void) |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
374 { |
|
13667
a6c7bfdd6777
Even more ANSIfication: fix as many function pointers and declarations as
Thomas Wouters <thomas@python.org>
parents:
13651
diff
changeset
|
375 extern char *Py_GetProgramName(void); |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
376 |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
377 static char delimiter[2] = {DELIM, '\0'}; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
378 static char separator[2] = {SEP, '\0'}; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
379 char *pythonpath = PYTHONPATH; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
380 char *rtpypath = getenv("PYTHONPATH"); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
381 char *home = Py_GetPythonHome(); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
382 char *path = getenv("PATH"); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
383 char *prog = Py_GetProgramName(); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
384 char argv0_path[MAXPATHLEN+1]; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
385 int pfound, efound; /* 1 if found; -1 if found build directory */ |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
386 char *buf; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
387 size_t bufsz; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
388 size_t prefixsz; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
389 char *defpath = pythonpath; |
|
9970
8efa37a770c6
Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents:
8203
diff
changeset
|
390 #ifdef WITH_NEXT_FRAMEWORK |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
391 NSModule pythonModule; |
|
9970
8efa37a770c6
Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents:
8203
diff
changeset
|
392 #endif |
|
8efa37a770c6
Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents:
8203
diff
changeset
|
393 |
|
8efa37a770c6
Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents:
8203
diff
changeset
|
394 #ifdef WITH_NEXT_FRAMEWORK |
|
14898
4bea4f59c4e4
Fix buffer overflow vulnerabilities in calculate_path(). Code used
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14845
diff
changeset
|
395 /* XXX Need to check this code for buffer overflows */ |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
396 pythonModule = NSModuleForSymbol(NSLookupAndBindSymbol("_Py_Initialize")); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
397 /* Use dylib functions to find out where the framework was loaded from */ |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
398 buf = NSLibraryNameForModule(pythonModule); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
399 if (buf != NULL) { |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
400 /* We're in a framework. */ |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
401 strcpy(progpath, buf); |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
402 |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
403 /* Frameworks have support for versioning */ |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
404 strcpy(lib_python, "lib"); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
405 } |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
406 else { |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
407 /* If we're not in a framework, fall back to the old way |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
408 (even though NSNameOfModule() probably does the same thing.) */ |
|
9970
8efa37a770c6
Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents:
8203
diff
changeset
|
409 #endif |
|
8efa37a770c6
Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents:
8203
diff
changeset
|
410 |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
411 /* If there is no slash in the argv0 path, then we have to |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
412 * assume python is on the user's $PATH, since there's no |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
413 * other way to find a directory to start the search from. If |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
414 * $PATH isn't exported, you lose. |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
415 */ |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
416 if (strchr(prog, SEP)) |
|
14898
4bea4f59c4e4
Fix buffer overflow vulnerabilities in calculate_path(). Code used
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14845
diff
changeset
|
417 strncpy(progpath, prog, MAXPATHLEN); |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
418 else if (path) { |
|
14898
4bea4f59c4e4
Fix buffer overflow vulnerabilities in calculate_path(). Code used
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14845
diff
changeset
|
419 int bufspace = MAXPATHLEN; |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
420 while (1) { |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
421 char *delim = strchr(path, DELIM); |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
422 |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
423 if (delim) { |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
424 size_t len = delim - path; |
|
14898
4bea4f59c4e4
Fix buffer overflow vulnerabilities in calculate_path(). Code used
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14845
diff
changeset
|
425 if (len > bufspace) |
|
4bea4f59c4e4
Fix buffer overflow vulnerabilities in calculate_path(). Code used
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14845
diff
changeset
|
426 len = bufspace; |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
427 strncpy(progpath, path, len); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
428 *(progpath + len) = '\0'; |
|
14898
4bea4f59c4e4
Fix buffer overflow vulnerabilities in calculate_path(). Code used
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14845
diff
changeset
|
429 bufspace -= len; |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
430 } |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
431 else |
|
14898
4bea4f59c4e4
Fix buffer overflow vulnerabilities in calculate_path(). Code used
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14845
diff
changeset
|
432 strncpy(progpath, path, bufspace); |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
433 |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
434 joinpath(progpath, prog); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
435 if (isxfile(progpath)) |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
436 break; |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
437 |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
438 if (!delim) { |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
439 progpath[0] = '\0'; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
440 break; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
441 } |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
442 path = delim + 1; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
443 } |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
444 } |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
445 else |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
446 progpath[0] = '\0'; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
447 #ifdef WITH_NEXT_FRAMEWORK |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
448 } |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
449 #endif |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
450 |
|
14898
4bea4f59c4e4
Fix buffer overflow vulnerabilities in calculate_path(). Code used
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14845
diff
changeset
|
451 strncpy(argv0_path, progpath, MAXPATHLEN); |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
452 |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
453 #if HAVE_READLINK |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
454 { |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
455 char tmpbuffer[MAXPATHLEN+1]; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
456 int linklen = readlink(progpath, tmpbuffer, MAXPATHLEN); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
457 while (linklen != -1) { |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
458 /* It's not null terminated! */ |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
459 tmpbuffer[linklen] = '\0'; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
460 if (tmpbuffer[0] == SEP) |
|
14898
4bea4f59c4e4
Fix buffer overflow vulnerabilities in calculate_path(). Code used
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14845
diff
changeset
|
461 /* tmpbuffer should never be longer than MAXPATHLEN, |
|
4bea4f59c4e4
Fix buffer overflow vulnerabilities in calculate_path(). Code used
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14845
diff
changeset
|
462 but extra check does not hurt */ |
|
4bea4f59c4e4
Fix buffer overflow vulnerabilities in calculate_path(). Code used
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14845
diff
changeset
|
463 strncpy(argv0_path, tmpbuffer, MAXPATHLEN); |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
464 else { |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
465 /* Interpret relative to progpath */ |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
466 reduce(argv0_path); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
467 joinpath(argv0_path, tmpbuffer); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
468 } |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
469 linklen = readlink(argv0_path, tmpbuffer, MAXPATHLEN); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
470 } |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
471 } |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
472 #endif /* HAVE_READLINK */ |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
473 |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
474 reduce(argv0_path); |
|
14898
4bea4f59c4e4
Fix buffer overflow vulnerabilities in calculate_path(). Code used
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14845
diff
changeset
|
475 /* At this point, argv0_path is guaranteed to be less than |
|
4bea4f59c4e4
Fix buffer overflow vulnerabilities in calculate_path(). Code used
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14845
diff
changeset
|
476 MAXPATHLEN bytes long. |
|
4bea4f59c4e4
Fix buffer overflow vulnerabilities in calculate_path(). Code used
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14845
diff
changeset
|
477 */ |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
478 |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
479 if (!(pfound = search_for_prefix(argv0_path, home))) { |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
480 if (!Py_FrozenFlag) |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
481 fprintf(stderr, |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
482 "Could not find platform independent libraries <prefix>\n"); |
|
14898
4bea4f59c4e4
Fix buffer overflow vulnerabilities in calculate_path(). Code used
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14845
diff
changeset
|
483 strncpy(prefix, PREFIX, MAXPATHLEN); |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
484 joinpath(prefix, lib_python); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
485 } |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
486 else |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
487 reduce(prefix); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
488 |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
489 if (!(efound = search_for_exec_prefix(argv0_path, home))) { |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
490 if (!Py_FrozenFlag) |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
491 fprintf(stderr, |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
492 "Could not find platform dependent libraries <exec_prefix>\n"); |
|
14898
4bea4f59c4e4
Fix buffer overflow vulnerabilities in calculate_path(). Code used
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14845
diff
changeset
|
493 strncpy(exec_prefix, EXEC_PREFIX, MAXPATHLEN); |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
494 joinpath(exec_prefix, "lib/lib-dynload"); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
495 } |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
496 /* If we found EXEC_PREFIX do *not* reduce it! (Yet.) */ |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
497 |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
498 if ((!pfound || !efound) && !Py_FrozenFlag) |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
499 fprintf(stderr, |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
500 "Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]\n"); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
501 |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
502 /* Calculate size of return buffer. |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
503 */ |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
504 bufsz = 0; |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
505 |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
506 if (rtpypath) |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
507 bufsz += strlen(rtpypath) + 1; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
508 |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
509 prefixsz = strlen(prefix) + 1; |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
510 |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
511 while (1) { |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
512 char *delim = strchr(defpath, DELIM); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
513 |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
514 if (defpath[0] != SEP) |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
515 /* Paths are relative to prefix */ |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
516 bufsz += prefixsz; |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
517 |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
518 if (delim) |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
519 bufsz += delim - defpath + 1; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
520 else { |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
521 bufsz += strlen(defpath) + 1; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
522 break; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
523 } |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
524 defpath = delim + 1; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
525 } |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
526 |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
527 bufsz += strlen(exec_prefix) + 1; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
528 |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
529 /* This is the only malloc call in this file */ |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
530 buf = PyMem_Malloc(bufsz); |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
531 |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
532 if (buf == NULL) { |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
533 /* We can't exit, so print a warning and limp along */ |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
534 fprintf(stderr, "Not enough memory for dynamic PYTHONPATH.\n"); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
535 fprintf(stderr, "Using default static PYTHONPATH.\n"); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
536 module_search_path = PYTHONPATH; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
537 } |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
538 else { |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
539 /* Run-time value of $PYTHONPATH goes first */ |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
540 if (rtpypath) { |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
541 strcpy(buf, rtpypath); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
542 strcat(buf, delimiter); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
543 } |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
544 else |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
545 buf[0] = '\0'; |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
546 |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
547 /* Next goes merge of compile-time $PYTHONPATH with |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
548 * dynamically located prefix. |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
549 */ |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
550 defpath = pythonpath; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
551 while (1) { |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
552 char *delim = strchr(defpath, DELIM); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
553 |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
554 if (defpath[0] != SEP) { |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
555 strcat(buf, prefix); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
556 strcat(buf, separator); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
557 } |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
558 |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
559 if (delim) { |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
560 size_t len = delim - defpath + 1; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
561 size_t end = strlen(buf) + len; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
562 strncat(buf, defpath, len); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
563 *(buf + end) = '\0'; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
564 } |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
565 else { |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
566 strcat(buf, defpath); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
567 break; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
568 } |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
569 defpath = delim + 1; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
570 } |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
571 strcat(buf, delimiter); |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
572 |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
573 /* Finally, on goes the directory for dynamic-load modules */ |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
574 strcat(buf, exec_prefix); |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
575 |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
576 /* And publish the results */ |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
577 module_search_path = buf; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
578 } |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
579 |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
580 /* Reduce prefix and exec_prefix to their essence, |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
581 * e.g. /usr/local/lib/python1.5 is reduced to /usr/local. |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
582 * If we're loading relative to the build directory, |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
583 * return the compiled-in defaults instead. |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
584 */ |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
585 if (pfound > 0) { |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
586 reduce(prefix); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
587 reduce(prefix); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
588 } |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
589 else |
|
14898
4bea4f59c4e4
Fix buffer overflow vulnerabilities in calculate_path(). Code used
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14845
diff
changeset
|
590 strncpy(prefix, PREFIX, MAXPATHLEN); |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
591 |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
592 if (efound > 0) { |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
593 reduce(exec_prefix); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
594 reduce(exec_prefix); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
595 reduce(exec_prefix); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
596 } |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
597 else |
|
14898
4bea4f59c4e4
Fix buffer overflow vulnerabilities in calculate_path(). Code used
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14845
diff
changeset
|
598 strncpy(exec_prefix, EXEC_PREFIX, MAXPATHLEN); |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
599 } |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
600 |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
601 |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
602 /* External interface */ |
| 2896 | 603 |
| 604 char * | |
|
13651
8a063423e0b7
Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
605 Py_GetPath(void) |
| 2896 | 606 { |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
607 if (!module_search_path) |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
608 calculate_path(); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
609 return module_search_path; |
| 2896 | 610 } |
|
3674
3eaf2c673a11
provide access to $(exec_)prefix
Guido van Rossum <guido@python.org>
parents:
3621
diff
changeset
|
611 |
|
3eaf2c673a11
provide access to $(exec_)prefix
Guido van Rossum <guido@python.org>
parents:
3621
diff
changeset
|
612 char * |
|
13651
8a063423e0b7
Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
613 Py_GetPrefix(void) |
|
3674
3eaf2c673a11
provide access to $(exec_)prefix
Guido van Rossum <guido@python.org>
parents:
3621
diff
changeset
|
614 { |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
615 if (!module_search_path) |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
616 calculate_path(); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
617 return prefix; |
|
3674
3eaf2c673a11
provide access to $(exec_)prefix
Guido van Rossum <guido@python.org>
parents:
3621
diff
changeset
|
618 } |
|
3eaf2c673a11
provide access to $(exec_)prefix
Guido van Rossum <guido@python.org>
parents:
3621
diff
changeset
|
619 |
|
3eaf2c673a11
provide access to $(exec_)prefix
Guido van Rossum <guido@python.org>
parents:
3621
diff
changeset
|
620 char * |
|
13651
8a063423e0b7
Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
621 Py_GetExecPrefix(void) |
|
3674
3eaf2c673a11
provide access to $(exec_)prefix
Guido van Rossum <guido@python.org>
parents:
3621
diff
changeset
|
622 { |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
623 if (!module_search_path) |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
624 calculate_path(); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
625 return exec_prefix; |
|
3674
3eaf2c673a11
provide access to $(exec_)prefix
Guido van Rossum <guido@python.org>
parents:
3621
diff
changeset
|
626 } |
|
5568
139ab21d2629
Make delimiter and separator static for K&R C.
Guido van Rossum <guido@python.org>
parents:
5500
diff
changeset
|
627 |
|
139ab21d2629
Make delimiter and separator static for K&R C.
Guido van Rossum <guido@python.org>
parents:
5500
diff
changeset
|
628 char * |
|
13651
8a063423e0b7
Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
629 Py_GetProgramFullPath(void) |
|
5568
139ab21d2629
Make delimiter and separator static for K&R C.
Guido van Rossum <guido@python.org>
parents:
5500
diff
changeset
|
630 { |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
631 if (!module_search_path) |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
632 calculate_path(); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
633 return progpath; |
|
5568
139ab21d2629
Make delimiter and separator static for K&R C.
Guido van Rossum <guido@python.org>
parents:
5500
diff
changeset
|
634 } |
