annotate PC/getpathp.c @ 65035:87f4b32905df 2.7

Cosmetic fix to use print function.
author Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>
date Fri, 01 Oct 2010 10:48:47 +0000
parents fd25030223b0
children 787b969d37f0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5545
7e4228780ff8 Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
1
7e4228780ff8 Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
2 /* Return the initial module search path. */
8895
9b4bc3b8b9d4 This file's previous log message is bogus. The real change is that
Guido van Rossum <guido@python.org>
parents: 8892
diff changeset
3 /* Used by DOS, OS/2, Windows 3.1, Windows 95/98, Windows NT. */
5545
7e4228780ff8 Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
4
12116
e6ab3c603ff9 Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents: 12090
diff changeset
5 /* ----------------------------------------------------------------
e6ab3c603ff9 Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents: 12090
diff changeset
6 PATH RULES FOR WINDOWS:
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
7 This describes how sys.path is formed on Windows. It describes the
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
8 functionality, not the implementation (ie, the order in which these
12116
e6ab3c603ff9 Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents: 12090
diff changeset
9 are actually fetched is different)
e6ab3c603ff9 Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents: 12090
diff changeset
10
e6ab3c603ff9 Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents: 12090
diff changeset
11 * Python always adds an empty entry at the start, which corresponds
e6ab3c603ff9 Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents: 12090
diff changeset
12 to the current directory.
e6ab3c603ff9 Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents: 12090
diff changeset
13
35276
4adbd331d335 Fix all wrong instances of "it's".
Georg Brandl <georg@python.org>
parents: 33017
diff changeset
14 * If the PYTHONPATH env. var. exists, its entries are added next.
12116
e6ab3c603ff9 Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents: 12090
diff changeset
15
e6ab3c603ff9 Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents: 12090
diff changeset
16 * We look in the registry for "application paths" - that is, sub-keys
e6ab3c603ff9 Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents: 12090
diff changeset
17 under the main PythonPath registry key. These are added next (the
e6ab3c603ff9 Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents: 12090
diff changeset
18 order of sub-key processing is undefined).
e6ab3c603ff9 Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents: 12090
diff changeset
19 HKEY_CURRENT_USER is searched and added first.
e6ab3c603ff9 Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents: 12090
diff changeset
20 HKEY_LOCAL_MACHINE is searched and added next.
e6ab3c603ff9 Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents: 12090
diff changeset
21 (Note that all known installers only use HKLM, so HKCU is typically
e6ab3c603ff9 Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents: 12090
diff changeset
22 empty)
e6ab3c603ff9 Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents: 12090
diff changeset
23
e6ab3c603ff9 Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents: 12090
diff changeset
24 * We attempt to locate the "Python Home" - if the PYTHONHOME env var
e6ab3c603ff9 Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents: 12090
diff changeset
25 is set, we believe it. Otherwise, we use the path of our host .EXE's
12775
8e2b35d386aa Patch from M.-A. Lemburg:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 12116
diff changeset
26 to try and locate our "landmark" (lib\\os.py) and deduce our home.
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
27 - If we DO have a Python Home: The relevant sub-directories (Lib,
12116
e6ab3c603ff9 Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents: 12090
diff changeset
28 plat-win, lib-tk, etc) are based on the Python Home
e6ab3c603ff9 Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents: 12090
diff changeset
29 - If we DO NOT have a Python Home, the core Python Path is
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
30 loaded from the registry. This is the main PythonPath key,
12116
e6ab3c603ff9 Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents: 12090
diff changeset
31 and both HKLM and HKCU are combined to form the path)
e6ab3c603ff9 Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents: 12090
diff changeset
32
e6ab3c603ff9 Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents: 12090
diff changeset
33 * Iff - we can not locate the Python Home, have not had a PYTHONPATH
e6ab3c603ff9 Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents: 12090
diff changeset
34 specified, and can't locate any Registry entries (ie, we have _nothing_
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
35 we can assume is a good path), a default path with relative entries is
12116
e6ab3c603ff9 Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents: 12090
diff changeset
36 used (eg. .\Lib;.\plat-win, etc)
e6ab3c603ff9 Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents: 12090
diff changeset
37
e6ab3c603ff9 Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents: 12090
diff changeset
38
e6ab3c603ff9 Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents: 12090
diff changeset
39 The end result of all this is:
e6ab3c603ff9 Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents: 12090
diff changeset
40 * When running python.exe, or any other .exe in the main Python directory
e6ab3c603ff9 Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents: 12090
diff changeset
41 (either an installed version, or directly from the PCbuild directory),
e6ab3c603ff9 Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents: 12090
diff changeset
42 the core path is deduced, and the core paths in the registry are
e6ab3c603ff9 Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents: 12090
diff changeset
43 ignored. Other "application paths" in the registry are always read.
e6ab3c603ff9 Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents: 12090
diff changeset
44
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
45 * When Python is hosted in another exe (different directory, embedded via
12116
e6ab3c603ff9 Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents: 12090
diff changeset
46 COM, etc), the Python Home will not be deduced, so the core path from
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
47 the registry is used. Other "application paths" in the registry are
12116
e6ab3c603ff9 Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents: 12090
diff changeset
48 always read.
e6ab3c603ff9 Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents: 12090
diff changeset
49
e6ab3c603ff9 Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents: 12090
diff changeset
50 * If Python can't find its home and there is no registry (eg, frozen
e6ab3c603ff9 Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents: 12090
diff changeset
51 exe, some very strange installation setup) you get a path with
e6ab3c603ff9 Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents: 12090
diff changeset
52 some default, but relative, paths.
e6ab3c603ff9 Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents: 12090
diff changeset
53
e6ab3c603ff9 Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents: 12090
diff changeset
54 ---------------------------------------------------------------- */
e6ab3c603ff9 Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents: 12090
diff changeset
55
e6ab3c603ff9 Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents: 12090
diff changeset
56
5545
7e4228780ff8 Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
57 #include "Python.h"
7e4228780ff8 Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
58 #include "osdefs.h"
7e4228780ff8 Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
59
24071
8142f8d668a0 Patch #569753: Remove support for WIN16.
Martin v. Löwis <martin@v.loewis.de>
parents: 21712
diff changeset
60 #ifdef MS_WINDOWS
5999
f2d134bf6973 Some changes to make it work on NT; add the directory where the binary
Guido van Rossum <guido@python.org>
parents: 5545
diff changeset
61 #include <windows.h>
12116
e6ab3c603ff9 Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents: 12090
diff changeset
62 #include <tchar.h>
5999
f2d134bf6973 Some changes to make it work on NT; add the directory where the binary
Guido van Rossum <guido@python.org>
parents: 5545
diff changeset
63 #endif
f2d134bf6973 Some changes to make it work on NT; add the directory where the binary
Guido van Rossum <guido@python.org>
parents: 5545
diff changeset
64
38716
42808526511c Patch #1495999: Part two of Windows CE changes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36507
diff changeset
65 #ifdef HAVE_SYS_TYPES_H
5545
7e4228780ff8 Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
66 #include <sys/types.h>
38716
42808526511c Patch #1495999: Part two of Windows CE changes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36507
diff changeset
67 #endif /* HAVE_SYS_TYPES_H */
42808526511c Patch #1495999: Part two of Windows CE changes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36507
diff changeset
68
42808526511c Patch #1495999: Part two of Windows CE changes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36507
diff changeset
69 #ifdef HAVE_SYS_STAT_H
5545
7e4228780ff8 Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
70 #include <sys/stat.h>
38716
42808526511c Patch #1495999: Part two of Windows CE changes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36507
diff changeset
71 #endif /* HAVE_SYS_STAT_H */
42808526511c Patch #1495999: Part two of Windows CE changes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36507
diff changeset
72
5545
7e4228780ff8 Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
73 #include <string.h>
7e4228780ff8 Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
74
7e4228780ff8 Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
75 /* Search in some common locations for the associated Python libraries.
7e4228780ff8 Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
76 *
7e4228780ff8 Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
77 * Py_GetPath() tries to return a sensible Python module search path.
7e4228780ff8 Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
78 *
7407
2c54901471f5 Fix some outdated comments (mostly by removing a large comment block
Guido van Rossum <guido@python.org>
parents: 6826
diff changeset
79 * The approach is an adaptation for Windows of the strategy used in
2c54901471f5 Fix some outdated comments (mostly by removing a large comment block
Guido van Rossum <guido@python.org>
parents: 6826
diff changeset
80 * ../Modules/getpath.c; it uses the Windows Registry as one of its
2c54901471f5 Fix some outdated comments (mostly by removing a large comment block
Guido van Rossum <guido@python.org>
parents: 6826
diff changeset
81 * information sources.
5545
7e4228780ff8 Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
82 */
7e4228780ff8 Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
83
7e4228780ff8 Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
84 #ifndef LANDMARK
12775
8e2b35d386aa Patch from M.-A. Lemburg:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 12116
diff changeset
85 #define LANDMARK "lib\\os.py"
5545
7e4228780ff8 Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
86 #endif
7e4228780ff8 Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
87
7e4228780ff8 Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
88 static char prefix[MAXPATHLEN+1];
7e4228780ff8 Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
89 static char progpath[MAXPATHLEN+1];
26885
54aacb87beda PEP 302 + zipimport:
Just van Rossum <just@letterror.com>
parents: 24353
diff changeset
90 static char dllpath[MAXPATHLEN+1];
5545
7e4228780ff8 Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
91 static char *module_search_path = NULL;
7e4228780ff8 Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
92
6001
8056169ec448 Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents: 5999
diff changeset
93
5545
7e4228780ff8 Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
94 static int
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
95 is_sep(char ch) /* determine if "ch" is a separator character */
5545
7e4228780ff8 Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
96 {
7e4228780ff8 Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
97 #ifdef ALTSEP
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
98 return ch == SEP || ch == ALTSEP;
5545
7e4228780ff8 Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
99 #else
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
100 return ch == SEP;
5545
7e4228780ff8 Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
101 #endif
7e4228780ff8 Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
102 }
7e4228780ff8 Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
103
15084
9be67c5a823a Prevent possible buffer overflow exploits under Windows. As per (the very quick) patch Patch #101801.
Mark Hammond <mhammond@skippinet.com.au>
parents: 14500
diff changeset
104 /* assumes 'dir' null terminated in bounds. Never writes
9be67c5a823a Prevent possible buffer overflow exploits under Windows. As per (the very quick) patch Patch #101801.
Mark Hammond <mhammond@skippinet.com.au>
parents: 14500
diff changeset
105 beyond existing terminator.
9be67c5a823a Prevent possible buffer overflow exploits under Windows. As per (the very quick) patch Patch #101801.
Mark Hammond <mhammond@skippinet.com.au>
parents: 14500
diff changeset
106 */
5545
7e4228780ff8 Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
107 static void
13660
a1ce07218781 Miscelaneous ANSIfications. I'm assuming here 'main' should take (int,
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
108 reduce(char *dir)
5545
7e4228780ff8 Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
109 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
110 size_t i = strlen(dir);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
111 while (i > 0 && !is_sep(dir[i]))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
112 --i;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
113 dir[i] = '\0';
5545
7e4228780ff8 Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
114 }
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
115
5545
7e4228780ff8 Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
116
7e4228780ff8 Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
117 static int
13660
a1ce07218781 Miscelaneous ANSIfications. I'm assuming here 'main' should take (int,
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
118 exists(char *filename)
5545
7e4228780ff8 Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
119 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
120 struct stat buf;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
121 return stat(filename, &buf) == 0;
5545
7e4228780ff8 Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
122 }
7e4228780ff8 Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
123
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
124 /* Assumes 'filename' MAXPATHLEN+1 bytes long -
15084
9be67c5a823a Prevent possible buffer overflow exploits under Windows. As per (the very quick) patch Patch #101801.
Mark Hammond <mhammond@skippinet.com.au>
parents: 14500
diff changeset
125 may extend 'filename' by one character.
9be67c5a823a Prevent possible buffer overflow exploits under Windows. As per (the very quick) patch Patch #101801.
Mark Hammond <mhammond@skippinet.com.au>
parents: 14500
diff changeset
126 */
8902
6f73ae1cf934 Sigh. More restructuring was needed.
Guido van Rossum <guido@python.org>
parents: 8895
diff changeset
127 static int
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
128 ismodule(char *filename) /* Is module -- check for .pyc/.pyo too */
8902
6f73ae1cf934 Sigh. More restructuring was needed.
Guido van Rossum <guido@python.org>
parents: 8895
diff changeset
129 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
130 if (exists(filename))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
131 return 1;
8902
6f73ae1cf934 Sigh. More restructuring was needed.
Guido van Rossum <guido@python.org>
parents: 8895
diff changeset
132
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
133 /* Check for the compiled version of prefix. */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
134 if (strlen(filename) < MAXPATHLEN) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
135 strcat(filename, Py_OptimizeFlag ? "o" : "c");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
136 if (exists(filename))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
137 return 1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
138 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
139 return 0;
8902
6f73ae1cf934 Sigh. More restructuring was needed.
Guido van Rossum <guido@python.org>
parents: 8895
diff changeset
140 }
6f73ae1cf934 Sigh. More restructuring was needed.
Guido van Rossum <guido@python.org>
parents: 8895
diff changeset
141
33017
ab93aff4c90a SF bug 1003471: Python 1.5.2 security vulnerability
Tim Peters <tim.peters@gmail.com>
parents: 30180
diff changeset
142 /* Add a path component, by appending stuff to buffer.
ab93aff4c90a SF bug 1003471: Python 1.5.2 security vulnerability
Tim Peters <tim.peters@gmail.com>
parents: 30180
diff changeset
143 buffer must have at least MAXPATHLEN + 1 bytes allocated, and contain a
ab93aff4c90a SF bug 1003471: Python 1.5.2 security vulnerability
Tim Peters <tim.peters@gmail.com>
parents: 30180
diff changeset
144 NUL-terminated string with no more than MAXPATHLEN characters (not counting
ab93aff4c90a SF bug 1003471: Python 1.5.2 security vulnerability
Tim Peters <tim.peters@gmail.com>
parents: 30180
diff changeset
145 the trailing NUL). It's a fatal error if it contains a string longer than
ab93aff4c90a SF bug 1003471: Python 1.5.2 security vulnerability
Tim Peters <tim.peters@gmail.com>
parents: 30180
diff changeset
146 that (callers must be careful!). If these requirements are met, it's
ab93aff4c90a SF bug 1003471: Python 1.5.2 security vulnerability
Tim Peters <tim.peters@gmail.com>
parents: 30180
diff changeset
147 guaranteed that buffer will still be a NUL-terminated string with no more
ab93aff4c90a SF bug 1003471: Python 1.5.2 security vulnerability
Tim Peters <tim.peters@gmail.com>
parents: 30180
diff changeset
148 than MAXPATHLEN characters at exit. If stuff is too long, only as much of
ab93aff4c90a SF bug 1003471: Python 1.5.2 security vulnerability
Tim Peters <tim.peters@gmail.com>
parents: 30180
diff changeset
149 stuff as fits will be appended.
ab93aff4c90a SF bug 1003471: Python 1.5.2 security vulnerability
Tim Peters <tim.peters@gmail.com>
parents: 30180
diff changeset
150 */
5545
7e4228780ff8 Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
151 static void
13660
a1ce07218781 Miscelaneous ANSIfications. I'm assuming here 'main' should take (int,
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
152 join(char *buffer, char *stuff)
5545
7e4228780ff8 Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
153 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
154 size_t n, k;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
155 if (is_sep(stuff[0]))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
156 n = 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
157 else {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
158 n = strlen(buffer);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
159 if (n > 0 && !is_sep(buffer[n-1]) && n < MAXPATHLEN)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
160 buffer[n++] = SEP;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
161 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
162 if (n > MAXPATHLEN)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
163 Py_FatalError("buffer overflow in getpathp.c's joinpath()");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
164 k = strlen(stuff);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
165 if (n + k > MAXPATHLEN)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
166 k = MAXPATHLEN - n;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
167 strncpy(buffer+n, stuff, k);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
168 buffer[n+k] = '\0';
5545
7e4228780ff8 Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
169 }
7e4228780ff8 Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
170
15084
9be67c5a823a Prevent possible buffer overflow exploits under Windows. As per (the very quick) patch Patch #101801.
Mark Hammond <mhammond@skippinet.com.au>
parents: 14500
diff changeset
171 /* gotlandmark only called by search_for_prefix, which ensures
9be67c5a823a Prevent possible buffer overflow exploits under Windows. As per (the very quick) patch Patch #101801.
Mark Hammond <mhammond@skippinet.com.au>
parents: 14500
diff changeset
172 'prefix' is null terminated in bounds. join() ensures
9be67c5a823a Prevent possible buffer overflow exploits under Windows. As per (the very quick) patch Patch #101801.
Mark Hammond <mhammond@skippinet.com.au>
parents: 14500
diff changeset
173 'landmark' can not overflow prefix if too long.
9be67c5a823a Prevent possible buffer overflow exploits under Windows. As per (the very quick) patch Patch #101801.
Mark Hammond <mhammond@skippinet.com.au>
parents: 14500
diff changeset
174 */
5545
7e4228780ff8 Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
175 static int
13660
a1ce07218781 Miscelaneous ANSIfications. I'm assuming here 'main' should take (int,
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
176 gotlandmark(char *landmark)
12090
9877e978170e Changes to completely ignore the registry when it detects that you are
Guido van Rossum <guido@python.org>
parents: 8967
diff changeset
177 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
178 int ok;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
179 Py_ssize_t n;
12090
9877e978170e Changes to completely ignore the registry when it detects that you are
Guido van Rossum <guido@python.org>
parents: 8967
diff changeset
180
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
181 n = strlen(prefix);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
182 join(prefix, landmark);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
183 ok = ismodule(prefix);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
184 prefix[n] = '\0';
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
185 return ok;
12090
9877e978170e Changes to completely ignore the registry when it detects that you are
Guido van Rossum <guido@python.org>
parents: 8967
diff changeset
186 }
9877e978170e Changes to completely ignore the registry when it detects that you are
Guido van Rossum <guido@python.org>
parents: 8967
diff changeset
187
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
188 /* assumes argv0_path is MAXPATHLEN+1 bytes long, already \0 term'd.
15084
9be67c5a823a Prevent possible buffer overflow exploits under Windows. As per (the very quick) patch Patch #101801.
Mark Hammond <mhammond@skippinet.com.au>
parents: 14500
diff changeset
189 assumption provided by only caller, calculate_path() */
12090
9877e978170e Changes to completely ignore the registry when it detects that you are
Guido van Rossum <guido@python.org>
parents: 8967
diff changeset
190 static int
13660
a1ce07218781 Miscelaneous ANSIfications. I'm assuming here 'main' should take (int,
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
191 search_for_prefix(char *argv0_path, char *landmark)
5545
7e4228780ff8 Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
192 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
193 /* Search from argv0_path, until landmark is found */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
194 strcpy(prefix, argv0_path);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
195 do {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
196 if (gotlandmark(landmark))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
197 return 1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
198 reduce(prefix);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
199 } while (prefix[0]);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
200 return 0;
5545
7e4228780ff8 Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
201 }
7e4228780ff8 Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
202
24071
8142f8d668a0 Patch #569753: Remove support for WIN16.
Martin v. Löwis <martin@v.loewis.de>
parents: 21712
diff changeset
203 #ifdef MS_WINDOWS
51262
2adf9ed6ba7e Merged revisions 69205 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 41460
diff changeset
204 #ifdef Py_ENABLE_SHARED
8902
6f73ae1cf934 Sigh. More restructuring was needed.
Guido van Rossum <guido@python.org>
parents: 8895
diff changeset
205
12116
e6ab3c603ff9 Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents: 12090
diff changeset
206 /* a string loaded from the DLL at startup.*/
e6ab3c603ff9 Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents: 12090
diff changeset
207 extern const char *PyWin_DLLVersionString;
6356
a857d2f87336 Seem to be some changes related to DLL version from string resource,
Guido van Rossum <guido@python.org>
parents: 6001
diff changeset
208
6001
8056169ec448 Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents: 5999
diff changeset
209
8056169ec448 Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents: 5999
diff changeset
210 /* Load a PYTHONPATH value from the registry.
8056169ec448 Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents: 5999
diff changeset
211 Load from either HKEY_LOCAL_MACHINE or HKEY_CURRENT_USER.
8056169ec448 Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents: 5999
diff changeset
212
12116
e6ab3c603ff9 Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents: 12090
diff changeset
213 Works in both Unicode and 8bit environments. Only uses the
e6ab3c603ff9 Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents: 12090
diff changeset
214 Ex family of functions so it also works with Windows CE.
e6ab3c603ff9 Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents: 12090
diff changeset
215
6001
8056169ec448 Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents: 5999
diff changeset
216 Returns NULL, or a pointer that should be freed.
16748
e444a5271181 Checkin updated version of patch #103933 . As Thomas says, fixes the bugs #131064, #129584, #127722. See the discussion in bug #131064
Mark Hammond <mhammond@skippinet.com.au>
parents: 15084
diff changeset
217
e444a5271181 Checkin updated version of patch #103933 . As Thomas says, fixes the bugs #131064, #129584, #127722. See the discussion in bug #131064
Mark Hammond <mhammond@skippinet.com.au>
parents: 15084
diff changeset
218 XXX - this code is pretty strange, as it used to also
e444a5271181 Checkin updated version of patch #103933 . As Thomas says, fixes the bugs #131064, #129584, #127722. See the discussion in bug #131064
Mark Hammond <mhammond@skippinet.com.au>
parents: 15084
diff changeset
219 work on Win16, where the buffer sizes werent available
e444a5271181 Checkin updated version of patch #103933 . As Thomas says, fixes the bugs #131064, #129584, #127722. See the discussion in bug #131064
Mark Hammond <mhammond@skippinet.com.au>
parents: 15084
diff changeset
220 in advance. It could be simplied now Win16/Win32s is dead!
6001
8056169ec448 Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents: 5999
diff changeset
221 */
8056169ec448 Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents: 5999
diff changeset
222
8056169ec448 Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents: 5999
diff changeset
223 static char *
12116
e6ab3c603ff9 Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents: 12090
diff changeset
224 getpythonregpath(HKEY keyBase, int skipcore)
6001
8056169ec448 Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents: 5999
diff changeset
225 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
226 HKEY newKey = 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
227 DWORD dataSize = 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
228 DWORD numKeys = 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
229 LONG rc;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
230 char *retval = NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
231 TCHAR *dataBuf = NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
232 static const TCHAR keyPrefix[] = _T("Software\\Python\\PythonCore\\");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
233 static const TCHAR keySuffix[] = _T("\\PythonPath");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
234 size_t versionLen;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
235 DWORD index;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
236 TCHAR *keyBuf = NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
237 TCHAR *keyBufPtr;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
238 TCHAR **ppPaths = NULL;
12116
e6ab3c603ff9 Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents: 12090
diff changeset
239
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
240 /* Tried to use sysget("winver") but here is too early :-( */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
241 versionLen = _tcslen(PyWin_DLLVersionString);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
242 /* Space for all the chars, plus one \0 */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
243 keyBuf = keyBufPtr = malloc(sizeof(keyPrefix) +
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
244 sizeof(TCHAR)*(versionLen-1) +
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
245 sizeof(keySuffix));
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
246 if (keyBuf==NULL) goto done;
6356
a857d2f87336 Seem to be some changes related to DLL version from string resource,
Guido van Rossum <guido@python.org>
parents: 6001
diff changeset
247
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
248 memcpy(keyBufPtr, keyPrefix, sizeof(keyPrefix)-sizeof(TCHAR));
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
249 keyBufPtr += sizeof(keyPrefix)/sizeof(TCHAR) - 1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
250 memcpy(keyBufPtr, PyWin_DLLVersionString, versionLen * sizeof(TCHAR));
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
251 keyBufPtr += versionLen;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
252 /* NULL comes with this one! */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
253 memcpy(keyBufPtr, keySuffix, sizeof(keySuffix));
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
254 /* Open the root Python key */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
255 rc=RegOpenKeyEx(keyBase,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
256 keyBuf, /* subkey */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
257 0, /* reserved */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
258 KEY_READ,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
259 &newKey);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
260 if (rc!=ERROR_SUCCESS) goto done;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
261 /* Find out how big our core buffer is, and how many subkeys we have */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
262 rc = RegQueryInfoKey(newKey, NULL, NULL, NULL, &numKeys, NULL, NULL,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
263 NULL, NULL, &dataSize, NULL, NULL);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
264 if (rc!=ERROR_SUCCESS) goto done;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
265 if (skipcore) dataSize = 0; /* Only count core ones if we want them! */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
266 /* Allocate a temp array of char buffers, so we only need to loop
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
267 reading the registry once
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
268 */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
269 ppPaths = malloc( sizeof(TCHAR *) * numKeys );
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
270 if (ppPaths==NULL) goto done;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
271 memset(ppPaths, 0, sizeof(TCHAR *) * numKeys);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
272 /* Loop over all subkeys, allocating a temp sub-buffer. */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
273 for(index=0;index<numKeys;index++) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
274 TCHAR keyBuf[MAX_PATH+1];
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
275 HKEY subKey = 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
276 DWORD reqdSize = MAX_PATH+1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
277 /* Get the sub-key name */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
278 DWORD rc = RegEnumKeyEx(newKey, index, keyBuf, &reqdSize,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
279 NULL, NULL, NULL, NULL );
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
280 if (rc!=ERROR_SUCCESS) goto done;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
281 /* Open the sub-key */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
282 rc=RegOpenKeyEx(newKey,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
283 keyBuf, /* subkey */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
284 0, /* reserved */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
285 KEY_READ,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
286 &subKey);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
287 if (rc!=ERROR_SUCCESS) goto done;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
288 /* Find the value of the buffer size, malloc, then read it */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
289 RegQueryValueEx(subKey, NULL, 0, NULL, NULL, &reqdSize);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
290 if (reqdSize) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
291 ppPaths[index] = malloc(reqdSize);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
292 if (ppPaths[index]) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
293 RegQueryValueEx(subKey, NULL, 0, NULL,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
294 (LPBYTE)ppPaths[index],
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
295 &reqdSize);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
296 dataSize += reqdSize + 1; /* 1 for the ";" */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
297 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
298 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
299 RegCloseKey(subKey);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
300 }
39158
a4fc4e752634 Patch #1232023: Don't include empty path component from registry,
Martin v. Löwis <martin@v.loewis.de>
parents: 38716
diff changeset
301
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
302 /* return null if no path to return */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
303 if (dataSize == 0) goto done;
39158
a4fc4e752634 Patch #1232023: Don't include empty path component from registry,
Martin v. Löwis <martin@v.loewis.de>
parents: 38716
diff changeset
304
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
305 /* original datasize from RegQueryInfo doesn't include the \0 */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
306 dataBuf = malloc((dataSize+1) * sizeof(TCHAR));
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
307 if (dataBuf) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
308 TCHAR *szCur = dataBuf;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
309 DWORD reqdSize = dataSize;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
310 /* Copy our collected strings */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
311 for (index=0;index<numKeys;index++) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
312 if (index > 0) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
313 *(szCur++) = _T(';');
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
314 dataSize--;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
315 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
316 if (ppPaths[index]) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
317 Py_ssize_t len = _tcslen(ppPaths[index]);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
318 _tcsncpy(szCur, ppPaths[index], len);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
319 szCur += len;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
320 assert(dataSize > (DWORD)len);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
321 dataSize -= (DWORD)len;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
322 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
323 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
324 if (skipcore)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
325 *szCur = '\0';
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
326 else {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
327 /* If we have no values, we dont need a ';' */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
328 if (numKeys) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
329 *(szCur++) = _T(';');
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
330 dataSize--;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
331 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
332 /* Now append the core path entries -
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
333 this will include the NULL
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
334 */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
335 rc = RegQueryValueEx(newKey, NULL, 0, NULL,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
336 (LPBYTE)szCur, &dataSize);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
337 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
338 /* And set the result - caller must free
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
339 If MBCS, it is fine as is. If Unicode, allocate new
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
340 buffer and convert.
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
341 */
12116
e6ab3c603ff9 Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents: 12090
diff changeset
342 #ifdef UNICODE
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
343 retval = (char *)malloc(reqdSize+1);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
344 if (retval)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
345 WideCharToMultiByte(CP_ACP, 0,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
346 dataBuf, -1, /* source */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
347 retval, reqdSize+1, /* dest */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
348 NULL, NULL);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
349 free(dataBuf);
12116
e6ab3c603ff9 Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents: 12090
diff changeset
350 #else
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
351 retval = dataBuf;
12116
e6ab3c603ff9 Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents: 12090
diff changeset
352 #endif
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
353 }
12116
e6ab3c603ff9 Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents: 12090
diff changeset
354 done:
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
355 /* Loop freeing my temp buffers */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
356 if (ppPaths) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
357 for(index=0;index<numKeys;index++)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
358 if (ppPaths[index]) free(ppPaths[index]);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
359 free(ppPaths);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
360 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
361 if (newKey)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
362 RegCloseKey(newKey);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
363 if (keyBuf)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
364 free(keyBuf);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
365 return retval;
6001
8056169ec448 Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents: 5999
diff changeset
366 }
51262
2adf9ed6ba7e Merged revisions 69205 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 41460
diff changeset
367 #endif /* Py_ENABLE_SHARED */
24071
8142f8d668a0 Patch #569753: Remove support for WIN16.
Martin v. Löwis <martin@v.loewis.de>
parents: 21712
diff changeset
368 #endif /* MS_WINDOWS */
6001
8056169ec448 Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents: 5999
diff changeset
369
5545
7e4228780ff8 Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
370 static void
13660
a1ce07218781 Miscelaneous ANSIfications. I'm assuming here 'main' should take (int,
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
371 get_progpath(void)
5545
7e4228780ff8 Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
372 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
373 extern char *Py_GetProgramName(void);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
374 char *path = getenv("PATH");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
375 char *prog = Py_GetProgramName();
5545
7e4228780ff8 Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
376
24071
8142f8d668a0 Patch #569753: Remove support for WIN16.
Martin v. Löwis <martin@v.loewis.de>
parents: 21712
diff changeset
377 #ifdef MS_WINDOWS
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
378 extern HANDLE PyWin_DLLhModule;
12116
e6ab3c603ff9 Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents: 12090
diff changeset
379 #ifdef UNICODE
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
380 WCHAR wprogpath[MAXPATHLEN+1];
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
381 /* Windows documents that GetModuleFileName() will "truncate",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
382 but makes no mention of the null terminator. Play it safe.
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
383 PLUS Windows itself defines MAX_PATH as the same, but anyway...
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
384 */
51262
2adf9ed6ba7e Merged revisions 69205 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 41460
diff changeset
385 #ifdef Py_ENABLE_SHARED
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
386 wprogpath[MAXPATHLEN]=_T('\0');
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
387 if (PyWin_DLLhModule &&
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
388 GetModuleFileName(PyWin_DLLhModule, wprogpath, MAXPATHLEN)) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
389 WideCharToMultiByte(CP_ACP, 0,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
390 wprogpath, -1,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
391 dllpath, MAXPATHLEN+1,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
392 NULL, NULL);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
393 }
51262
2adf9ed6ba7e Merged revisions 69205 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 41460
diff changeset
394 #else
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
395 dllpath[0] = 0;
51262
2adf9ed6ba7e Merged revisions 69205 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 41460
diff changeset
396 #endif
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
397 wprogpath[MAXPATHLEN]=_T('\0');
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
398 if (GetModuleFileName(NULL, wprogpath, MAXPATHLEN)) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
399 WideCharToMultiByte(CP_ACP, 0,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
400 wprogpath, -1,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
401 progpath, MAXPATHLEN+1,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
402 NULL, NULL);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
403 return;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
404 }
12116
e6ab3c603ff9 Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents: 12090
diff changeset
405 #else
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
406 /* static init of progpath ensures final char remains \0 */
51262
2adf9ed6ba7e Merged revisions 69205 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 41460
diff changeset
407 #ifdef Py_ENABLE_SHARED
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
408 if (PyWin_DLLhModule)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
409 if (!GetModuleFileName(PyWin_DLLhModule, dllpath, MAXPATHLEN))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
410 dllpath[0] = 0;
51262
2adf9ed6ba7e Merged revisions 69205 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 41460
diff changeset
411 #else
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
412 dllpath[0] = 0;
51262
2adf9ed6ba7e Merged revisions 69205 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 41460
diff changeset
413 #endif
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
414 if (GetModuleFileName(NULL, progpath, MAXPATHLEN))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
415 return;
6001
8056169ec448 Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents: 5999
diff changeset
416 #endif
12116
e6ab3c603ff9 Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents: 12090
diff changeset
417 #endif
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
418 if (prog == NULL || *prog == '\0')
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
419 prog = "python";
6001
8056169ec448 Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents: 5999
diff changeset
420
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
421 /* If there is no slash in the argv0 path, then we have to
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
422 * assume python is on the user's $PATH, since there's no
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
423 * other way to find a directory to start the search from. If
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
424 * $PATH isn't exported, you lose.
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
425 */
5545
7e4228780ff8 Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
426 #ifdef ALTSEP
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
427 if (strchr(prog, SEP) || strchr(prog, ALTSEP))
5545
7e4228780ff8 Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
428 #else
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
429 if (strchr(prog, SEP))
5545
7e4228780ff8 Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
430 #endif
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
431 strncpy(progpath, prog, MAXPATHLEN);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
432 else if (path) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
433 while (1) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
434 char *delim = strchr(path, DELIM);
5545
7e4228780ff8 Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
435
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
436 if (delim) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
437 size_t len = delim - path;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
438 /* ensure we can't overwrite buffer */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
439 len = min(MAXPATHLEN,len);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
440 strncpy(progpath, path, len);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
441 *(progpath + len) = '\0';
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
442 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
443 else
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
444 strncpy(progpath, path, MAXPATHLEN);
5545
7e4228780ff8 Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
445
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
446 /* join() is safe for MAXPATHLEN+1 size buffer */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
447 join(progpath, prog);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
448 if (exists(progpath))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
449 break;
5545
7e4228780ff8 Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
450
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
451 if (!delim) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
452 progpath[0] = '\0';
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
453 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
454 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
455 path = delim + 1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
456 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
457 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
458 else
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
459 progpath[0] = '\0';
5545
7e4228780ff8 Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
460 }
7e4228780ff8 Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
461
7e4228780ff8 Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
462 static void
13660
a1ce07218781 Miscelaneous ANSIfications. I'm assuming here 'main' should take (int,
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
463 calculate_path(void)
5545
7e4228780ff8 Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
464 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
465 char argv0_path[MAXPATHLEN+1];
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
466 char *buf;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
467 size_t bufsz;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
468 char *pythonhome = Py_GetPythonHome();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
469 char *envpath = Py_GETENV("PYTHONPATH");
8902
6f73ae1cf934 Sigh. More restructuring was needed.
Guido van Rossum <guido@python.org>
parents: 8895
diff changeset
470
24071
8142f8d668a0 Patch #569753: Remove support for WIN16.
Martin v. Löwis <martin@v.loewis.de>
parents: 21712
diff changeset
471 #ifdef MS_WINDOWS
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
472 int skiphome, skipdefault;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
473 char *machinepath = NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
474 char *userpath = NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
475 char zip_path[MAXPATHLEN+1];
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
476 size_t len;
6001
8056169ec448 Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents: 5999
diff changeset
477 #endif
5545
7e4228780ff8 Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
478
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
479 get_progpath();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
480 /* progpath guaranteed \0 terminated in MAXPATH+1 bytes. */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
481 strcpy(argv0_path, progpath);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
482 reduce(argv0_path);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
483 if (pythonhome == NULL || *pythonhome == '\0') {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
484 if (search_for_prefix(argv0_path, LANDMARK))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
485 pythonhome = prefix;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
486 else
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
487 pythonhome = NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
488 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
489 else
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
490 strncpy(prefix, pythonhome, MAXPATHLEN);
5545
7e4228780ff8 Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
491
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
492 if (envpath && *envpath == '\0')
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
493 envpath = NULL;
6001
8056169ec448 Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents: 5999
diff changeset
494
12090
9877e978170e Changes to completely ignore the registry when it detects that you are
Guido van Rossum <guido@python.org>
parents: 8967
diff changeset
495
24071
8142f8d668a0 Patch #569753: Remove support for WIN16.
Martin v. Löwis <martin@v.loewis.de>
parents: 21712
diff changeset
496 #ifdef MS_WINDOWS
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
497 /* Calculate zip archive path */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
498 if (dllpath[0]) /* use name of python DLL */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
499 strncpy(zip_path, dllpath, MAXPATHLEN);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
500 else /* use name of executable program */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
501 strncpy(zip_path, progpath, MAXPATHLEN);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
502 zip_path[MAXPATHLEN] = '\0';
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
503 len = strlen(zip_path);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
504 if (len > 4) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
505 zip_path[len-3] = 'z'; /* change ending to "zip" */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
506 zip_path[len-2] = 'i';
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
507 zip_path[len-1] = 'p';
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
508 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
509 else {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
510 zip_path[0] = 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
511 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
512
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
513 skiphome = pythonhome==NULL ? 0 : 1;
51262
2adf9ed6ba7e Merged revisions 69205 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 41460
diff changeset
514 #ifdef Py_ENABLE_SHARED
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
515 machinepath = getpythonregpath(HKEY_LOCAL_MACHINE, skiphome);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
516 userpath = getpythonregpath(HKEY_CURRENT_USER, skiphome);
51262
2adf9ed6ba7e Merged revisions 69205 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 41460
diff changeset
517 #endif
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
518 /* We only use the default relative PYTHONPATH if we havent
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
519 anything better to use! */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
520 skipdefault = envpath!=NULL || pythonhome!=NULL || \
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
521 machinepath!=NULL || userpath!=NULL;
8902
6f73ae1cf934 Sigh. More restructuring was needed.
Guido van Rossum <guido@python.org>
parents: 8895
diff changeset
522 #endif
6f73ae1cf934 Sigh. More restructuring was needed.
Guido van Rossum <guido@python.org>
parents: 8895
diff changeset
523
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
524 /* We need to construct a path from the following parts.
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
525 (1) the PYTHONPATH environment variable, if set;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
526 (2) for Win32, the zip archive file path;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
527 (3) for Win32, the machinepath and userpath, if set;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
528 (4) the PYTHONPATH config macro, with the leading "."
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
529 of each component replaced with pythonhome, if set;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
530 (5) the directory containing the executable (argv0_path).
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
531 The length calculation calculates #4 first.
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
532 Extra rules:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
533 - If PYTHONHOME is set (in any way) item (3) is ignored.
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
534 - If registry values are used, (4) and (5) are ignored.
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
535 */
6001
8056169ec448 Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents: 5999
diff changeset
536
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
537 /* Calculate size of return buffer */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
538 if (pythonhome != NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
539 char *p;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
540 bufsz = 1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
541 for (p = PYTHONPATH; *p; p++) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
542 if (*p == DELIM)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
543 bufsz++; /* number of DELIM plus one */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
544 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
545 bufsz *= strlen(pythonhome);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
546 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
547 else
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
548 bufsz = 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
549 bufsz += strlen(PYTHONPATH) + 1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
550 bufsz += strlen(argv0_path) + 1;
24071
8142f8d668a0 Patch #569753: Remove support for WIN16.
Martin v. Löwis <martin@v.loewis.de>
parents: 21712
diff changeset
551 #ifdef MS_WINDOWS
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
552 if (userpath)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
553 bufsz += strlen(userpath) + 1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
554 if (machinepath)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
555 bufsz += strlen(machinepath) + 1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
556 bufsz += strlen(zip_path) + 1;
6001
8056169ec448 Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents: 5999
diff changeset
557 #endif
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
558 if (envpath != NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
559 bufsz += strlen(envpath) + 1;
6001
8056169ec448 Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents: 5999
diff changeset
560
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
561 module_search_path = buf = malloc(bufsz);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
562 if (buf == NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
563 /* We can't exit, so print a warning and limp along */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
564 fprintf(stderr, "Can't malloc dynamic PYTHONPATH.\n");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
565 if (envpath) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
566 fprintf(stderr, "Using environment $PYTHONPATH.\n");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
567 module_search_path = envpath;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
568 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
569 else {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
570 fprintf(stderr, "Using default static path.\n");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
571 module_search_path = PYTHONPATH;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
572 }
24071
8142f8d668a0 Patch #569753: Remove support for WIN16.
Martin v. Löwis <martin@v.loewis.de>
parents: 21712
diff changeset
573 #ifdef MS_WINDOWS
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
574 if (machinepath)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
575 free(machinepath);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
576 if (userpath)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
577 free(userpath);
24071
8142f8d668a0 Patch #569753: Remove support for WIN16.
Martin v. Löwis <martin@v.loewis.de>
parents: 21712
diff changeset
578 #endif /* MS_WINDOWS */
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
579 return;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
580 }
6001
8056169ec448 Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents: 5999
diff changeset
581
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
582 if (envpath) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
583 strcpy(buf, envpath);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
584 buf = strchr(buf, '\0');
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
585 *buf++ = DELIM;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
586 }
24071
8142f8d668a0 Patch #569753: Remove support for WIN16.
Martin v. Löwis <martin@v.loewis.de>
parents: 21712
diff changeset
587 #ifdef MS_WINDOWS
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
588 if (zip_path[0]) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
589 strcpy(buf, zip_path);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
590 buf = strchr(buf, '\0');
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
591 *buf++ = DELIM;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
592 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
593 if (userpath) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
594 strcpy(buf, userpath);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
595 buf = strchr(buf, '\0');
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
596 *buf++ = DELIM;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
597 free(userpath);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
598 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
599 if (machinepath) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
600 strcpy(buf, machinepath);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
601 buf = strchr(buf, '\0');
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
602 *buf++ = DELIM;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
603 free(machinepath);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
604 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
605 if (pythonhome == NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
606 if (!skipdefault) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
607 strcpy(buf, PYTHONPATH);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
608 buf = strchr(buf, '\0');
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
609 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
610 }
12116
e6ab3c603ff9 Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents: 12090
diff changeset
611 #else
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
612 if (pythonhome == NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
613 strcpy(buf, PYTHONPATH);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
614 buf = strchr(buf, '\0');
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
615 }
24071
8142f8d668a0 Patch #569753: Remove support for WIN16.
Martin v. Löwis <martin@v.loewis.de>
parents: 21712
diff changeset
616 #endif /* MS_WINDOWS */
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
617 else {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
618 char *p = PYTHONPATH;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
619 char *q;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
620 size_t n;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
621 for (;;) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
622 q = strchr(p, DELIM);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
623 if (q == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
624 n = strlen(p);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
625 else
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
626 n = q-p;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
627 if (p[0] == '.' && is_sep(p[1])) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
628 strcpy(buf, pythonhome);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
629 buf = strchr(buf, '\0');
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
630 p++;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
631 n--;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
632 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
633 strncpy(buf, p, n);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
634 buf += n;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
635 if (q == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
636 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
637 *buf++ = DELIM;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
638 p = q+1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
639 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
640 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
641 if (argv0_path) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
642 *buf++ = DELIM;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
643 strcpy(buf, argv0_path);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
644 buf = strchr(buf, '\0');
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
645 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
646 *buf = '\0';
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
647 /* Now to pull one last hack/trick. If sys.prefix is
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
648 empty, then try and find it somewhere on the paths
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
649 we calculated. We scan backwards, as our general policy
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
650 is that Python core directories are at the *end* of
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
651 sys.path. We assume that our "lib" directory is
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
652 on the path, and that our 'prefix' directory is
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
653 the parent of that.
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
654 */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
655 if (*prefix=='\0') {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
656 char lookBuf[MAXPATHLEN+1];
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
657 char *look = buf - 1; /* 'buf' is at the end of the buffer */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
658 while (1) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
659 Py_ssize_t nchars;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
660 char *lookEnd = look;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
661 /* 'look' will end up one character before the
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
662 start of the path in question - even if this
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
663 is one character before the start of the buffer
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
664 */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
665 while (look >= module_search_path && *look != DELIM)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
666 look--;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
667 nchars = lookEnd-look;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
668 strncpy(lookBuf, look+1, nchars);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
669 lookBuf[nchars] = '\0';
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
670 /* Up one level to the parent */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
671 reduce(lookBuf);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
672 if (search_for_prefix(lookBuf, LANDMARK)) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
673 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
674 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
675 /* If we are out of paths to search - give up */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
676 if (look < module_search_path)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
677 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
678 look--;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
679 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
680 }
5545
7e4228780ff8 Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
681 }
7e4228780ff8 Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
682
7e4228780ff8 Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
683
7e4228780ff8 Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
684 /* External interface */
7e4228780ff8 Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
685
7e4228780ff8 Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
686 char *
13660
a1ce07218781 Miscelaneous ANSIfications. I'm assuming here 'main' should take (int,
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
687 Py_GetPath(void)
5545
7e4228780ff8 Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
688 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
689 if (!module_search_path)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
690 calculate_path();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
691 return module_search_path;
5545
7e4228780ff8 Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
692 }
7e4228780ff8 Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
693
7e4228780ff8 Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
694 char *
13660
a1ce07218781 Miscelaneous ANSIfications. I'm assuming here 'main' should take (int,
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
695 Py_GetPrefix(void)
5545
7e4228780ff8 Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
696 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
697 if (!module_search_path)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
698 calculate_path();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
699 return prefix;
5545
7e4228780ff8 Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
700 }
7e4228780ff8 Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
701
7e4228780ff8 Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
702 char *
13660
a1ce07218781 Miscelaneous ANSIfications. I'm assuming here 'main' should take (int,
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
703 Py_GetExecPrefix(void)
5545
7e4228780ff8 Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
704 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
705 return Py_GetPrefix();
5545
7e4228780ff8 Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
706 }
7e4228780ff8 Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
707
7e4228780ff8 Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
708 char *
13660
a1ce07218781 Miscelaneous ANSIfications. I'm assuming here 'main' should take (int,
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
709 Py_GetProgramFullPath(void)
5545
7e4228780ff8 Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
710 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
711 if (!module_search_path)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
712 calculate_path();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 51262
diff changeset
713 return progpath;
5545
7e4228780ff8 Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
714 }