Changeset 391 for python/trunk/Modules/getpath.c
- Timestamp:
- Mar 19, 2014, 11:31:01 PM (11 years ago)
- Location:
- python/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
python/trunk
-
Property svn:mergeinfo
set to
/python/vendor/Python-2.7.6 merged eligible /python/vendor/current merged eligible
-
Property svn:mergeinfo
set to
-
python/trunk/Modules/getpath.c
r383 r391 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) … … 239 239 } 240 240 else { 241 getcwd(path, MAXPATHLEN); 241 if (!getcwd(path, MAXPATHLEN)) { 242 /* unable to get the current directory */ 243 strcpy(path, p); 244 return; 245 } 242 246 if (p[0] == '.' && IS_SEP(p[1])) 243 247 p += 2; … … 343 347 } 344 348 345 /* Check to see if argv[0] is in the build directory */ 349 /* Check to see if argv[0] is in the build directory. "pybuilddir.txt" 350 is written by setup.py and contains the relative path to the location 351 of shared library modules. */ 346 352 strcpy(exec_prefix, argv0_path); 347 joinpath(exec_prefix, " Modules/Setup");353 joinpath(exec_prefix, "pybuilddir.txt"); 348 354 if (isfile(exec_prefix)) { 349 reduce(exec_prefix); 350 return -1; 355 FILE *f = fopen(exec_prefix, "r"); 356 if (f == NULL) 357 errno = 0; 358 else { 359 char rel_builddir_path[MAXPATHLEN+1]; 360 size_t n; 361 n = fread(rel_builddir_path, 1, MAXPATHLEN, f); 362 rel_builddir_path[n] = '\0'; 363 fclose(f); 364 if (n >= 0) { 365 strcpy(exec_prefix, argv0_path); 366 joinpath(exec_prefix, rel_builddir_path); 367 return -1; 368 } 369 } 351 370 } 352 371 … … 405 424 #endif 406 425 407 408 409 410 411 412 413 426 /* If there is no slash in the argv0 path, then we have to 427 * assume python is on the user's $PATH, since there's no 428 * other way to find a directory to start the search from. If 429 * $PATH isn't exported, you lose. 430 */ 431 if (HAS_ANYSEP(prog)) 432 strncpy(progpath, prog, MAXPATHLEN); 414 433 #ifdef __APPLE__ 415 434 /* On Mac OS X, if a script uses an interpreter of the form … … 426 445 ; 427 446 #endif /* __APPLE__ */ 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 447 else if (path) { 448 while (1) { 449 char *delim = strchr(path, DELIM); 450 451 if (delim) { 452 size_t len = delim - path; 453 if (len > MAXPATHLEN) 454 len = MAXPATHLEN; 455 strncpy(progpath, path, len); 456 *(progpath + len) = '\0'; 457 } 458 else 459 strncpy(progpath, path, MAXPATHLEN); 460 461 joinpath(progpath, prog); 462 if (isxfile(progpath)) 463 break; 464 465 if (!delim) { 466 progpath[0] = '\0'; 467 break; 468 } 469 path = delim + 1; 470 } 471 } 472 else 473 progpath[0] = '\0'; 455 474 #ifndef ALTSEP 456 if (!IS_ABSPATH(progpath))457 #endif 458 459 460 475 if (!IS_ABSPATH(progpath) && progpath[0] != '\0') 476 #endif 477 absolutize(progpath); 478 strncpy(argv0_path, progpath, MAXPATHLEN); 479 argv0_path[MAXPATHLEN] = '\0'; 461 480 462 481 #ifdef WITH_NEXT_FRAMEWORK 463 464 465 466 467 482 /* On Mac OS X we have a special case if we're running from a framework. 483 ** This is because the python home should be set relative to the library, 484 ** which is in the framework, not relative to the executable, which may 485 ** be outside of the framework. Except when we're in the build directory... 486 */ 468 487 pythonModule = NSModuleForSymbol(NSLookupAndBindSymbol("_Py_Initialize")); 469 488 /* Use dylib functions to find out where the framework was loaded from */ … … 485 504 /* We are in the build directory so use the name of the 486 505 executable - we know that the absolute path is passed */ 487 strncpy(argv0_path, prog , MAXPATHLEN);506 strncpy(argv0_path, progpath, MAXPATHLEN); 488 507 } 489 508 else { … … 539 558 strncpy(zip_path, PREFIX, MAXPATHLEN); 540 559 joinpath(zip_path, "lib/python00.zip"); 541 bufsz = strlen(zip_path); 560 bufsz = strlen(zip_path); /* Replace "00" with version */ 542 561 zip_path[bufsz - 6] = VERSION[0]; 543 562 zip_path[bufsz - 5] = VERSION[2]; … … 648 667 reduce(prefix); 649 668 reduce(prefix); 650 651 652 653 669 /* The prefix is the root directory, but reduce() chopped 670 * off the "/". */ 671 if (!prefix[0]) 672 strcpy(prefix, separator); 654 673 } 655 674 else … … 660 679 reduce(exec_prefix); 661 680 reduce(exec_prefix); 662 663 681 if (!exec_prefix[0]) 682 strcpy(exec_prefix, separator); 664 683 } 665 684 else
Note:
See TracChangeset
for help on using the changeset viewer.