scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | README | LICENSE

commit 6ac01512d50b19e600c21d689e4dc5b49c3d2687
parent f10db9d467c19b671989d03f3dc0af105b20b784
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Fri, 21 Sep 2018 20:55:56 +0100

[lib/c] Fix locale.h functions

Diffstat:
Mlib/c/localeconv.c | 25++++++++++++++++++++-----
Mroot/include/scc/locale.h | 6------
Atests/libc/execute/0035-setlocale.c | 46++++++++++++++++++++++++++++++++++++++++++++++
Atests/libc/execute/0036-localeconv.c | 44++++++++++++++++++++++++++++++++++++++++++++
Mtests/libc/execute/libc-tests.lst | 2++
5 files changed, 112 insertions(+), 11 deletions(-)

diff --git a/lib/c/localeconv.c b/lib/c/localeconv.c @@ -5,10 +5,25 @@ struct lconv * localeconv(void) { - static struct lconv lc = { ".", "", "", "", "", "", "", "", "", "", - CHAR_MAX, CHAR_MAX, CHAR_MAX, CHAR_MAX, - CHAR_MAX, CHAR_MAX, CHAR_MAX, CHAR_MAX, - CHAR_MAX, CHAR_MAX, CHAR_MAX, CHAR_MAX, - CHAR_MAX, CHAR_MAX }; + static struct lconv lc = { + .decimal_point = ".", + .thousands_sep = "", + .grouping = "", + .mon_decimal_point = "", + .mon_thousands_sep = "", + .mon_grouping = "", + .positive_sign = "", + .negative_sign = "", + .currency_symbol = "", + .int_curr_symbol = "", + .frac_digits = CHAR_MAX, + .p_cs_precedes = CHAR_MAX, + .n_cs_precedes = CHAR_MAX, + .p_sep_by_space = CHAR_MAX, + .p_sign_posn = CHAR_MAX, + .n_sep_by_space = CHAR_MAX, + .n_sign_posn = CHAR_MAX, + .int_frac_digits = CHAR_MAX, + }; return &lc; } diff --git a/root/include/scc/locale.h b/root/include/scc/locale.h @@ -31,12 +31,6 @@ struct lconv { char p_sign_posn; char n_sign_posn; char int_frac_digits; - char int_p_cs_precedes; - char int_n_cs_precedes; - char int_p_sep_by_space; - char int_n_sep_by_space; - char int_p_sign_posn; - char int_n_sign_posn; }; extern char *setlocale(int category, const char *locale); diff --git a/tests/libc/execute/0035-setlocale.c b/tests/libc/execute/0035-setlocale.c @@ -0,0 +1,46 @@ +#include <assert.h> +#include <locale.h> +#include <stdio.h> + +/* +output: +testing +done +end: +*/ + +int +main() +{ + puts("testing"); + assert(!strcmp(setlocale(LC_ALL, NULL), "C")); + assert(!strcmp(setlocale(LC_COLLATE, NULL), "C")); + assert(!strcmp(setlocale(LC_CTYPE, NULL), "C")); + assert(!strcmp(setlocale(LC_MONETARY, NULL), "C")); + assert(!strcmp(setlocale(LC_NUMERIC, NULL), "C")); + assert(!strcmp(setlocale(LC_TIME, NULL), "C")); + + assert(!strcmp(setlocale(LC_ALL, "C"), "C")); + assert(!strcmp(setlocale(LC_COLLATE, "C"), "C")); + assert(!strcmp(setlocale(LC_CTYPE, "C"), "C")); + assert(!strcmp(setlocale(LC_MONETARY, "C"), "C")); + assert(!strcmp(setlocale(LC_NUMERIC, "C"), "C")); + assert(!strcmp(setlocale(LC_TIME, "C"), "C")); + + assert(!setlocale(LC_ALL, "invalid-locale")); + assert(!setlocale(LC_COLLATE, "invalid-locale")); + assert(!setlocale(LC_CTYPE, "invalid-locale")); + assert(!setlocale(LC_MONETARY, "invalid-locale")); + assert(!setlocale(LC_NUMERIC, "invalid-locale")); + assert(!setlocale(LC_TIME, "invalid-locale")); + + assert(setlocale(LC_ALL, "")); + assert(setlocale(LC_COLLATE, "")); + assert(setlocale(LC_CTYPE, "")); + assert(setlocale(LC_MONETARY, "")); + assert(setlocale(LC_NUMERIC, "")); + assert(setlocale(LC_TIME, "")); + puts("done"); + + return 0; +} diff --git a/tests/libc/execute/0036-localeconv.c b/tests/libc/execute/0036-localeconv.c @@ -0,0 +1,44 @@ +#include <assert.h> +#include <limits.h> +#include <locale.h> +#include <stdio.h> + +/* +output: +testing +done +end: +*/ + +int +main() +{ + struct lconv *lc; + + puts("testing"); + assert(setlocale(LC_ALL, "C")); + assert((lc = localeconv()) != NULL); + assert(!strcmp(lc->decimal_point, ".")); + assert(!strcmp(lc->thousands_sep, "")); + assert(!strcmp(lc->grouping, "")); + assert(!strcmp(lc->int_curr_symbol, "")); + assert(!strcmp(lc->currency_symbol, "")); + assert(!strcmp(lc->mon_decimal_point, "")); + assert(!strcmp(lc->mon_thousands_sep, "")); + assert(!strcmp(lc->mon_grouping, "")); + assert(!strcmp(lc->positive_sign, "")); + assert(!strcmp(lc->negative_sign, "")); + assert(!strcmp(lc->currency_symbol, "")); + assert(!strcmp(lc->int_curr_symbol, "")); + assert(lc->int_frac_digits == CHAR_MAX); + assert(lc->frac_digits == CHAR_MAX); + assert(lc->p_cs_precedes == CHAR_MAX); + assert(lc->n_cs_precedes == CHAR_MAX); + assert(lc->p_sep_by_space == CHAR_MAX); + assert(lc->n_sep_by_space == CHAR_MAX); + assert(lc->p_sign_posn == CHAR_MAX); + assert(lc->n_sign_posn == CHAR_MAX); + puts("done"); + + return 0; +} diff --git a/tests/libc/execute/libc-tests.lst b/tests/libc/execute/libc-tests.lst @@ -32,3 +32,5 @@ 0032-memset 0033-memcmp 0034-errno +0035-setlocale +0036-localeconv