Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/netbsd-8]: src Pull up following revision(s) (requested by joerg in tick...



details:   https://anonhg.NetBSD.org/src/rev/aab41f8d7074
branches:  netbsd-8
changeset: 434242:aab41f8d7074
user:      martin <martin%NetBSD.org@localhost>
date:      Tue Aug 29 11:51:50 2017 +0000

description:
Pull up following revision(s) (requested by joerg in ticket #215):
        tests/lib/libc/locale/t_strfmon.c: revision 1.1
        tests/lib/libc/locale/Makefile: revision 1.12
        lib/libc/stdlib/strfmon.c: revision 1.11
        distrib/sets/lists/debug/mi: revision 1.224
        include/monetary.h: revision 1.3
        distrib/sets/lists/tests/mi: revision 1.761
        lib/libc/stdlib/strfmon.3: revision 1.6
        lib/libc/stdlib/strfmon.3: revision 1.7
Add missing strfmon_l. Noticed by Bruno Haible. Add test case.
Typo fix.

diffstat:

 distrib/sets/lists/debug/mi       |   3 +-
 distrib/sets/lists/tests/mi       |   3 +-
 include/monetary.h                |  12 +++++-
 lib/libc/stdlib/strfmon.3         |  14 ++++++-
 lib/libc/stdlib/strfmon.c         |  77 ++++++++++++++++++++++++--------------
 tests/lib/libc/locale/Makefile    |   3 +-
 tests/lib/libc/locale/t_strfmon.c |  76 ++++++++++++++++++++++++++++++++++++++
 7 files changed, 154 insertions(+), 34 deletions(-)

diffs (truncated from 388 to 300 lines):

diff -r 121ded8ea372 -r aab41f8d7074 distrib/sets/lists/debug/mi
--- a/distrib/sets/lists/debug/mi       Tue Aug 29 11:45:18 2017 +0000
+++ b/distrib/sets/lists/debug/mi       Tue Aug 29 11:51:50 2017 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.216.2.2 2017/08/29 09:43:16 bouyer Exp $
+# $NetBSD: mi,v 1.216.2.3 2017/08/29 11:51:50 martin Exp $
 ./etc/mtree/set.debug                           comp-sys-root
 ./usr/lib                                      comp-sys-usr            compatdir
 ./usr/lib/i18n/libBIG5_g.a                     comp-c-debuglib         debuglib,compatfile
@@ -1952,6 +1952,7 @@
 ./usr/libdata/debug/usr/tests/lib/libc/locale/t_mbstowcs.debug         tests-lib-debug         debug,atf,compattestfile
 ./usr/libdata/debug/usr/tests/lib/libc/locale/t_mbtowc.debug           tests-lib-debug         debug,atf,compattestfile
 ./usr/libdata/debug/usr/tests/lib/libc/locale/t_sprintf.debug          tests-lib-debug         debug,atf,compattestfile
+./usr/libdata/debug/usr/tests/lib/libc/locale/t_strfmon.debug          tests-lib-debug         debug,atf,compattestfile
 ./usr/libdata/debug/usr/tests/lib/libc/locale/t_toupper.debug          tests-lib-debug         debug,atf,compattestfile
 ./usr/libdata/debug/usr/tests/lib/libc/locale/t_wcscspn.debug          tests-lib-debug         debug,atf,compattestfile
 ./usr/libdata/debug/usr/tests/lib/libc/locale/t_wcspbrk.debug          tests-lib-debug         debug,atf,compattestfile
diff -r 121ded8ea372 -r aab41f8d7074 distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi       Tue Aug 29 11:45:18 2017 +0000
+++ b/distrib/sets/lists/tests/mi       Tue Aug 29 11:51:50 2017 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.752.2.1 2017/08/29 09:43:17 bouyer Exp $
+# $NetBSD: mi,v 1.752.2.2 2017/08/29 11:51:51 martin Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -2549,6 +2549,7 @@
 ./usr/tests/lib/libc/locale/t_mbstowcs         tests-lib-tests         compattestfile,atf
 ./usr/tests/lib/libc/locale/t_mbtowc           tests-lib-tests         compattestfile,atf
 ./usr/tests/lib/libc/locale/t_sprintf          tests-lib-tests         compattestfile,atf
+./usr/tests/lib/libc/locale/t_strfmon          tests-lib-tests         compattestfile,atf
 ./usr/tests/lib/libc/locale/t_toupper          tests-lib-tests         compattestfile,atf
 ./usr/tests/lib/libc/locale/t_wcscspn          tests-lib-tests         compattestfile,atf
 ./usr/tests/lib/libc/locale/t_wcspbrk          tests-lib-tests         compattestfile,atf
diff -r 121ded8ea372 -r aab41f8d7074 include/monetary.h
--- a/include/monetary.h        Tue Aug 29 11:45:18 2017 +0000
+++ b/include/monetary.h        Tue Aug 29 11:51:50 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: monetary.h,v 1.2 2008/09/21 16:59:46 christos Exp $    */
+/*     $NetBSD: monetary.h,v 1.2.56.1 2017/08/29 11:51:51 martin Exp $ */
 
 /*-
  * Copyright (c) 2001 Alexey Zelkin <phantom%FreeBSD.org@localhost>
@@ -44,6 +44,16 @@
 #undef _BSD_SSIZE_T_
 #endif
 
+#if defined(_NETBSD_SOURCE)
+#  ifndef __LOCALE_T_DECLARED
+typedef struct _locale         *locale_t;
+#  define __LOCALE_T_DECLARED
+#  endif
+__BEGIN_DECLS
+ssize_t        strfmon_l(char * __restrict, size_t, locale_t, const char * __restrict, ...)
+    __attribute__((__format__(__strfmon__, 4, 5)));
+#endif
+
 __BEGIN_DECLS
 ssize_t        strfmon(char * __restrict, size_t, const char * __restrict, ...)
     __attribute__((__format__(__strfmon__, 3, 4)));
diff -r 121ded8ea372 -r aab41f8d7074 lib/libc/stdlib/strfmon.3
--- a/lib/libc/stdlib/strfmon.3 Tue Aug 29 11:45:18 2017 +0000
+++ b/lib/libc/stdlib/strfmon.3 Tue Aug 29 11:51:50 2017 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: strfmon.3,v 1.5 2014/03/18 18:20:37 riastradh Exp $
+.\"    $NetBSD: strfmon.3,v 1.5.18.1 2017/08/29 11:51:50 martin Exp $
 .\"
 .\" Copyright (c) 2001 Jeroen Ruigrok van der Werven <asmodai%FreeBSD.org@localhost>
 .\" All rights reserved.
@@ -26,7 +26,7 @@
 .\"
 .\"    From: FreeBSD: Id: strfmon.3,v 1.7 2003/01/06 06:21:25 tjr Exp
 .\"
-.Dd October 12, 2002
+.Dd August 15, 2017
 .Dt STRFMON 3
 .Os
 .Sh NAME
@@ -38,6 +38,8 @@
 .In monetary.h
 .Ft ssize_t
 .Fn strfmon "char * restrict s" "size_t maxsize" "const char * restrict format" "..."
+.Ft ssize_t
+.Fn strfmon_l "char * restrict s" "size_t maxsize" "locale_t loc" "const char * restrict format" "..."
 .Sh DESCRIPTION
 The
 .Fn strfmon
@@ -49,6 +51,14 @@
 .Fa maxsize
 bytes are placed into the array.
 .Pp
+The
+.Fn strfmon_l
+function behaves the same as
+.Fn strfmon ,
+but uses the locale
+.Fa loc
+instead of the process global locale.
+.Pp
 The format string is composed of zero or more directives:
 ordinary characters (not
 .Cm % ) ,
diff -r 121ded8ea372 -r aab41f8d7074 lib/libc/stdlib/strfmon.c
--- a/lib/libc/stdlib/strfmon.c Tue Aug 29 11:45:18 2017 +0000
+++ b/lib/libc/stdlib/strfmon.c Tue Aug 29 11:51:50 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: strfmon.c,v 1.10 2012/03/21 14:19:15 christos Exp $    */
+/*     $NetBSD: strfmon.c,v 1.10.24.1 2017/08/29 11:51:50 martin Exp $ */
 
 /*-
  * Copyright (c) 2001 Alexey Zelkin <phantom%FreeBSD.org@localhost>
@@ -32,14 +32,11 @@
 #if 0
 __FBSDID("$FreeBSD: src/lib/libc/stdlib/strfmon.c,v 1.14 2003/03/20 08:18:55 ache Exp $");
 #else
-__RCSID("$NetBSD: strfmon.c,v 1.10 2012/03/21 14:19:15 christos Exp $");
+__RCSID("$NetBSD: strfmon.c,v 1.10.24.1 2017/08/29 11:51:50 martin Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
-#if defined(__NetBSD__)
 #include "namespace.h"
-#include <monetary.h>
-#endif
 
 #include <sys/types.h>
 #include <assert.h>
@@ -47,11 +44,14 @@
 #include <errno.h>
 #include <limits.h>
 #include <locale.h>
+#include <monetary.h>
 #include <stdarg.h>
+#include <stddef.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <stddef.h>
+
+#include "setlocale_local.h"
 
 /* internal flags */
 #define        NEED_GROUPING           0x01    /* print digits grouped (default) */
@@ -104,15 +104,14 @@
        groups++;                                               \
 } while (/* CONSTCOND */ 0)
 
-static void __setup_vars(int, char *, char *, char *, const char **);
-static int __calc_left_pad(int, char *);
-static char *__format_grouped_double(double, int *, int, int, int);
+static void __setup_vars(struct lconv *, int, char *, char *, char *, const char **);
+static int __calc_left_pad(struct lconv *, int, char *);
+static char *__format_grouped_double(struct lconv *, double, int *, int, int, int);
 
-ssize_t
-strfmon(char * __restrict s, size_t maxsize, const char * __restrict format,
-    ...)
+static ssize_t
+vstrfmon_l(char * __restrict s, size_t maxsize, locale_t loc,
+    const char * __restrict format, va_list ap)
 {
-       va_list         ap;
        char            *dst;           /* output destination pointer */
        const char      *fmt;           /* current format poistion pointer */
        struct lconv    *lc;            /* pointer to lconv structure */
@@ -136,9 +135,7 @@
        char            *tmpptr;        /* temporary vars */
        int             sverrno;
 
-        va_start(ap, format);
-
-       lc = localeconv();
+       lc = localeconv_l(loc);
        dst = s;
        fmt = format;
        asciivalue = NULL;
@@ -263,21 +260,21 @@
 
                /* fill left_prec with amount of padding chars */
                if (left_prec >= 0) {
-                       pad_size = __calc_left_pad((flags ^ IS_NEGATIVE),
+                       pad_size = __calc_left_pad(lc, (flags ^ IS_NEGATIVE),
                                                        currency_symbol) -
-                                  __calc_left_pad(flags, currency_symbol);
+                                  __calc_left_pad(lc, flags, currency_symbol);
                        if (pad_size < 0)
                                pad_size = 0;
                }
 
-               asciivalue = __format_grouped_double(value, &flags,
+               asciivalue = __format_grouped_double(lc, value, &flags,
                                left_prec, right_prec, pad_char);
                if (asciivalue == NULL)
                        goto end_error;         /* errno already set     */
                                                /* to ENOMEM by malloc() */
 
                /* set some variables for later use */
-               __setup_vars(flags, &cs_precedes, &sep_by_space,
+               __setup_vars(lc, flags, &cs_precedes, &sep_by_space,
                                &sign_posn, &signstr);
 
                /*
@@ -392,7 +389,6 @@
        }
 
        PRINT('\0');
-       va_end(ap);
        free(asciivalue);
        free(currency_symbol);
        return (dst - s - 1);   /* return size of put data except trailing '\0' */
@@ -411,14 +407,12 @@
        if (currency_symbol != NULL)
                free(currency_symbol);
        errno = sverrno;
-       va_end(ap);
        return (-1);
 }
 
 static void
-__setup_vars(int flags, char *cs_precedes, char *sep_by_space,
+__setup_vars(struct lconv *lc, int flags, char *cs_precedes, char *sep_by_space,
                char *sign_posn, const char **signstr) {
-       struct lconv *lc = localeconv();
 
        if ((flags & IS_NEGATIVE) && (flags & USE_INTL_CURRENCY)) {
                *cs_precedes = lc->int_n_cs_precedes;
@@ -454,13 +448,13 @@
 }
 
 static int
-__calc_left_pad(int flags, char *cur_symb) {
+__calc_left_pad(struct lconv *lc, int flags, char *cur_symb) {
 
        char cs_precedes, sep_by_space, sign_posn;
        const char *signstr;
        size_t left_chars = 0;
 
-       __setup_vars(flags, &cs_precedes, &sep_by_space, &sign_posn, &signstr);
+       __setup_vars(lc, flags, &cs_precedes, &sep_by_space, &sign_posn, &signstr);
 
        if (cs_precedes != 0) {
                left_chars += strlen(cur_symb);
@@ -506,7 +500,7 @@
 
 /* convert double to ASCII */
 static char *
-__format_grouped_double(double value, int *flags,
+__format_grouped_double(struct lconv *lc, double value, int *flags,
                        int left_prec, int right_prec, int pad_char) {
 
        char            *rslt;
@@ -518,7 +512,6 @@
 
        int             padded;
 
-       struct lconv    *lc = localeconv();
        char            *grouping;
        char            decimal_point;
        char            thousands_sep;
@@ -627,3 +620,31 @@
        free(avalue);
        return (rslt);
 }
+
+ssize_t
+strfmon(char * __restrict s, size_t maxsize, const char * __restrict format,
+    ...)
+{
+       ssize_t rv;
+       va_list ap;
+
+       va_start(ap, format);
+       rv = vstrfmon_l(s, maxsize, _current_locale(), format, ap);
+       va_end(ap);
+
+       return rv;
+}
+
+ssize_t
+strfmon_l(char * __restrict s, size_t maxsize, locale_t loc,
+    const char * __restrict format, ...)
+{
+       ssize_t rv;
+       va_list ap;
+
+       va_start(ap, format);
+       rv = vstrfmon_l(s, maxsize, loc, format, ap);
+       va_end(ap);
+
+       return rv;
+}
diff -r 121ded8ea372 -r aab41f8d7074 tests/lib/libc/locale/Makefile
--- a/tests/lib/libc/locale/Makefile    Tue Aug 29 11:45:18 2017 +0000
+++ b/tests/lib/libc/locale/Makefile    Tue Aug 29 11:51:50 2017 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.9 2017/06/01 15:45:02 perseant Exp $
+# $NetBSD: Makefile,v 1.9.2.1 2017/08/29 11:51:50 martin Exp $
 
 .include <bsd.own.mk>
 



Home | Main Index | Thread Index | Old Index