Mercurial > cpython-lru_cache-weakref
diff Python/import.c @ 630:04ed4765b17c legacy-trunk
getbinaryname is now part of dl_loadmod.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Sun, 26 Jan 1992 18:15:22 +0000 |
| parents | 0ad5b35e3ad8 |
| children | 5aff9f8fd299 |
line wrap: on
line diff
--- a/Python/import.c Sun Jan 26 18:13:18 1992 +0000 +++ b/Python/import.c Sun Jan 26 18:15:22 1992 +0000 @@ -46,7 +46,7 @@ #ifdef USE_DL #include "dl.h" -static char *getbinaryname(); +extern char *argv0; #endif /* Magic word to reject pre-0.9.4 .pyc files */ @@ -194,7 +194,7 @@ dl_funcptr p; D(fprintf(stderr, "Found %s\n", namebuf)); sprintf(funcname, "init%s", name); - p = dl_loadmod(getbinaryname(), namebuf, funcname); + p = dl_loadmod(argv0, namebuf, funcname); if (p == NULL) { D(fprintf(stderr, "dl_loadmod failed\n")); } @@ -404,64 +404,3 @@ } return 0; } - -#ifdef USE_DL - -/* A function to find a filename for the currently executing binary. - Because this is not directly available, we have to search for argv[0] - along $PATH. But note that if argv[0] contains a slash anywhere, - sh(1) doesn't search $PATH -- so neither do we! */ - -/* XXX This should be moved to a more system-specific file */ - -#include <sys/types.h> -#include <sys/stat.h> /* For stat */ - -extern char *getenv(); - -extern char *argv0; /* In config.c */ - -/* Default path from sh(1) in Irix 4.0.1 */ -#define DEF_PATH ":/usr/sbin:/usr/bsd:/bin:/usr/bin:/usr/bin/X11" - -static char * -getbinaryname() -{ - char *p, *q; - char *path; - static char buf[258]; - int i; - struct stat st; - - if (strchr(argv0, '/') != NULL) { - D(fprintf(stderr, "binary includes slash: %s\n", argv0)); - return argv0; - } - path = getenv("PATH"); - if (path == NULL) - path = DEF_PATH; - p = q = path; - for (;;) { - while (*q && *q != ':') - q++; - i = q-p; - strncpy(buf, p, i); - if (q > p && q[-1] != '/') - buf[i++] = '/'; - strcpy(buf+i, argv0); - if (stat(buf, &st) >= 0) { - if (S_ISREG(st.st_mode) && - (st.st_mode & 0111)) { - D(fprintf(stderr, "found binary: %s\n", buf)); - return buf; - } - } - if (!*q) - break; - p = ++q; - } - D(fprintf(stderr, "can't find binary: %s\n", argv0)); - return argv0; -} - -#endif
