Changeset 388 for python/vendor/current/Modules/getpath.c
- Timestamp:
- Mar 19, 2014, 11:11:30 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
python/vendor/current/Modules/getpath.c
r2 r388 217 217 } 218 218 if (n > MAXPATHLEN) 219 219 Py_FatalError("buffer overflow in getpath.c's joinpath()"); 220 220 k = strlen(stuff); 221 221 if (n + k > MAXPATHLEN) … … 233 233 strcpy(path, p); 234 234 else { 235 getcwd(path, MAXPATHLEN); 235 if (!getcwd(path, MAXPATHLEN)) { 236 /* unable to get the current directory */ 237 strcpy(path, p); 238 return; 239 } 236 240 if (p[0] == '.' && p[1] == SEP) 237 241 p += 2; … … 332 336 } 333 337 334 /* Check to see if argv[0] is in the build directory */ 338 /* Check to see if argv[0] is in the build directory. "pybuilddir.txt" 339 is written by setup.py and contains the relative path to the location 340 of shared library modules. */ 335 341 strcpy(exec_prefix, argv0_path); 336 joinpath(exec_prefix, " Modules/Setup");342 joinpath(exec_prefix, "pybuilddir.txt"); 337 343 if (isfile(exec_prefix)) { 338 reduce(exec_prefix); 339 return -1; 344 FILE *f = fopen(exec_prefix, "r"); 345 if (f == NULL) 346 errno = 0; 347 else { 348 char rel_builddir_path[MAXPATHLEN+1]; 349 size_t n; 350 n = fread(rel_builddir_path, 1, MAXPATHLEN, f); 351 rel_builddir_path[n] = '\0'; 352 fclose(f); 353 if (n >= 0) { 354 strcpy(exec_prefix, argv0_path); 355 joinpath(exec_prefix, rel_builddir_path); 356 return -1; 357 } 358 } 340 359 } 341 360 … … 394 413 #endif 395 414 396 397 398 399 400 401 402 415 /* If there is no slash in the argv0 path, then we have to 416 * assume python is on the user's $PATH, since there's no 417 * other way to find a directory to start the search from. If 418 * $PATH isn't exported, you lose. 419 */ 420 if (strchr(prog, SEP)) 421 strncpy(progpath, prog, MAXPATHLEN); 403 422 #ifdef __APPLE__ 404 423 /* On Mac OS X, if a script uses an interpreter of the form … … 415 434 ; 416 435 #endif /* __APPLE__ */ 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 if (progpath[0] != SEP)445 446 447 436 else if (path) { 437 while (1) { 438 char *delim = strchr(path, DELIM); 439 440 if (delim) { 441 size_t len = delim - path; 442 if (len > MAXPATHLEN) 443 len = MAXPATHLEN; 444 strncpy(progpath, path, len); 445 *(progpath + len) = '\0'; 446 } 447 else 448 strncpy(progpath, path, MAXPATHLEN); 449 450 joinpath(progpath, prog); 451 if (isxfile(progpath)) 452 break; 453 454 if (!delim) { 455 progpath[0] = '\0'; 456 break; 457 } 458 path = delim + 1; 459 } 460 } 461 else 462 progpath[0] = '\0'; 463 if (progpath[0] != SEP && progpath[0] != '\0') 464 absolutize(progpath); 465 strncpy(argv0_path, progpath, MAXPATHLEN); 466 argv0_path[MAXPATHLEN] = '\0'; 448 467 449 468 #ifdef WITH_NEXT_FRAMEWORK 450 451 452 453 454 469 /* On Mac OS X we have a special case if we're running from a framework. 470 ** This is because the python home should be set relative to the library, 471 ** which is in the framework, not relative to the executable, which may 472 ** be outside of the framework. Except when we're in the build directory... 473 */ 455 474 pythonModule = NSModuleForSymbol(NSLookupAndBindSymbol("_Py_Initialize")); 456 475 /* Use dylib functions to find out where the framework was loaded from */ … … 472 491 /* We are in the build directory so use the name of the 473 492 executable - we know that the absolute path is passed */ 474 strncpy(argv0_path, prog , MAXPATHLEN);493 strncpy(argv0_path, progpath, MAXPATHLEN); 475 494 } 476 495 else { … … 526 545 strncpy(zip_path, PREFIX, MAXPATHLEN); 527 546 joinpath(zip_path, "lib/python00.zip"); 528 bufsz = strlen(zip_path); 547 bufsz = strlen(zip_path); /* Replace "00" with version */ 529 548 zip_path[bufsz - 6] = VERSION[0]; 530 549 zip_path[bufsz - 5] = VERSION[2]; … … 634 653 reduce(prefix); 635 654 reduce(prefix); 636 637 638 639 655 /* The prefix is the root directory, but reduce() chopped 656 * off the "/". */ 657 if (!prefix[0]) 658 strcpy(prefix, separator); 640 659 } 641 660 else … … 646 665 reduce(exec_prefix); 647 666 reduce(exec_prefix); 648 649 667 if (!exec_prefix[0]) 668 strcpy(exec_prefix, separator); 650 669 } 651 670 else
Note:
See TracChangeset
for help on using the changeset viewer.