aboutsummaryrefslogtreecommitdiff
path: root/src/xz/util.c
diff options
context:
space:
mode:
authorLasse Collin <lasse.collin@tukaani.org>2009-06-26 20:36:45 +0300
committerLasse Collin <lasse.collin@tukaani.org>2009-06-26 20:36:45 +0300
commitcad62551c5fa9865dbe0841a0b3bc729c4fbe8fc (patch)
tree18c034dce54895c884ce480780b47f4ca3092f4b /src/xz/util.c
parentAdded missing source files to windows/Makefile. (diff)
downloadxz-cad62551c5fa9865dbe0841a0b3bc729c4fbe8fc.tar.xz
Ugly hack to make it possible to use the thousand separator
format character with snprintf() on POSIX systems but not on non-POSIX systems and still keep xgettext working.
Diffstat (limited to '')
-rw-r--r--src/xz/util.c34
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
///