Commit b4afd23c authored by Wayne Davison's avatar Wayne Davison

Allow safe_fname() to tweak up to two name at a time.

parent af1a3f9b
...@@ -902,17 +902,20 @@ int pop_dir(char *dir) ...@@ -902,17 +902,20 @@ int pop_dir(char *dir)
/** /**
* Return the filename, turning any newlines into '?'s. This ensures that * Return the filename, turning any newlines into '?'s. This ensures that
* outputting it on a line of its own cannot generate an empty line. * outputting it on a line of its own cannot generate an empty line. This
* function can handle only 2 names at a time!
**/ **/
const char *safe_fname(const char *fname) const char *safe_fname(const char *fname)
{ {
static char fbuf[MAXPATHLEN]; static char fbuf1[MAXPATHLEN], fbuf2[MAXPATHLEN];
static char *fbuf = fbuf2;
char *nl = strchr(fname, '\n'); char *nl = strchr(fname, '\n');
if (!nl) if (!nl)
return fname; return fname;
strlcpy(fbuf, fname, sizeof fbuf); fbuf = fbuf == fbuf1 ? fbuf2 : fbuf1;
strlcpy(fbuf, fname, MAXPATHLEN);
nl = fbuf + (nl - (char *)fname); nl = fbuf + (nl - (char *)fname);
do { do {
*nl = '?'; *nl = '?';
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment