diff options
Diffstat (limited to 'src/xz/util.c')
-rw-r--r-- | src/xz/util.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/xz/util.c b/src/xz/util.c index d200bfca..d160ea0d 100644 --- a/src/xz/util.c +++ b/src/xz/util.c @@ -13,6 +13,15 @@ #include "private.h" +// Thousand separator for format strings is not supported outside POSIX. +// This is used in uint64_to_str() and double_to_str(). +#ifdef DOSLIKE +# define THOUSAND "" +#else +# define THOUSAND "'" +#endif + + extern void * xrealloc(void *ptr, size_t size) { @@ -118,6 +127,31 @@ error: } +extern const char * +uint64_to_str(uint64_t value, uint32_t slot) +{ + // 2^64 with thousand separators is 26 bytes plus trailing '\0'. + static char bufs[4][32]; + + assert(slot < ARRAY_SIZE(bufs)); + + snprintf(bufs[slot], sizeof(bufs[slot]), "%" THOUSAND PRIu64, value); + return bufs[slot]; +} + + +extern const char * +double_to_str(double value) +{ + // 64 bytes is surely enough, since it won't fit in some other + // fields anyway. + static char buf[64]; + + snprintf(buf, sizeof(buf), "%" THOUSAND ".1f", value); + return buf; +} + + /* /// \brief Simple quoting to get rid of ASCII control characters /// |