summaryrefslogtreecommitdiffstats
path: root/usr.bin
diff options
context:
space:
mode:
authorvangyzen <vangyzen@FreeBSD.org>2016-11-30 18:11:35 +0000
committervangyzen <vangyzen@FreeBSD.org>2016-11-30 18:11:35 +0000
commitd3b47ab79c9ce879e5f157cb71dbf91f035f3925 (patch)
tree6f8688ddb92689116ff47b6fbe073467181fc7dc /usr.bin
parentd873b7fd693d863e1465afe9b1352cce32eb9900 (diff)
downloadFreeBSD-src-d3b47ab79c9ce879e5f157cb71dbf91f035f3925.zip
FreeBSD-src-d3b47ab79c9ce879e5f157cb71dbf91f035f3925.tar.gz
MFC r308824
locale: fix display of "grouping" and "mon_grouping" values The "grouping" and "mon_grouping" values are arrays of one-byte integers, not arrays of ASCII characters. Display them in a format similar to GNU and MacOS. Sponsored by: Dell EMC
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/locale/locale.c34
1 files changed, 32 insertions, 2 deletions
diff --git a/usr.bin/locale/locale.c b/usr.bin/locale/locale.c
index 765910b..21615f5 100644
--- a/usr.bin/locale/locale.c
+++ b/usr.bin/locale/locale.c
@@ -38,6 +38,7 @@
#include <sys/types.h>
#include <dirent.h>
#include <err.h>
+#include <limits.h>
#include <locale.h>
#include <langinfo.h>
#include <stdio.h>
@@ -48,6 +49,7 @@
#include "setlocale.h"
/* Local prototypes */
+char *format_grouping(const char *);
void init_locales_list(void);
void list_charmaps(void);
void list_locales(void);
@@ -486,6 +488,34 @@ showlocale(void)
printf("LC_ALL=%s\n", vval);
}
+char *
+format_grouping(const char *binary)
+{
+ static char rval[64];
+ const char *cp;
+ size_t len;
+
+ rval[0] = '\0';
+ for (cp = binary; *cp != '\0'; ++cp) {
+ char group[sizeof("127;")];
+ snprintf(group, sizeof(group), "%hhd;", *cp);
+ len = strlcat(rval, group, sizeof(rval));
+ if (len >= sizeof(rval)) {
+ len = sizeof(rval) - 1;
+ break;
+ }
+ if (*cp == CHAR_MAX) {
+ break;
+ }
+ }
+
+ /* Remove the trailing ';'. */
+ rval[len - 1] = '\0';
+
+ return (rval);
+}
+
+
/*
* keyword value lookup helper (via localeconv())
*/
@@ -499,7 +529,7 @@ kwval_lconv(int id)
lc = localeconv();
switch (id) {
case KW_GROUPING:
- rval = lc->grouping;
+ rval = format_grouping(lc->grouping);
break;
case KW_INT_CURR_SYMBOL:
rval = lc->int_curr_symbol;
@@ -514,7 +544,7 @@ kwval_lconv(int id)
rval = lc->mon_thousands_sep;
break;
case KW_MON_GROUPING:
- rval = lc->mon_grouping;
+ rval = format_grouping(lc->mon_grouping);
break;
case KW_POSITIVE_SIGN:
rval = lc->positive_sign;
OpenPOWER on IntegriCloud