| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: strfmon.c,v 1.18 2022/08/18 11:05:02 christos Exp $ */ | | 1 | /* $NetBSD: strfmon.c,v 1.19 2023/09/28 10:03:41 martin Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 2001 Alexey Zelkin <phantom@FreeBSD.org> | | 4 | * Copyright (c) 2001 Alexey Zelkin <phantom@FreeBSD.org> |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * Redistribution and use in source and binary forms, with or without | | 7 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions | | 8 | * modification, are permitted provided that the following conditions |
9 | * are met: | | 9 | * are met: |
10 | * 1. Redistributions of source code must retain the above copyright | | 10 | * 1. Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions and the following disclaimer. | | 11 | * notice, this list of conditions and the following disclaimer. |
12 | * 2. Redistributions in binary form must reproduce the above copyright | | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the | | 13 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. | | 14 | * documentation and/or other materials provided with the distribution. |
| @@ -22,27 +22,27 @@ | | | @@ -22,27 +22,27 @@ |
22 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | | 22 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
23 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | | 23 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
24 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | | 24 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
25 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | | 25 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
26 | * SUCH DAMAGE. | | 26 | * SUCH DAMAGE. |
27 | * | | 27 | * |
28 | */ | | 28 | */ |
29 | | | 29 | |
30 | #include <sys/cdefs.h> | | 30 | #include <sys/cdefs.h> |
31 | #if defined(LIBC_SCCS) && !defined(lint) | | 31 | #if defined(LIBC_SCCS) && !defined(lint) |
32 | #if 0 | | 32 | #if 0 |
33 | __FBSDID("$FreeBSD: src/lib/libc/stdlib/strfmon.c,v 1.14 2003/03/20 08:18:55 ache Exp $"); | | 33 | __FBSDID("$FreeBSD: src/lib/libc/stdlib/strfmon.c,v 1.14 2003/03/20 08:18:55 ache Exp $"); |
34 | #else | | 34 | #else |
35 | __RCSID("$NetBSD: strfmon.c,v 1.18 2022/08/18 11:05:02 christos Exp $"); | | 35 | __RCSID("$NetBSD: strfmon.c,v 1.19 2023/09/28 10:03:41 martin Exp $"); |
36 | #endif | | 36 | #endif |
37 | #endif /* LIBC_SCCS and not lint */ | | 37 | #endif /* LIBC_SCCS and not lint */ |
38 | | | 38 | |
39 | #include "namespace.h" | | 39 | #include "namespace.h" |
40 | | | 40 | |
41 | #include <sys/types.h> | | 41 | #include <sys/types.h> |
42 | #include <assert.h> | | 42 | #include <assert.h> |
43 | #include <ctype.h> | | 43 | #include <ctype.h> |
44 | #include <errno.h> | | 44 | #include <errno.h> |
45 | #include <limits.h> | | 45 | #include <limits.h> |
46 | #include <locale.h> | | 46 | #include <locale.h> |
47 | #include <monetary.h> | | 47 | #include <monetary.h> |
48 | #include <stdarg.h> | | 48 | #include <stdarg.h> |
| @@ -131,46 +131,46 @@ vstrfmon_l(char * __restrict s, size_t m | | | @@ -131,46 +131,46 @@ vstrfmon_l(char * __restrict s, size_t m |
131 | sep_by_space, | | 131 | sep_by_space, |
132 | sign_posn, | | 132 | sign_posn, |
133 | *currency_symbol; | | 133 | *currency_symbol; |
134 | const char *signstr; | | 134 | const char *signstr; |
135 | | | 135 | |
136 | char *tmpptr; /* temporary vars */ | | 136 | char *tmpptr; /* temporary vars */ |
137 | int sverrno; | | 137 | int sverrno; |
138 | | | 138 | |
139 | lc = localeconv_l(loc); | | 139 | lc = localeconv_l(loc); |
140 | dst = s; | | 140 | dst = s; |
141 | fmt = format; | | 141 | fmt = format; |
142 | asciivalue = NULL; | | 142 | asciivalue = NULL; |
143 | currency_symbol = NULL; | | 143 | currency_symbol = NULL; |
144 | pad_size = 0; | | | |
145 | | | 144 | |
146 | while (*fmt) { | | 145 | while (*fmt) { |
147 | /* pass nonformating characters AS IS */ | | 146 | /* pass nonformating characters AS IS */ |
148 | if (*fmt != '%') | | 147 | if (*fmt != '%') |
149 | goto literal; | | 148 | goto literal; |
150 | | | 149 | |
151 | /* '%' found ! */ | | 150 | /* '%' found ! */ |
152 | | | 151 | |
153 | /* "%%" mean just '%' */ | | 152 | /* "%%" mean just '%' */ |
154 | if (*(fmt+1) == '%') { | | 153 | if (*(fmt+1) == '%') { |
155 | fmt++; | | 154 | fmt++; |
156 | literal: | | 155 | literal: |
157 | PRINT(*fmt++); | | 156 | PRINT(*fmt++); |
158 | continue; | | 157 | continue; |
159 | } | | 158 | } |
160 | | | 159 | |
161 | /* set up initial values */ | | 160 | /* set up initial values */ |
162 | flags = (NEED_GROUPING|LOCALE_POSN); | | 161 | flags = (NEED_GROUPING|LOCALE_POSN); |
163 | pad_char = ' '; /* padding character is "space" */ | | 162 | pad_char = ' '; /* padding character is "space" */ |
| | | 163 | pad_size = 0; /* no padding initially */ |
164 | left_prec = -1; /* no left precision specified */ | | 164 | left_prec = -1; /* no left precision specified */ |
165 | right_prec = -1; /* no right precision specified */ | | 165 | right_prec = -1; /* no right precision specified */ |
166 | width = -1; /* no width specified */ | | 166 | width = -1; /* no width specified */ |
167 | value = 0; /* we have no value to print now */ | | 167 | value = 0; /* we have no value to print now */ |
168 | | | 168 | |
169 | /* Flags */ | | 169 | /* Flags */ |
170 | while (/* CONSTCOND */ 1) { | | 170 | while (/* CONSTCOND */ 1) { |
171 | switch (*++fmt) { | | 171 | switch (*++fmt) { |
172 | case '=': /* fill character */ | | 172 | case '=': /* fill character */ |
173 | pad_char = *++fmt; | | 173 | pad_char = *++fmt; |
174 | if (pad_char == '\0') | | 174 | if (pad_char == '\0') |
175 | goto format_error; | | 175 | goto format_error; |
176 | continue; | | 176 | continue; |