Added safe_fname() that converts any newlines in a name into '?'s.

This commit is contained in:
Wayne Davison committed 2004-07-26 15:52:25 +00:00
1 parent 3cb22c204c
commit 820b6c9aa0
1 file changed
+21
+21
View File
@@ -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