crunchgen: use realpath(3) instead of ``pwd -P''

r366466 (9c7bd4f198) fixed a subtle bug by stripping the trailing
'\n' appended to the output of popen("cd %s && pwd -P", p->srcdir).

Replace this cumbersome implementation with a single realpath(3) call
which avoids spawning a shell, reading from the stream with fgets(3),
and final strdup(3).

Reviewed by:		arichardson, kevans
Approved by:		imp
Differential Revision:	https://reviews.freebsd.org/D26734
This commit is contained in:
Alexey Dokuchaev 2020-10-11 08:23:00 +00:00
parent 70de1003da
commit ccfdf335d6

View File

@ -639,7 +639,6 @@ fillin_program(prog_t *p)
{
char path[MAXPATHLEN];
char line[MAXLINELEN];
FILE *f;
snprintf(line, MAXLINELEN, "filling in parms for %s", p->name);
status(line);
@ -654,22 +653,9 @@ fillin_program(prog_t *p)
/* Determine the actual srcdir (maybe symlinked). */
if (p->srcdir) {
snprintf(line, MAXLINELEN, "cd %s && pwd -P", 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))
errx(1, "Can't execute: %s\n", line);
if (!*path)
errx(1, "Can't perform pwd on: %s\n", p->srcdir);
/* Chop off trailing newline. */
path[strlen(path) - 1] = '\0';
p->realsrcdir = strdup(path);
p->realsrcdir = realpath(p->srcdir, NULL);
if (p->realsrcdir == NULL)
errx(1, "Can't resolve path: %s\n", p->srcdir);
}
/* Unless the option to make object files was specified the