shithub: scc

Download patch

ref: 4606d3ce5f3e8afbd0ba8d4d9971bf981838df16
parent: 2d390f87f239823f51aa811504980688c24813cf
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Fri Sep 21 16:55:56 EDT 2018

[lib/c] Fix locale.h functions

--- 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;
 }
--- a/root/include/scc/locale.h
+++ b/root/include/scc/locale.h
@@ -31,12 +31,6 @@
 	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);
--- /dev/null
+++ b/tests/libc/execute/0035-setlocale.c
@@ -1,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;
+}
--- /dev/null
+++ b/tests/libc/execute/0036-localeconv.c
@@ -1,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;
+}
--- 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