af_alg: Improve comments.
[gnulib.git] / lib / strfmon_l.c
blob4e23835fc646537568a535a34cecb4486285da06
1 /* strfmon_l override.
2 Copyright (C) 2017-2018 Free Software Foundation, Inc.
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3, or (at your option)
7 any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License along
15 with this program; if not, see <https://www.gnu.org/licenses/>. */
17 #include <config.h>
19 /* Specification. */
20 #include <monetary.h>
22 #include <locale.h>
23 #include <stdarg.h>
25 #undef strfmon_l
27 /* This override can only support a limited number of arguments. */
28 #define MAX_ARG_WORDS 16
30 ssize_t
31 rpl_strfmon_l (char *s, size_t maxsize, locale_t locale, const char *format, ...)
33 /* Work around glibc 2.23 bug
34 <https://sourceware.org/bugzilla/show_bug.cgi?id=19633>. */
35 va_list argptr;
36 double args[MAX_ARG_WORDS];
37 int i;
38 locale_t orig_locale;
39 ssize_t result;
41 orig_locale = uselocale ((locale_t)0);
43 if (uselocale (locale) == (locale_t)0)
44 /* errno is set. */
45 return -1;
47 va_start (argptr, format);
48 /* Hack: Consume more arguments than those that are actually given. */
49 for (i = 0; i < MAX_ARG_WORDS; i++)
50 args[i] = va_arg (argptr, double);
52 result = strfmon_l (s, maxsize, locale, format,
53 args[0], args[1], args[2], args[3], args[4], args[5],
54 args[6], args[7], args[8], args[9], args[10], args[11],
55 args[12], args[13], args[14], args[15]);
57 va_end (argptr);
59 if (uselocale (orig_locale) == (locale_t)0)
60 /* errno is set. */
61 return -1;
63 return result;