Added a new function, full_fname(), that makes a filename more complete

for error messages.  If the path is in a module, we ensure that the
"path" setting (from the config file) is not revealed, while still
reminding the user that the path is relative to the module's root.
This commit is contained in:
Wayne Davison
2003-09-11 04:48:15 +00:00
parent 9b9114e8cd
commit eb61be192d

46
util.c
View File

@@ -774,6 +774,52 @@ int pop_dir(char *dir)
return 0;
}
/**
* Return a quoted string with the full pathname of the indicated filename.
* The string " (in MODNAME)" may also be appended. The returned pointer
* remains valid until the next time full_fname() is called.
**/
char *full_fname(char *fn)
{
extern int module_id;
static char *result = NULL;
char *m1, *m2, *m3;
char *p1, *p2;
if (result)
free(result);
if (*fn == '/')
p1 = p2 = "";
else {
p1 = curr_dir;
p2 = "/";
}
if (module_id >= 0) {
m1 = " (in ";
m2 = lp_name(module_id);
m3 = ")";
if (*p1) {
if (!lp_use_chroot(module_id)) {
char *p = lp_path(module_id);
if (*p != '/' || p[1])
p1 += strlen(p);
}
if (!*p1)
p2++;
else
p1++;
}
else
fn++;
} else
m1 = m2 = m3 = "";
asprintf(&result, "\"%s%s%s\"%s%s%s", p1, p2, fn, m1, m2, m3);
return result;
}
/** We need to supply our own strcmp function for file list comparisons
to ensure that signed/unsigned usage is consistent between machines. */
int u_strcmp(const char *cs1, const char *cs2)