Mercurial > hg > aboriginal
changeset 1104:6ab5dfe6b035
Check for null $PATH after checking for dir/filename (which doesn't need $PATH).
author | Rob Landley <rob@landley.net> |
---|---|
date | Tue, 08 Jun 2010 15:01:39 -0500 |
parents | 0a32de72b781 |
children | 345f49b45123 |
files | sources/toys/ccwrap.c |
diffstat | 1 files changed, 3 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/sources/toys/ccwrap.c Tue Jun 08 01:39:07 2010 -0500 +++ b/sources/toys/ccwrap.c Tue Jun 08 15:01:39 2010 -0500 @@ -55,15 +55,12 @@ char *find_in_path(char *path, char *filename, int has_exe) { - // Don't segfault if $PATH wasn't exported - if (!path) return 0; - char *cwd = getcwd(NULL, 0); if (index(filename, '/') && is_file(filename, has_exe)) return realpath(filename, NULL); - for (;;) { + while (path) { char *str, *next = path ? index(path, ':') : NULL; int len = next ? next-path : strlen(path); @@ -84,12 +81,11 @@ if (is_file(str, has_exe)) { char *s = realpath(str, NULL); free(str); + free(cwd); return s; } else free(str); - if (!next) break; - path += len; - path++; + path = next; } free(cwd);