X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fvppinfra%2Fformat.c;h=886f03d9c5f78702ce1a54e9691b7a443ab3f952;hb=e88865d7bc9cd45b044f8aeadf1916c38e0eb165;hp=78e52e9a2ad35496748eac24c061a1da19e3c614;hpb=7cd468a3d7dee7d6c92f69a0bb7061ae208ec727;p=vpp.git diff --git a/src/vppinfra/format.c b/src/vppinfra/format.c index 78e52e9a2ad..886f03d9c5f 100644 --- a/src/vppinfra/format.c +++ b/src/vppinfra/format.c @@ -62,6 +62,7 @@ #include #include #include /* os_puts */ +#include typedef struct { @@ -138,25 +139,25 @@ justify (u8 * s, format_info_t * fi, uword s_len_orig) if (n_left > 0) { vec_insert (s, n_left, i0); - memset (s + i0, fi->pad_char, n_left); + clib_memset (s + i0, fi->pad_char, n_left); l1 = vec_len (s); } if (n_right > 0) { vec_resize (s, n_right); - memset (s + l1, fi->pad_char, n_right); + clib_memset (s + l1, fi->pad_char, n_right); } } return s; } -static u8 * -do_percent (u8 ** _s, u8 * fmt, va_list * va) +static const u8 * +do_percent (u8 ** _s, const u8 * fmt, va_list * va) { u8 *s = *_s; uword c; - u8 *f = fmt; + const u8 *f = fmt; format_info_t fi = { .justify = '+', @@ -385,7 +386,7 @@ done: u8 * va_format (u8 * s, const char *fmt, va_list * va) { - u8 *f = (u8 *) fmt, *g; + const u8 *f = (u8 *) fmt, *g; u8 c; g = f; @@ -462,6 +463,17 @@ fformat (FILE * f, char *fmt, ...) } #ifdef CLIB_UNIX +void +fformat_append_cr (FILE * ofp, const char *fmt, ...) +{ + va_list va; + + va_start (va, fmt); + (void) va_fformat (ofp, (char *) fmt, &va); + va_end (va); + fformat (ofp, "\n"); +} + word fdformat (int fd, char *fmt, ...) { @@ -708,8 +720,12 @@ format_float (u8 * s, f64 x, uword n_fraction_digits, uword output_style) sign = 1; } + /* Check for not-a-number. */ + if (isnan (x)) + return format (s, "%cNaN", sign ? '-' : '+'); + /* Check for infinity. */ - if (x == x / 2) + if (isinf (x)) return format (s, "%cinfinity", sign ? '-' : '+'); x = normalize (x, &expon, &prec);