From 820b6c9aa0cf587fda363c2e473ca9c140f7866c Mon Sep 17 00:00:00 2001 From: Wayne Davison Date: Mon, 26 Jul 2004 15:52:25 +0000 Subject: [PATCH] Added safe_fname() that converts any newlines in a name into '?'s. --- util.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/util.c b/util.c index 8d057712..d896082d 100644 --- a/util.c +++ b/util.c @@ -900,6 +900,27 @@ int pop_dir(char *dir) return 1; } +/** + * Return the filename, turning any newlines into '?'s. This ensures that + * outputting it on a line of its own cannot generate an empty line. + **/ +const char *safe_fname(const char *fname) +{ + static char fbuf[MAXPATHLEN]; + char *nl = strchr(fname, '\n'); + + if (!nl) + return fname; + + strlcpy(fbuf, fname, sizeof fbuf); + nl = fbuf + (nl - (char *)fname); + do { + *nl = '?'; + } while ((nl = strchr(nl+1, '\n')) != NULL); + + return fbuf; +} + /** * Return a quoted string with the full pathname of the indicated filename. * The string " (in MODNAME)" may also be appended. The returned pointer -- 2.34.1