From: Oliver Kurth Date: Tue, 19 Feb 2019 20:51:33 +0000 (-0800) Subject: Common source file change not directly applicable to open-vm-tools. X-Git-Tag: stable-11.0.0~190 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=05fb961e2c5fcb0e3be0353171f3f2b5d945d0dd;p=thirdparty%2Fopen-vm-tools.git Common source file change not directly applicable to open-vm-tools. --- diff --git a/open-vm-tools/lib/stubs/stub-log.c b/open-vm-tools/lib/stubs/stub-log.c index 8d139b179..fd5c107ab 100644 --- a/open-vm-tools/lib/stubs/stub-log.c +++ b/open-vm-tools/lib/stubs/stub-log.c @@ -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 #include +#include +#include #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; } -