summaryrefslogtreecommitdiffstats
path: root/Python/sysmodule.c
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1996-07-24 01:31:37 (GMT)
committerGuido van Rossum <guido@python.org>1996-07-24 01:31:37 (GMT)
commita63d9f4d9fdd4d659d80628e4429129351fc61cb (patch)
tree38992eb593e953b6ebd0b38d834e1783079572d2 /Python/sysmodule.c
parent3b8e20d2c2022f49376578f230ea1cbb54f694f7 (diff)
downloadcpython-a63d9f4d9fdd4d659d80628e4429129351fc61cb.zip
cpython-a63d9f4d9fdd4d659d80628e4429129351fc61cb.tar.gz
cpython-a63d9f4d9fdd4d659d80628e4429129351fc61cb.tar.bz2
As a side effect of calling PySys_SetArgv (setpythonargv), the
directory containing argv[0] is inserted in front of sys.path. If argv[0] contains no directory, an empty string is inserted. If argv is empty, nothing happens.
Diffstat (limited to 'Python/sysmodule.c')
-rw-r--r--Python/sysmodule.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/Python/sysmodule.c b/Python/sysmodule.c
index 8937c85..1b6fab8 100644
--- a/Python/sysmodule.c
+++ b/Python/sysmodule.c
@@ -364,5 +364,23 @@ setpythonargv(argc, argv)
fatal("no mem for sys.argv");
if (sysset("argv", av) != 0)
fatal("can't assign sys.argv");
+ if (argc > 0) {
+ object *path = sysget("path");
+ if (path != NULL) {
+ char *p = strrchr(argv[0], SEP);
+ int n;
+ object *a;
+ if (p == NULL)
+ n = 0;
+ else
+ n = p + 1 - argv[0];
+ a = newsizedstringobject(argv[0], n);
+ if (a == NULL)
+ fatal("no mem for sys.path insertion");
+ if (inslistitem(path, 0, a) < 0)
+ fatal("sys.path.insert(0) failed");
+ DECREF(a);
+ }
+ }
DECREF(av);
}