@@ -269,25 +269,32 @@ canonicalize(wchar_t *buffer, const wchar_t *path)
269
269
return _PyStatus_OK ();
270
270
}
271
271
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
+ }
272
283
273
284
/* assumes argv0_path is MAXPATHLEN+1 bytes long, already \0 term'd.
274
285
assumption provided by only caller, calculate_path() */
275
286
static int
276
287
search_for_prefix (wchar_t * prefix , const wchar_t * argv0_path )
277
288
{
278
- wchar_t filename [MAXPATHLEN + 1 ];
279
- memset (filename , 0 , sizeof (filename ));
289
+ wchar_t stdlibdir [MAXPATHLEN + 1 ];
280
290
/* Search from argv0_path, until LANDMARK is found.
281
291
We guarantee 'prefix' is null terminated in bounds. */
282
292
wcscpy_s (prefix , MAXPATHLEN + 1 , argv0_path );
283
293
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 )) {
291
298
return 1 ;
292
299
}
293
300
reduce (prefix );
0 commit comments