X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=blobdiff_plain;f=palacios%2Fsrc%2Fpalacios%2Fvmm_sprintf.c;h=c573e3ae62d6ea1359464550a7316445f72cf9b4;hb=HEAD;hp=837cb6bea39d296c1d519d67e770ea2fa43077b9;hpb=3dd047dc0f70231ea93e5b3b40a9142a391bf507;p=palacios.git diff --git a/palacios/src/palacios/vmm_sprintf.c b/palacios/src/palacios/vmm_sprintf.c index 837cb6b..c573e3a 100644 --- a/palacios/src/palacios/vmm_sprintf.c +++ b/palacios/src/palacios/vmm_sprintf.c @@ -66,11 +66,6 @@ #include -#define NEED_SPRINTF 1 -#define NEED_SNPRINTF 1 -#define NEED_VSPRINTF 1 -#define NEED_VSNPRINTF 1 -#define NEED_VSNRPRINTF 1 typedef addr_t ptrdiff_t; /* ptr1 - ptr2 */ @@ -86,17 +81,25 @@ static char const hex2ascii_data[] = "0123456789abcdefghijklmnopqrstuvwxyz"; struct snprintf_arg { - char *str; - size_t remain; + char *str; + size_t remain; }; + +#if defined(CONFIG_BUILT_IN_STDIO) && \ + ( defined(CONFIG_BUILT_IN_SPRINTF) || \ + defined(CONFIG_BUILT_IN_SNPRINTF) || \ + defined(CONFIG_BUILT_IN_VSPRINTF) || \ + defined(CONFIG_BUILT_IN_VSNPRINTF) || \ + defined(CONFIG_BUILT_IN_VSNRPRINTF )) + static char * ksprintn(char * nbuf, uint64_t num, int base, int *len, int upper); static void snprintf_func(int ch, void * arg); static int kvprintf(char const * fmt, void (*func)(int, void *), void * arg, int radix, va_list ap); -#if NEED_SPRINTF +#ifdef CONFIG_BUILT_IN_SPRINTF /* * Scaled down version of sprintf(3). */ @@ -113,7 +116,7 @@ int sprintf(char * buf, const char * cfmt, ...) { #endif -#if NEED_VSPRINTF +#ifdef CONFIG_BUILT_IN_VSPRINTF /* * Scaled down version of vsprintf(3). */ @@ -127,7 +130,7 @@ int vsprintf(char * buf, const char * cfmt, va_list ap) { #endif -#if NEED_SNPRINTF +#ifdef CONFIG_BUILT_IN_SNPRINTF /* * Scaled down version of snprintf(3). */ @@ -143,7 +146,7 @@ int snprintf(char * str, size_t size, const char * format, ...) { #endif -#if NEED_VSNPRINTF +#ifdef CONFIG_BUILT_IN_VSNPRINTF /* * Scaled down version of vsnprintf(3). */ @@ -162,7 +165,7 @@ int vsnprintf(char * str, size_t size, const char * format, va_list ap) { #endif -#if NEED_VSNRPRINTF +#ifdef CONFIG_BUILT_IN_VSNRPRINTF /* * Kernel version which takes radix argument vsnprintf(3). */ @@ -181,9 +184,7 @@ int vsnrprintf(char * str, size_t size, int radix, const char * format, va_list #endif -static void -snprintf_func(int ch, void *arg) -{ +static void snprintf_func(int ch, void *arg) { struct snprintf_arg *const info = arg; if (info->remain >= 2) { @@ -198,9 +199,7 @@ snprintf_func(int ch, void *arg) * written in the buffer (i.e., the first character of the string). * The buffer pointed to by `nbuf' must have length >= MAXNBUF. */ -static char * -ksprintn(char *nbuf, uint64_t num, int base, int *lenp, int upper) -{ +static char * ksprintn(char *nbuf, uint64_t num, int base, int *lenp, int upper) { char *p, c; p = nbuf; @@ -554,63 +553,58 @@ number: } -#define HD_COLUMN_MASK 0xff -#define HD_DELIM_MASK 0xff00 -#define HD_OMIT_COUNT (1 << 16) -#define HD_OMIT_HEX (1 << 17) -#define HD_OMIT_CHARS (1 << 18) +#endif // CONFIG_BUILT_IN_STDIO -void -v3_hexdump(const void *ptr, int length, const char *hdr, int flags) -{ - int i, j, k; - int cols; - const unsigned char *cp; - char delim; - - if ((flags & HD_DELIM_MASK) != 0) - delim = (flags & HD_DELIM_MASK) >> 8; - else - delim = ' '; - if ((flags & HD_COLUMN_MASK) != 0) - cols = flags & HD_COLUMN_MASK; - else - cols = 16; - - cp = ptr; - for (i = 0; i < length; i+= cols) { - if (hdr != NULL) - PrintDebug("%s", hdr); - - if ((flags & HD_OMIT_COUNT) == 0) - PrintDebug("%04x ", i); - - if ((flags & HD_OMIT_HEX) == 0) { - for (j = 0; j < cols; j++) { - k = i + j; - if (k < length) - PrintDebug("%c%02x", delim, cp[k]); - else - PrintDebug(" "); - } - } +void v3_hexdump(const void * ptr, int length, const char * hdr, int flags) { + int i, j, k; + int cols; + const unsigned char *cp; + char delim; + + if ((flags & HD_DELIM_MASK) != 0) + delim = (flags & HD_DELIM_MASK) >> 8; + else + delim = ' '; + + if ((flags & HD_COLUMN_MASK) != 0) + cols = flags & HD_COLUMN_MASK; + else + cols = 16; + + cp = ptr; + for (i = 0; i < length; i+= cols) { + if (hdr != NULL) + V3_Print("%s", hdr); + + if ((flags & HD_OMIT_COUNT) == 0) + V3_Print("%04x ", i); + + if ((flags & HD_OMIT_HEX) == 0) { + for (j = 0; j < cols; j++) { + k = i + j; + if (k < length) + V3_Print("%c%02x", delim, cp[k]); + else + V3_Print(" "); + } + } - if ((flags & HD_OMIT_CHARS) == 0) { - PrintDebug(" |"); - for (j = 0; j < cols; j++) { - k = i + j; - if (k >= length) - PrintDebug(" "); - else if (cp[k] >= ' ' && cp[k] <= '~') - PrintDebug("%c", cp[k]); - else - PrintDebug("."); - } - PrintDebug("|"); - } - PrintDebug("\n"); + if ((flags & HD_OMIT_CHARS) == 0) { + V3_Print(" |"); + for (j = 0; j < cols; j++) { + k = i + j; + if (k >= length) + V3_Print(" "); + else if (cp[k] >= ' ' && cp[k] <= '~') + V3_Print("%c", cp[k]); + else + V3_Print("."); + } + V3_Print("|"); } + V3_Print("\n"); + } }