Added safe_fname() that converts any newlines in a name into '?'s.
authorWayne Davison <wayned@samba.org>
Mon, 26 Jul 2004 15:52:25 +0000 (15:52 +0000)
committerWayne Davison <wayned@samba.org>
Mon, 26 Jul 2004 15:52:25 +0000 (15:52 +0000)
util.c

diff --git a/util.c b/util.c
index 8d05771..d896082 100644 (file)
--- a/util.c
+++ b/util.c
@@ -900,6 +900,27 @@ int pop_dir(char *dir)
        return 1;
 }
 
        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
 /**
  * Return a quoted string with the full pathname of the indicated filename.
  * The string " (in MODNAME)" may also be appended.  The returned pointer