Skip to content

Commit 1b05589

Browse files
Factor out is_stdlibdir().
1 parent dcfe615 commit 1b05589

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

PC/getpathp.c

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -269,25 +269,32 @@ canonicalize(wchar_t *buffer, const wchar_t *path)
269269
return _PyStatus_OK();
270270
}
271271

272+
static int
273+
is_stdlibdir(wchar_t *stdlibdir)
274+
{
275+
wchar_t *filename = stdlibdir;
276+
#ifndef LANDMARK
277+
# define LANDMARK L"os.py"
278+
#endif
279+
/* join() ensures 'landmark' can not overflow prefix if too long. */
280+
join(filename, LANDMARK);
281+
return ismodule(filename);
282+
}
272283

273284
/* assumes argv0_path is MAXPATHLEN+1 bytes long, already \0 term'd.
274285
assumption provided by only caller, calculate_path() */
275286
static int
276287
search_for_prefix(wchar_t *prefix, const wchar_t *argv0_path)
277288
{
278-
wchar_t filename[MAXPATHLEN+1];
279-
memset(filename, 0, sizeof(filename));
289+
wchar_t stdlibdir[MAXPATHLEN+1];
280290
/* Search from argv0_path, until LANDMARK is found.
281291
We guarantee 'prefix' is null terminated in bounds. */
282292
wcscpy_s(prefix, MAXPATHLEN+1, argv0_path);
283293
do {
284-
wcscpy_s(filename, Py_ARRAY_LENGTH(filename), prefix);
285-
#ifndef LANDMARK
286-
# define LANDMARK L"lib\\os.py"
287-
#endif
288-
/* join() ensures 'landmark' can not overflow prefix if too long. */
289-
join(filename, LANDMARK);
290-
if (ismodule(filename)) {
294+
memset(stdlibdir, 0, sizeof(stdlibdir));
295+
wcscpy_s(stdlibdir, Py_ARRAY_LENGTH(stdlibdir), prefix);
296+
join(stdlibdir, L"lib");
297+
if (is_stdlibdir(stdlibdir)) {
291298
return 1;
292299
}
293300
reduce(prefix);

0 commit comments

Comments
 (0)