]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Common source file change not directly applicable to open-vm-tools.
authorOliver Kurth <okurth@vmware.com>
Tue, 19 Feb 2019 20:51:33 +0000 (12:51 -0800)
committerOliver Kurth <okurth@vmware.com>
Tue, 19 Feb 2019 20:51:33 +0000 (12:51 -0800)
open-vm-tools/lib/stubs/stub-log.c

index 8d139b179bcc160701b44ea0bd2293aa4568218e..fd5c107abf23abf5f1704e3a8017361a14cfc945 100644 (file)
@@ -1,5 +1,5 @@
 /*********************************************************
- * Copyright (C) 2008-2016 VMware, Inc. All rights reserved.
+ * Copyright (C) 2008-2016,2019 VMware, Inc. All rights reserved.
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of the GNU Lesser General Public License as published
@@ -25,6 +25,8 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
 #include "str.h"
 #include "log.h"
 
@@ -61,6 +63,60 @@ Log(const char *fmt,
    LogV(VMW_LOG_INFO, fmt, args);
    va_end(args);
 }
+
+
+void
+Log_Level(uint32 routing,   // IN:
+          const char *fmt,  // IN:
+          ...)              // IN or OUT: depends on 'fmt'
+{
+   va_list ap;
+
+   va_start(ap, fmt);
+   LogV(routing, fmt, ap);
+   va_end(ap);
+}
+
+
+void
+Log_HexDumpLevel(uint32 routing,      // IN:
+                 const char *prefix,  // IN: prefix for each log line
+                 const void *data,    // IN: data to log
+                 size_t size)         // IN: number of bytes
+{
+   size_t i = 0;
+
+   while (i < size) {
+      char hex[16 * 3 + 1];
+      char ascii[16 + 1];
+      unsigned j;
+
+      memset(hex, ' ', sizeof hex - 1);
+      hex[sizeof hex - 1] = 0;
+      memset(ascii, ' ', sizeof ascii - 1);
+      ascii[sizeof ascii - 1] = 0;
+
+      for (j = 0; j < 16 && i < size; j++, i++) {
+         uint8 c = ((const uint8 *)data)[i];
+
+         hex[j * 3 + 0] = "0123456789abcdef"[c >> 4];
+         hex[j * 3 + 1] = "0123456789abcdef"[c & 0xf];
+         ascii[j] = isprint(c) ? c : '.';
+      }
+
+      Log_Level(routing, "%s %03"FMTSZ"x: %s%s\n", prefix, i - j, hex, ascii);
+   }
+}
+
+
+void
+Log_HexDump(const char *prefix,  // IN: prefix for each log line
+            const void *data,    // IN: data to log
+            size_t size)         // IN: number of bytes
+{
+   Log_HexDumpLevel(VMW_LOG_INFO, prefix, data, size);
+}
+
 #endif
 
 
@@ -76,4 +132,3 @@ Log_GetFileName(void)
 {
    return NULL;
 }
-