FreeBSD Bugzilla – Attachment 237546 Details for
Bug 267282
[PATCH] strfmon: Attempt to fix some strfmon(3) bugs
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
MWE
strfmon_bugs.c (text/plain), 1.73 KB, created by
Jose Luis Duran
on 2022-10-23 03:49:26 UTC
(
hide
)
Description:
MWE
Filename:
MIME Type:
Creator:
Jose Luis Duran
Created:
2022-10-23 03:49:26 UTC
Size:
1.73 KB
patch
obsolete
>/* GitHub Pull Request #619 */ >#include <stdio.h> >#include <locale.h> >#include <monetary.h> > >#define nitems(x) (sizeof((x)) / sizeof((x)[0])) > >int >main(int argc, char *argv[]) >{ > const struct { > const char *locale; > const char *expected; > } tests[] = { > { "en_US.UTF-8", "[USD123.45]" }, > { "fr_FR.UTF-8", "[123,45 EUR]" }, > }; > struct lconv *lc; > size_t i; > char string[100]; > > if (setlocale(LC_ALL, "en_US.UTF-8") == NULL) { > fprintf(stderr, "Unable to setlocale().\n"); > return (1); > } > > strfmon(string, 100, "[%8n] [%8n]", 123.45, 123.45); > printf(" Format: [%%8n] [%%8n]\n"); > printf("Expected: %s\n", "[ $123.45] [ $123.45]"); > printf(" Actual: %s\n\n", string); > > strfmon(string, 100, "[%(#5n] [%(#5n] [%(#5n]", 123.45, -123.45, 3456.781); > printf(" Format: [%%(#5n]\n"); > printf("Expected: %s\n", "[ $ 123.45 ] [($ 123.45)] [ $ 3,456.78 ]"); > printf(" Actual: %s\n\n", string); > > strfmon(string, 100, "[%!(#5n] [%!(#5n] [%!(#5n]", 123.45, -123.45, 3456.781); > printf(" Format: [%%!(#5n]\n"); > printf("Expected: %s\n", "[ 123.45 ] [( 123.45)] [ 3,456.78 ]"); > printf(" Actual: %s\n\n", string); > > lc = localeconv(); > lc->n_cs_precedes = 0; > lc->n_sep_by_space = 2; > lc->n_sign_posn = 1; > > strfmon(string, 100, "[%n]", -123.45); > printf(" Format: [%%n] (n_cs_precedes = 0, n_sep_by_space = 2, n_sign_posn = 1)\n"); > printf("Expected: %s\n", "[- 123.45$]"); > printf(" Actual: %s\n\n", string); > > for (i = 0; i < nitems(tests); ++i) { > if (setlocale(LC_MONETARY, tests[i].locale) == NULL) { > fprintf(stderr, "Unable to setlocale().\n"); > return (1); > } > > strfmon(string, 100, "[%i]", 123.45); > printf(" Format: [%%i]\n"); > printf("Expected: %s\n", tests[i].expected); > printf(" Actual: %s\n\n", string); > } > > return (0); >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 267282
: 237546