Add print_asc_cb()
authorVolker Lendecke <vl@samba.org>
Sun, 24 Oct 2010 13:23:41 +0000 (15:23 +0200)
committerVolker Lendecke <vlendec@samba.org>
Sun, 24 Oct 2010 20:46:28 +0000 (20:46 +0000)
lib/util/util.c
lib/util/util.h

index 11bb31517617689328a62708bf881dcc2e613b35..a01b47da15d1faa6df229bb5dd6bf380d5c176b0 100644 (file)
@@ -300,11 +300,29 @@ _PUBLIC_ bool fcntl_lock(int fd, int op, off_t offset, off_t count, int type)
        return true;
 }
 
-void print_asc(int level, const uint8_t *buf,int len)
+static void debugadd_cb(const char *buf, void *private_data)
+{
+       int *plevel = (int *)private_data;
+       DEBUGADD(*plevel, ("%s", buf));
+}
+
+void print_asc_cb(const uint8_t *buf, int len,
+                 void (*cb)(const char *buf, void *private_data),
+                 void *private_data)
 {
        int i;
-       for (i=0;i<len;i++)
-               DEBUGADD(level,("%c", isprint(buf[i])?buf[i]:'.'));
+       char s[2];
+       s[1] = 0;
+
+       for (i=0; i<len; i++) {
+               s[0] = isprint(buf[i]) ? buf[i] : '.';
+               cb(s, private_data);
+       }
+}
+
+void print_asc(int level, const uint8_t *buf,int len)
+{
+       print_asc_cb(buf, len, debugadd_cb, &level);
 }
 
 /**
index c613e65adf93fca9186719fb8b86398024e56f59..261acea88c9506da3135ed4b56b70e35dac9edbf 100644 (file)
@@ -840,6 +840,9 @@ bool pm_process( const char *fileName,
 bool unmap_file(void *start, size_t size);
 
 void print_asc(int level, const uint8_t *buf,int len);
+void print_asc_cb(const uint8_t *buf, int len,
+                 void (*cb)(const char *buf, void *private_data),
+                 void *private_data);
 
 /**
  * Add an id to an array of ids.