]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
hexdump: can dump to a buffer
authorYehuda Sadeh <yehuda@hq.newdream.net>
Thu, 22 Oct 2009 18:51:32 +0000 (11:51 -0700)
committerYehuda Sadeh <yehuda@hq.newdream.net>
Thu, 22 Oct 2009 19:33:05 +0000 (12:33 -0700)
src/common/debug.h

index 26d3c9f9100c0cfa1f073198e5e0ab205e8d1d24..d47861dfa4130419bc278eef6c20ffa20e521ada 100644 (file)
@@ -86,18 +86,23 @@ inline ostream& operator<<(ostream& out, _bad_endl_use_dendl_t) {
 #define dendl std::endl; _dout_end_line(); } } while (0)
 
 
-inline static void hexdump(string msg, const char *s, int len)
+inline static void hex2str(const char *s, int len, char *buf, int dest_len)
 {
-  int buf_len = len*4;
-  char buf[buf_len];
   int pos = 0;
-  for (int i=0; i<len && pos<buf_len - 8; i++) {
+  for (int i=0; i<len && pos<dest_len; i++) {
     if (i && !(i%8))
-      pos += snprintf(&buf[pos], buf_len-pos, " ");
+      pos += snprintf(&buf[pos], dest_len-pos, " ");
     if (i && !(i%16))
-      pos += snprintf(&buf[pos], buf_len-pos, "\n");
-    pos += snprintf(&buf[pos], buf_len-pos, "%.2x ", (int)(unsigned char)s[i]);
+      pos += snprintf(&buf[pos], dest_len-pos, "\n");
+    pos += snprintf(&buf[pos], dest_len-pos, "%.2x ", (int)(unsigned char)s[i]);
   }
+}
+
+inline static void hexdump(string msg, const char *s, int len)
+{
+  int buf_len = len*4;
+  char buf[buf_len];
+  hex2str(s, len, buf, buf_len);
   generic_dout(0) << msg << ":\n" << buf << dendl;
 }