diff options
author | Yuri Pankov <yuri.pankov@nexenta.com> | 2018-04-29 21:28:12 +0300 |
---|---|---|
committer | Hans Rosenfeld <hans.rosenfeld@joyent.com> | 2018-05-16 12:03:43 +0200 |
commit | 804635d7bfa86d5f677fada06cb30420313f1159 (patch) | |
tree | 06785df23dd5e2ac2febed8901c51a4403067b85 /usr/src/lib/libc | |
parent | 4540c8e2f029ecd3f040b27b7489b1c9f2d920c0 (diff) | |
download | illumos-joyent-804635d7bfa86d5f677fada06cb30420313f1159.tar.gz |
9511 printf family isn't aware of multibyte decimal point characters
Reviewed by: Dan McDonald <danmcd@joyent.com>
Approved by: Hans Rosenfeld <rosenfeld@grumpf.hope-2000.org>
Diffstat (limited to 'usr/src/lib/libc')
-rw-r--r-- | usr/src/lib/libc/port/print/doprnt.c | 46 |
1 files changed, 33 insertions, 13 deletions
diff --git a/usr/src/lib/libc/port/print/doprnt.c b/usr/src/lib/libc/port/print/doprnt.c index 0c0fe0cacb..b6e8ceef0a 100644 --- a/usr/src/lib/libc/port/print/doprnt.c +++ b/usr/src/lib/libc/port/print/doprnt.c @@ -195,11 +195,11 @@ static const wchar_t widenullstr[] = L"(null)"; #define CHAR 0x2000 /* hh for char */ #ifdef _WIDE -static wchar_t * -insert_thousands_sep(wchar_t *bp, wchar_t *ep); +static wchar_t *insert_decimal_point(wchar_t *ep); +static wchar_t *insert_thousands_sep(wchar_t *bp, wchar_t *ep); #else /* _WIDE */ -static char * -insert_thousands_sep(char *bp, char *ep); +static char *insert_decimal_point(char *ep); +static char *insert_thousands_sep(char *bp, char *ep); #endif /* _WIDE */ static int _rec_scrswidth(wchar_t *, ssize_t); @@ -571,8 +571,6 @@ _ndoprnt(const char *format, va_list in_args, FILE *iop, int prflag) /* arglst[1] is the second arg, etc */ int starflg = 0; /* set to 1 if * format specifier seen */ - struct lconv *locptr = localeconv(); - char decimal_point = *locptr->decimal_point; /* * Initialize args and sargs to the start of the argument list. @@ -1344,11 +1342,11 @@ _ndoprnt(const char *format, va_list in_args, FILE *iop, int prflag) p = &buf[0]; *p++ = (*bp != '\0') ? *bp++ : '0'; - /* put in a decimal point if needed */ + /* Put in a decimal point if needed */ if (prec != 0 || (flagword & FSHARP)) - *p++ = decimal_point; + p = insert_decimal_point(p); - /* create the rest of the mantissa */ + /* Create the rest of the mantissa */ rz = prec; if (fcode == 'A') { for (; rz > 0 && *bp != '\0'; --rz) { @@ -1452,7 +1450,7 @@ _ndoprnt(const char *format, va_list in_args, FILE *iop, int prflag) /* Put in a decimal point if needed */ if (prec != 0 || (flagword & FSHARP)) - *p++ = decimal_point; + p = insert_decimal_point(p); /* Create the rest of the mantissa */ rz = prec; @@ -1575,9 +1573,9 @@ _ndoprnt(const char *format, va_list in_args, FILE *iop, int prflag) if (quote) p = insert_thousands_sep(buf, p); - /* Decide whether we need a decimal point */ - if ((flagword & FSHARP) || prec > 0) - *p++ = decimal_point; + /* Put in a decimal point if needed */ + if (prec != 0 || (flagword & FSHARP)) + p = insert_decimal_point(p); /* Digits (if any) after the decimal point */ nn = min(prec, MAXFCVT); @@ -2662,6 +2660,28 @@ insert_thousands_sep(char *bp, char *ep) return (ep); } +#ifdef _WIDE +static wchar_t * +insert_decimal_point(wchar_t *ep) +#else +static char * +insert_decimal_point(char *ep) +#endif +{ + struct lconv *locptr = localeconv(); + char *dp = locptr->decimal_point; +#ifdef _WIDE + wchar_t wdp; + + (void) mbtowc(&wdp, dp, MB_CUR_MAX); + *ep = wdp; + return (ep + 1); +#else + (void) memcpy(ep, dp, strlen(dp)); + return (ep + strlen(dp)); +#endif +} + /* * Recovery scrswidth function - |