summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/_assert.h8
-rw-r--r--src/_nonstd.h19
-rw-r--r--src/ctype/_ctype.h3
-rw-r--r--src/ctype/isblank.c3
-rw-r--r--src/ctype/iscntrl.c2
-rw-r--r--src/ctype/isgraph.c2
-rw-r--r--src/ctype/islower.c2
-rw-r--r--src/ctype/isprint.c2
-rw-r--r--src/ctype/ispunct.c2
-rw-r--r--src/ctype/isspace.c2
-rw-r--r--src/ctype/isupper.c2
-rw-r--r--src/ctype/isxdigit.c2
-rw-r--r--src/ctype/tolower.c3
-rw-r--r--src/ctype/toupper.c3
-rw-r--r--src/locale/__get_locale.c13
-rw-r--r--src/locale/__load_locale.c64
-rw-r--r--src/locale/_locale.h5
-rw-r--r--src/locale/localeconv.c3
-rw-r--r--src/locale/setlocale.c3
-rw-r--r--src/nonstd/__libc.c60
-rw-r--r--src/nonstd/__libc_per_thread.c14
-rw-r--r--src/unistd/fdatasync.c1
22 files changed, 67 insertions, 151 deletions
diff --git a/src/_assert.h b/src/_assert.h
index 2d27edfb..9698f5a2 100644
--- a/src/_assert.h
+++ b/src/_assert.h
@@ -6,7 +6,7 @@
if (!__ptr) { \
struct __constraint_info _ci = {0}; \
_ci.func = __func__; \
- __libc.stdlib.constraint_handler("Undefined behavior: " \
+ __stdlib.constraint_handler("Undefined behavior: " \
"Parameter " #__ptr " can not be NULL", &_ci, EFAULT); \
} \
} while (0)
@@ -15,7 +15,7 @@
if (!__n) { \
struct __constraint_info _ci = {0}; \
_ci.func = __func__; \
- __libc.stdlib.constraint_handler("Undefined behavior: " \
+ __stdlib.constraint_handler("Undefined behavior: " \
"Parameter " #__n " can not be 0", &_ci, ERANGE); \
} \
} while (0)
@@ -28,13 +28,13 @@
if (_sentinel && (_n != _sentinel && (_n < _min || _n > _max))) { \
struct __constraint_info _ci = {0}; \
_ci.func = __func__; \
- __libc.stdlib.constraint_handler("Undefined behavior: " \
+ __stdlib.constraint_handler("Undefined behavior: " \
"Paramater " #_n " must be representable as a " #_type \
"or be equal to " #_sentinel, &_ci, ERANGE); \
} else if (_n < _min || _n > _max) { \
struct __constraint_info _ci = {0}; \
_ci.func = __func__; \
- __libc.stdlib.constraint_handler("Undefined behavior: " \
+ __stdlib.constraint_handler("Undefined behavior: " \
"Parameter " #_n " must be representable as a " #_type, \
&_ci, ERANGE); \
} \
diff --git a/src/_nonstd.h b/src/_nonstd.h
deleted file mode 100644
index 4f8cd478..00000000
--- a/src/_nonstd.h
+++ /dev/null
@@ -1,19 +0,0 @@
-#ifndef ___NONSTD_H__
-#define ___NONSTD_H__
-
-typedef enum {
- /* locale.h */
- THREAD_LOCALE,
- GLOBAL_LOCALE,
- LCONV,
- LOAD_LOCALE,
-
- /* [w]ctype.h */
- CTYPE,
- TOLOWER,
- TOUPPER,
-} LIBC_INTERNAL;
-
-void *__libc(LIBC_INTERNAL __variable);
-
-#endif
diff --git a/src/ctype/_ctype.h b/src/ctype/_ctype.h
index f64553c1..be3e8401 100644
--- a/src/ctype/_ctype.h
+++ b/src/ctype/_ctype.h
@@ -1,7 +1,8 @@
#ifndef ___CTYPE_H__
#define ___CTYPE_H__
-#include "../_nonstd.h"
+#include "../_assert.h"
+#include "../locale/_locale.h"
typedef enum {
CT_ALPHA = (1 << 0),
diff --git a/src/ctype/isblank.c b/src/ctype/isblank.c
index d22d2315..b71b0faa 100644
--- a/src/ctype/isblank.c
+++ b/src/ctype/isblank.c
@@ -2,13 +2,12 @@
#include "limits.h"
#include "locale.h"
#include "_ctype.h"
-#include "../_assert.h"
/** test whether a character is blank **/
int isblank(int c)
{
- unsigned int *map = __libc(CTYPE);
+ unsigned int *map = __get_locale()->lc_ctype.ctattr;
ASSERT_REPRESENTABLE(c, 0, UCHAR_MAX, "unsigned char", EOF);
diff --git a/src/ctype/iscntrl.c b/src/ctype/iscntrl.c
index ef28ff20..d90803e5 100644
--- a/src/ctype/iscntrl.c
+++ b/src/ctype/iscntrl.c
@@ -7,7 +7,7 @@
int iscntrl(int c)
{
- unsigned int *map = __libc(CTYPE);
+ unsigned int *map = __get_locale()->lc_ctype.ctattr;
ASSERT_REPRESENTABLE(c, 0, UCHAR_MAX, unsigned char, EOF);
diff --git a/src/ctype/isgraph.c b/src/ctype/isgraph.c
index a6490d8f..72be27b3 100644
--- a/src/ctype/isgraph.c
+++ b/src/ctype/isgraph.c
@@ -7,7 +7,7 @@
int isgraph(int c)
{
- unsigned int *map = __libc(CTYPE);
+ unsigned int *map = __get_locale()->lc_ctype.ctattr;
ASSERT_REPRESENTABLE(c, 0, UCHAR_MAX, unsigned char, EOF);
diff --git a/src/ctype/islower.c b/src/ctype/islower.c
index 35c8236d..6dfedcc6 100644
--- a/src/ctype/islower.c
+++ b/src/ctype/islower.c
@@ -7,7 +7,7 @@
int islower(int c)
{
- unsigned int *map = __libc(CTYPE);
+ unsigned int *map = __get_locale()->lc_ctype.ctattr;
ASSERT_REPRESENTABLE(c, 0, UCHAR_MAX, unsigned char, EOF);
diff --git a/src/ctype/isprint.c b/src/ctype/isprint.c
index c3deaebd..e4b5a531 100644
--- a/src/ctype/isprint.c
+++ b/src/ctype/isprint.c
@@ -7,7 +7,7 @@
int isprint(int c)
{
- unsigned int *map = __libc(CTYPE);
+ unsigned int *map = __get_locale()->lc_ctype.ctattr;
ASSERT_REPRESENTABLE(c, 0, UCHAR_MAX, unsigned char, EOF);
diff --git a/src/ctype/ispunct.c b/src/ctype/ispunct.c
index 12d0cf16..e73461e1 100644
--- a/src/ctype/ispunct.c
+++ b/src/ctype/ispunct.c
@@ -7,7 +7,7 @@
int ispunct(int c)
{
- unsigned int *map = __libc(CTYPE);
+ unsigned int *map = __get_locale()->lc_ctype.ctattr;
ASSERT_REPRESENTABLE(c, 0, UCHAR_MAX, unsigned char, EOF);
diff --git a/src/ctype/isspace.c b/src/ctype/isspace.c
index fb913c49..d4eeb134 100644
--- a/src/ctype/isspace.c
+++ b/src/ctype/isspace.c
@@ -7,7 +7,7 @@
int isspace(int c)
{
- unsigned int *map = __libc(CTYPE);
+ unsigned int *map = __get_locale()->lc_ctype.ctattr;
ASSERT_REPRESENTABLE(c, 0, UCHAR_MAX, unsigned char, EOF);
diff --git a/src/ctype/isupper.c b/src/ctype/isupper.c
index ff07ff59..e0eb545e 100644
--- a/src/ctype/isupper.c
+++ b/src/ctype/isupper.c
@@ -7,7 +7,7 @@
int isupper(int c)
{
- unsigned int *map = __libc(CTYPE);
+ unsigned int *map = __get_locale()->lc_ctype.ctattr;
ASSERT_REPRESENTABLE(c, 0, UCHAR_MAX, unsigned char, EOF);
diff --git a/src/ctype/isxdigit.c b/src/ctype/isxdigit.c
index 9f9e0b91..9d73d662 100644
--- a/src/ctype/isxdigit.c
+++ b/src/ctype/isxdigit.c
@@ -7,7 +7,7 @@
int isxdigit(int c)
{
- unsigned int *map = __libc(CTYPE);
+ unsigned int *map = __get_locale()->lc_ctype.ctattr;
ASSERT_REPRESENTABLE(c, 0, UCHAR_MAX, unsigned char, EOF);
diff --git a/src/ctype/tolower.c b/src/ctype/tolower.c
index 4512ef36..3da90645 100644
--- a/src/ctype/tolower.c
+++ b/src/ctype/tolower.c
@@ -1,14 +1,13 @@
#include <ctype.h>
#include "stdio.h"
#include "limits.h"
-#include "../_assert.h"
#include "_ctype.h"
/** convert an uppercase letter to lowercase **/
int tolower(int c)
{
- unsigned char *map = __libc(TOLOWER);
+ unsigned char *map = __get_locale()->lc_ctype.ctolower;
ASSERT_REPRESENTABLE(c, 0, UCHAR_MAX, unsigned char, EOF);
diff --git a/src/ctype/toupper.c b/src/ctype/toupper.c
index 897d059e..3addcada 100644
--- a/src/ctype/toupper.c
+++ b/src/ctype/toupper.c
@@ -1,14 +1,13 @@
#include <ctype.h>
#include "stdio.h"
#include "limits.h"
-#include "../_assert.h"
#include "_ctype.h"
/** convert a lowercase letter to uppercase **/
int toupper(int c)
{
- unsigned char *map = __libc(TOUPPER);
+ unsigned char *map = __get_locale()->lc_ctype.ctoupper;
ASSERT_REPRESENTABLE(c, 0, UCHAR_MAX, unsigned char, EOF);
diff --git a/src/locale/__get_locale.c b/src/locale/__get_locale.c
new file mode 100644
index 00000000..4722175c
--- /dev/null
+++ b/src/locale/__get_locale.c
@@ -0,0 +1,13 @@
+#include "locale.h"
+#include "_locale.h"
+
+/*
+This implementation only supports a single, global locale. A second
+implementation will be needed for POSIX.1-2008 per-thread locales.
+*/
+
+struct __locale_t * __get_locale(void)
+{
+ static struct __locale_t l;
+ return &l;
+}
diff --git a/src/locale/__load_locale.c b/src/locale/__load_locale.c
index d79bb4e4..deff64bb 100644
--- a/src/locale/__load_locale.c
+++ b/src/locale/__load_locale.c
@@ -110,40 +110,40 @@ char * __load_locale(struct __locale_t *loc, int mask, const char *name)
strcpy(loc->monetary, name);
if (localefile == NULL) {
- loc->mn.mon_decimal_point = "";
- loc->mn.mon_thousands_sep = "";
- loc->mn.mon_grouping = "";
- loc->mn.positive_sign = "";
- loc->mn.negative_sign = "";
- loc->mn.currency_symbol = "";
- loc->mn.frac_digits = CHAR_MAX;
- loc->mn.p_cs_precedes = CHAR_MAX;
- loc->mn.n_cs_precedes = CHAR_MAX;
- loc->mn.p_sep_by_space = CHAR_MAX;
- loc->mn.n_sep_by_space = CHAR_MAX;
- loc->mn.p_sign_posn = CHAR_MAX;
- loc->mn.n_sign_posn = CHAR_MAX;
- loc->mn.int_curr_symbol = "";
- loc->mn.int_frac_digits = CHAR_MAX;
+ loc->lconv.mon_decimal_point = "";
+ loc->lconv.mon_thousands_sep = "";
+ loc->lconv.mon_grouping = "";
+ loc->lconv.positive_sign = "";
+ loc->lconv.negative_sign = "";
+ loc->lconv.currency_symbol = "";
+ loc->lconv.frac_digits = CHAR_MAX;
+ loc->lconv.p_cs_precedes = CHAR_MAX;
+ loc->lconv.n_cs_precedes = CHAR_MAX;
+ loc->lconv.p_sep_by_space = CHAR_MAX;
+ loc->lconv.n_sep_by_space = CHAR_MAX;
+ loc->lconv.p_sign_posn = CHAR_MAX;
+ loc->lconv.n_sign_posn = CHAR_MAX;
+ loc->lconv.int_curr_symbol = "";
+ loc->lconv.int_frac_digits = CHAR_MAX;
#if defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__
- loc->mn.int_p_cs_precedes = CHAR_MAX;
- loc->mn.int_n_cs_precedes = CHAR_MAX;
- loc->mn.int_p_sep_by_space = CHAR_MAX;
- loc->mn.int_n_sep_by_space = CHAR_MAX;
- loc->mn.int_p_sign_posn = CHAR_MAX;
- loc->mn.int_n_sign_posn = CHAR_MAX;
+ loc->lconv.int_p_cs_precedes = CHAR_MAX;
+ loc->lconv.int_n_cs_precedes = CHAR_MAX;
+ loc->lconv.int_p_sep_by_space = CHAR_MAX;
+ loc->lconv.int_n_sep_by_space = CHAR_MAX;
+ loc->lconv.int_p_sign_posn = CHAR_MAX;
+ loc->lconv.int_n_sign_posn = CHAR_MAX;
#else
- loc->mn.__int_p_cs_precedes = CHAR_MAX;
- loc->mn.__int_n_cs_precedes = CHAR_MAX;
- loc->mn.__int_p_sep_by_space = CHAR_MAX;
- loc->mn.__int_n_sep_by_space = CHAR_MAX;
- loc->mn.__int_p_sign_posn = CHAR_MAX;
- loc->mn.__int_n_sign_posn = CHAR_MAX;
+ loc->lconv.__int_p_cs_precedes = CHAR_MAX;
+ loc->lconv.__int_n_cs_precedes = CHAR_MAX;
+ loc->lconv.__int_p_sep_by_space = CHAR_MAX;
+ loc->lconv.__int_n_sep_by_space = CHAR_MAX;
+ loc->lconv.__int_p_sign_posn = CHAR_MAX;
+ loc->lconv.__int_n_sign_posn = CHAR_MAX;
#endif
} else {
/*
- loc->mn.monetary fields;
+ loc->lconv.monetary fields;
*/
}
}
@@ -152,12 +152,12 @@ char * __load_locale(struct __locale_t *loc, int mask, const char *name)
strcpy(loc->numeric, name);
if (localefile == NULL) {
- loc->mn.decimal_point = ".";
- loc->mn.thousands_sep = "";
- loc->mn.grouping = "";
+ loc->lconv.decimal_point = ".";
+ loc->lconv.thousands_sep = "";
+ loc->lconv.grouping = "";
} else {
/*
- loc->mn.numeric fields
+ loc->lconv.numeric fields
*/
}
}
diff --git a/src/locale/_locale.h b/src/locale/_locale.h
index bed7e0f5..8f974ef3 100644
--- a/src/locale/_locale.h
+++ b/src/locale/_locale.h
@@ -28,7 +28,7 @@ struct __locale_t {
char monetary[UCHAR_MAX];
char numeric[UCHAR_MAX];
- struct lconv mn;
+ struct lconv lconv;
char time[UCHAR_MAX];
struct {
@@ -60,6 +60,7 @@ struct __locale_t {
} lc_time;
};
-char * __load_locale(struct __locale_t *, int, const char *);
+char * __load_locale(struct __locale_t *loc, int mask, const char *name);
+struct __locale_t * __get_locale(void);
#endif
diff --git a/src/locale/localeconv.c b/src/locale/localeconv.c
index e63402e2..0021c13a 100644
--- a/src/locale/localeconv.c
+++ b/src/locale/localeconv.c
@@ -1,6 +1,5 @@
#include <locale.h>
#include "_locale.h"
-#include "../_nonstd.h"
/** return locale-specific information **/
struct lconv * localeconv(void)
@@ -8,7 +7,7 @@ struct lconv * localeconv(void)
/*
RETURN_SUCCESS(a pointer to a filled-in STRUCTDEF(lconv) for the current locale);
*/
- return __libc(LCONV);
+ return &(__get_locale()->lconv);
}
/***
diff --git a/src/locale/setlocale.c b/src/locale/setlocale.c
index 068bf858..72478686 100644
--- a/src/locale/setlocale.c
+++ b/src/locale/setlocale.c
@@ -2,7 +2,6 @@
#include "string.h"
#include "stdlib.h"
#include "_locale.h"
-#include "../_nonstd.h"
#include "LC_ALL_MASK.c"
#include "LC_COLLATE_MASK.c"
@@ -14,7 +13,7 @@
char * setlocale(int category, const char *locale)
{
- struct __locale_t *l = __libc(GLOBAL_LOCALE);
+ struct __locale_t *l = __get_locale();
int mask = 0;
if (locale == NULL) {
diff --git a/src/nonstd/__libc.c b/src/nonstd/__libc.c
deleted file mode 100644
index 0d8351ab..00000000
--- a/src/nonstd/__libc.c
+++ /dev/null
@@ -1,60 +0,0 @@
-#include "../_nonstd.h"
-#include "../locale/_locale.h"
-
-void *__libc(LIBC_INTERNAL variable)
-{
- extern void *__libc_per_thread(LIBC_INTERNAL __variable);
- static struct __locale_t locale;
-
- void *r = (void*)0;
-
- switch (variable) {
- case THREAD_LOCALE:
- r = __libc_per_thread(THREAD_LOCALE);
- if (r) {
- break;
- }
- /* fallthru */
-
- case GLOBAL_LOCALE:
- r = &locale;
- break;
-
- case CTYPE:
- r = __libc(THREAD_LOCALE);
- if (((struct __locale_t*)r)->ctype[0] == '\0') {
- r = &locale;
- }
- r = ((struct __locale_t*)r)->lc_ctype.ctattr;
- break;
-
- case TOLOWER:
- r = __libc(THREAD_LOCALE);
- if (((struct __locale_t*)r)->ctype[0] == '\0') {
- r = &locale;
- }
- r = ((struct __locale_t*)r)->lc_ctype.ctolower;
- break;
-
- case TOUPPER:
- r = __libc(THREAD_LOCALE);
- if (((struct __locale_t*)r)->ctype[0] == '\0') {
- r = &locale;
- }
- r = ((struct __locale_t*)r)->lc_ctype.ctoupper;
- break;
-
- case LCONV:
- r = __libc(THREAD_LOCALE);
- if (((struct __locale_t*)r)->numeric[0] == '\0') {
- r = &locale;
- }
- r = &(((struct __locale_t*)r)->mn);
- break;
-
- default:
- break;
- }
-
- return r;
-}
diff --git a/src/nonstd/__libc_per_thread.c b/src/nonstd/__libc_per_thread.c
deleted file mode 100644
index d487dcad..00000000
--- a/src/nonstd/__libc_per_thread.c
+++ /dev/null
@@ -1,14 +0,0 @@
-#include "../_nonstd.h"
-#include "../locale/_locale.h"
-#include "../_perthread.h"
-
-void *__libc_per_thread(LIBC_INTERNAL variable)
-{
- THREAD_LOCAL struct __locale_t locale;
-
- if (variable == THREAD_LOCALE) {
- return &locale;
- }
-
- return (void*)0;
-}
diff --git a/src/unistd/fdatasync.c b/src/unistd/fdatasync.c
index 3de269ec..904c12fe 100644
--- a/src/unistd/fdatasync.c
+++ b/src/unistd/fdatasync.c
@@ -1,5 +1,4 @@
#include <unistd.h>
-#include "__nonstd.h"
int fdatasync(int fildes)
{