From eb61be192de5bb899bedb851f69981e191ba1853 Mon Sep 17 00:00:00 2001 From: Wayne Davison Date: Thu, 11 Sep 2003 04:48:15 +0000 Subject: [PATCH] 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. --- util.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/util.c b/util.c index da10ca2f..e6420646 100644 --- a/util.c +++ b/util.c @@ -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) -- 2.34.1