diff options
author | Guido van Rossum <guido@python.org> | 1996-09-10 14:44:21 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1996-09-10 14:44:21 (GMT) |
commit | cc88341e6d25a7ca9fc7765d93c436f02d84f83b (patch) | |
tree | 1482fab0e192fd5eda0cd6e96c1fa539101ca00e /Python | |
parent | 688bbfc217ca389b66be88d023e93fd617923b73 (diff) | |
download | cpython-cc88341e6d25a7ca9fc7765d93c436f02d84f83b.zip cpython-cc88341e6d25a7ca9fc7765d93c436f02d84f83b.tar.gz cpython-cc88341e6d25a7ca9fc7765d93c436f02d84f83b.tar.bz2 |
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.
Diffstat (limited to 'Python')
-rw-r--r-- | Python/sysmodule.c | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 56d1e6d..5cfd2d6 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -367,14 +367,33 @@ setpythonargv(argc, argv) fatal("can't assign sys.argv"); if (path != NULL) { char *p = NULL; - int n; + int n = 0; object *a; +#if SEP == '\\' /* Special case for MS filename syntax */ + if (argc > 0 && argv[0] != NULL) { + char *q; + p = strrchr(argv[0], SEP); + /* Test for alternate separator */ + q = strrchr(p ? p : argv[0], '/'); + if (q != NULL) + p = q; + if (p != NULL) { + n = p + 1 - argv[0]; + if (n > 1 && p[-1] != ':') + n--; /* Drop trailing separator */ + } + } +#else /* All other filename syntaxes */ if (argc > 0 && argv[0] != NULL) p = strrchr(argv[0], SEP); - if (p == NULL) - n = 0; - else + if (p != NULL) { n = p + 1 - argv[0]; +#if SEP == '/' /* Special case for Unix filename syntax */ + if (n > 1) + n--; /* Drop trailing separator */ +#endif /* Unix */ + } +#endif /* All others */ a = newsizedstringobject(argv[0], n); if (a == NULL) fatal("no mem for sys.path insertion"); |