summaryrefslogtreecommitdiff
path: root/wsutil/str_util.c
diff options
context:
space:
mode:
authorGerald Combs <gerald@wireshark.org>2013-03-03 19:34:58 +0000
committerGerald Combs <gerald@wireshark.org>2013-03-03 19:34:58 +0000
commita79e5d5b94b771c44d5918ecbdde3945b72fb1fb (patch)
treecbc9f05544712ab770cfb2785f582678b6ca48a7 /wsutil/str_util.c
parent0d9dfe4b26b956c46a642fff98f33f2fcdc01eaa (diff)
downloadwireshark-a79e5d5b94b771c44d5918ecbdde3945b72fb1fb.tar.gz
Check to see if GLib's printf routines support the X/Open / POSIX
thousands grouping (') flag and use it in format_size if it's available. As far as I can tell this translates to "everywhere except Windows and OpenBSD". According to the various build logs at https://build.opensuse.org/package/show?package=mingw32-glib2&project=windows%3Amingw%3Awin32 the OBS GLib packages enable GLib's internal printf implementation from Gnulib which means we *should* be able to enable this on Windows. Unfortunately this doesn't appear to be the case. svn path=/trunk/; revision=48042
Diffstat (limited to 'wsutil/str_util.c')
-rw-r--r--wsutil/str_util.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/wsutil/str_util.c b/wsutil/str_util.c
index f2de5bfbee..c754423536 100644
--- a/wsutil/str_util.c
+++ b/wsutil/str_util.c
@@ -92,6 +92,12 @@ isdigit_string(guchar *str)
#define FORMAT_SIZE_UNIT_MASK 0x00ff
#define FORMAT_SIZE_PFX_MASK 0xff00
+#ifdef HAVE_GLIB_PRINTF_GROUPING
+#define GROUP_FLAG "'"
+#else
+#define GROUP_FLAG ""
+#endif
+
/* Given a size, return its value in a human-readable format */
gchar *format_size(gint64 size, format_size_flags_e flags) {
GString *human_str = g_string_new("");
@@ -107,15 +113,15 @@ gchar *format_size(gint64 size, format_size_flags_e flags) {
}
if (size / power / power / power / power >= 10) {
- g_string_printf(human_str, "%" G_GINT64_MODIFIER "d %s", size / power / power / power / power, prefix[pfx_off]);
+ g_string_printf(human_str, "%" GROUP_FLAG G_GINT64_MODIFIER "d %s", size / power / power / power / power, prefix[pfx_off]);
} else if (size / power / power / power >= 10) {
- g_string_printf(human_str, "%" G_GINT64_MODIFIER "d %s", size / power / power / power, prefix[pfx_off+1]);
+ g_string_printf(human_str, "%" GROUP_FLAG G_GINT64_MODIFIER "d %s", size / power / power / power, prefix[pfx_off+1]);
} else if (size / power / power >= 10) {
- g_string_printf(human_str, "%" G_GINT64_MODIFIER "d %s", size / power / power, prefix[pfx_off+2]);
+ g_string_printf(human_str, "%" GROUP_FLAG G_GINT64_MODIFIER "d %s", size / power / power, prefix[pfx_off+2]);
} else if (size / power >= 10) {
- g_string_printf(human_str, "%" G_GINT64_MODIFIER "d %s", size / power, prefix[pfx_off+3]);
+ g_string_printf(human_str, "%" GROUP_FLAG G_GINT64_MODIFIER "d %s", size / power, prefix[pfx_off+3]);
} else {
- g_string_printf(human_str, "%" G_GINT64_MODIFIER "d ", size);
+ g_string_printf(human_str, "%" GROUP_FLAG G_GINT64_MODIFIER "d ", size);
is_small = TRUE;
}