diff options
author | joe <joe@FreeBSD.org> | 2000-12-24 12:21:15 +0000 |
---|---|---|
committer | joe <joe@FreeBSD.org> | 2000-12-24 12:21:15 +0000 |
commit | 60930484fce5add335ff1828cd169c2822e6face (patch) | |
tree | 80a3bd4b774aa8a75a5766f6e926b8387cd07fe5 /usr.sbin/crunch/crunchgen | |
parent | 6bfb7240b822195a74d4fa5a8268f2143dc0102e (diff) | |
download | FreeBSD-src-60930484fce5add335ff1828cd169c2822e6face.zip FreeBSD-src-60930484fce5add335ff1828cd169c2822e6face.tar.gz |
Clean up the source directory finding code, and in the process fix a
problem that occurs when a program's source isn't found.
Diffstat (limited to 'usr.sbin/crunch/crunchgen')
-rw-r--r-- | usr.sbin/crunch/crunchgen/crunchgen.c | 40 |
1 files changed, 24 insertions, 16 deletions
diff --git a/usr.sbin/crunch/crunchgen/crunchgen.c b/usr.sbin/crunch/crunchgen/crunchgen.c index 5fcdb3a..d1e5e02 100644 --- a/usr.sbin/crunch/crunchgen/crunchgen.c +++ b/usr.sbin/crunch/crunchgen/crunchgen.c @@ -515,7 +515,6 @@ void gen_outputs(void) void fillin_program(prog_t *p) { char path[MAXPATHLEN]; - char *srcparent; char line[MAXLINELEN]; FILE *f; @@ -524,27 +523,29 @@ void fillin_program(prog_t *p) if(!p->ident) p->ident = genident(p->name); + + /* look for the source directory if one wasn't specified by a special */ if(!p->srcdir) { - srcparent = dir_search(p->name); - if(srcparent) - snprintf(line, MAXLINELEN, "%s/%s", srcparent, p->name); - if(is_dir(line)) - if ((p->srcdir = strdup(line)) == NULL) - out_of_memory(); + p->srcdir = dir_search(p->name); } /* Determine the actual srcdir (maybe symlinked). */ - snprintf(line, MAXLINELEN, "cd %s && echo -n `/bin/pwd`", p->srcdir); - f = popen(line,"r"); - if (f) { + if (p->srcdir) { + snprintf(line, MAXLINELEN, "cd %s && echo -n `/bin/pwd`", p->srcdir); + f = popen(line,"r"); + if (!f) + errx(1, "Can't execute: %s\n", line); + path[0] = '\0'; fgets(path, sizeof path, f); - if (!pclose(f)) { - p->realsrcdir = strdup(path); - } + if (pclose(f)) + errx(1, "Can't execute: %s\n", line); + + if (!*path) + errx(1, "Can't perform pwd on: %s\n", p->srcdir); + + p->realsrcdir = strdup(path); } - if (!p->realsrcdir) - errx(1, "Can't execute: %s\n", line); /* Unless the option to make object files was specified the * the objects will be built in the source directory unless @@ -809,10 +810,17 @@ char *dir_search(char *progname) { char path[MAXPATHLEN]; strlst_t *dir; + char *srcdir; for(dir=srcdirs; dir != NULL; dir=dir->next) { snprintf(path, MAXPATHLEN, "%s/%s", dir->str, progname); - if(is_dir(path)) return dir->str; + if (!is_dir(path)) { + continue; + } + + if ((srcdir = strdup(path)) == NULL) + out_of_memory(); + return srcdir; } return NULL; } |