aboutsummaryrefslogtreecommitdiffstats
path: root/util/miscutil.c
diff options
context:
space:
mode:
Diffstat (limited to 'util/miscutil.c')
-rw-r--r--util/miscutil.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/util/miscutil.c b/util/miscutil.c
index 9fecf4488..18fff2c08 100644
--- a/util/miscutil.c
+++ b/util/miscutil.c
@@ -21,6 +21,7 @@
#include <config.h>
#include <stdio.h>
#include <time.h>
+#include <ctype.h>
#include "types.h"
#include "util.h"
@@ -31,3 +32,23 @@ make_timestamp()
}
+/****************
+ * Print a string to FP, but filter all control characters out.
+ */
+void
+print_string( FILE *fp, byte *p, size_t n )
+{
+ for( ; n; n--, p++ )
+ if( iscntrl( *p ) ) {
+ putc('\\', fp);
+ if( *p == '\n' )
+ putc('n', fp);
+ else if( !*p )
+ putc('0', fp);
+ else
+ printf("x%02x", *p );
+ }
+ else
+ putc(*p, fp);
+}
+