diff options
-rw-r--r-- | config.h.win32 | 3 | ||||
-rw-r--r-- | configure.ac | 36 | ||||
-rw-r--r-- | wsutil/str_util.c | 16 |
3 files changed, 50 insertions, 5 deletions
diff --git a/config.h.win32 b/config.h.win32 index c10c89e533..8a32639559 100644 --- a/config.h.win32 +++ b/config.h.win32 @@ -110,6 +110,9 @@ /* Define if you have the <netinet/in.h> header file. */ /* #define HAVE_NETINET_IN_H 1 */ +/* Define if your printf() function supports thousands grouping. */ +/* #undef HAVE_GLIB_PRINTF_GROUPING */ + /* Define if you have the <snmp/snmp.h> header file. */ /* #undef HAVE_SNMP_SNMP_H */ diff --git a/configure.ac b/configure.ac index 2d8d9f2465..c9f8818444 100644 --- a/configure.ac +++ b/configure.ac @@ -1245,6 +1245,42 @@ main(void) AC_MSG_RESULT($ac_cv_dladdr_finds_executable_path) fi +# +# Check whether GLib's printf supports thousands grouping. (This might +# be different from the system's printf since GLib can optionally use +# its own printf implementation.) +# +AC_MSG_CHECKING(whether GLib supports POSIX/XSI thousands grouping) +ac_save_CFLAGS="$CFLAGS" +ac_save_LIBS="$LIBS" +CFLAGS="$CFLAGS $GLIB_CFLAGS" +LIBS="$GLIB_LIBS $LIBS" +AC_TRY_RUN([ +#include <glib.h> +#include <locale.h> +#include <stdio.h> +#include <string.h> + +int +main () +{ + gchar *str; + setlocale(LC_ALL, "en_US.UTF-8"); + str = g_strdup_printf("%'u", 123456); + return (strcmp (str, "123,456") != 0); +} +], ac_cv_glib_supports_printf_grouping=yes, ac_cv_glib_supports_printf_grouping=no, + [echo $ac_n "cross compiling; playing it safe... $ac_c" + ac_cv_glib_supports_printf_grouping=no]) +CFLAGS="$ac_save_CFLAGS" +LIBS="$ac_save_LIBS" +if test "$ac_cv_glib_supports_printf_grouping" = yes ; then + AC_MSG_RESULT(yes) + AC_DEFINE(HAVE_GLIB_PRINTF_GROUPING, 1, [Define if your printf() function supports thousands grouping.]) +else + AC_MSG_RESULT(no) +fi + if test "x$have_gtk" = "xyes" then # 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; } |