Mercurial > cpython-lru_cache-weakref
comparison Python/sysmodule.c @ 4256:e225e70fd657 legacy-trunk
Changes to setpythonpath():
Test for / as well as for SEP for MS filenames.
Drop trailing separator from sys.path[0] for MS and Unix filenames.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Tue, 10 Sep 1996 14:44:21 +0000 |
| parents | c80c515999b9 |
| children | 1427d61f1307 |
comparison
equal
deleted
inserted
replaced
| 4255:64704d36b198 | 4256:e225e70fd657 |
|---|---|
| 365 fatal("no mem for sys.argv"); | 365 fatal("no mem for sys.argv"); |
| 366 if (sysset("argv", av) != 0) | 366 if (sysset("argv", av) != 0) |
| 367 fatal("can't assign sys.argv"); | 367 fatal("can't assign sys.argv"); |
| 368 if (path != NULL) { | 368 if (path != NULL) { |
| 369 char *p = NULL; | 369 char *p = NULL; |
| 370 int n; | 370 int n = 0; |
| 371 object *a; | 371 object *a; |
| 372 #if SEP == '\\' /* Special case for MS filename syntax */ | |
| 373 if (argc > 0 && argv[0] != NULL) { | |
| 374 char *q; | |
| 375 p = strrchr(argv[0], SEP); | |
| 376 /* Test for alternate separator */ | |
| 377 q = strrchr(p ? p : argv[0], '/'); | |
| 378 if (q != NULL) | |
| 379 p = q; | |
| 380 if (p != NULL) { | |
| 381 n = p + 1 - argv[0]; | |
| 382 if (n > 1 && p[-1] != ':') | |
| 383 n--; /* Drop trailing separator */ | |
| 384 } | |
| 385 } | |
| 386 #else /* All other filename syntaxes */ | |
| 372 if (argc > 0 && argv[0] != NULL) | 387 if (argc > 0 && argv[0] != NULL) |
| 373 p = strrchr(argv[0], SEP); | 388 p = strrchr(argv[0], SEP); |
| 374 if (p == NULL) | 389 if (p != NULL) { |
| 375 n = 0; | |
| 376 else | |
| 377 n = p + 1 - argv[0]; | 390 n = p + 1 - argv[0]; |
| 391 #if SEP == '/' /* Special case for Unix filename syntax */ | |
| 392 if (n > 1) | |
| 393 n--; /* Drop trailing separator */ | |
| 394 #endif /* Unix */ | |
| 395 } | |
| 396 #endif /* All others */ | |
| 378 a = newsizedstringobject(argv[0], n); | 397 a = newsizedstringobject(argv[0], n); |
| 379 if (a == NULL) | 398 if (a == NULL) |
| 380 fatal("no mem for sys.path insertion"); | 399 fatal("no mem for sys.path insertion"); |
| 381 if (inslistitem(path, 0, a) < 0) | 400 if (inslistitem(path, 0, a) < 0) |
| 382 fatal("sys.path.insert(0) failed"); | 401 fatal("sys.path.insert(0) failed"); |
