Skip to content

Commit e622e75

Browse files
committed
added locale.h and added more wide-char prototypes
1 parent a494909 commit e622e75

File tree

19 files changed

+331
-29
lines changed

19 files changed

+331
-29
lines changed

src/libc/header_test.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <inttypes.h>
1111
#include <iso646.h>
1212
#include <limits.h>
13+
#include <locale.h>
1314
#include <math.h>
1415
#include <setjmp.h>
1516
#include <stdalign.h>

src/libc/include/__wchar_def.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,6 @@
33

44
#include <cdefs.h>
55

6-
#ifndef _WCHAR_T_DEFINED
7-
#define _WCHAR_T_DEFINED
8-
#ifndef __cplusplus
9-
typedef __WCHAR_TYPE__ wchar_t;
10-
#endif /* __cplusplus */
11-
#endif /* _WCHAR_T_DEFINED */
12-
136
#ifndef _WINT_T_DEFINED
147
#define _WINT_T_DEFINED
158
typedef __WINT_TYPE__ wint_t;

src/libc/include/cdefs.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,16 @@
3636
# endif /* __cplusplus */
3737
#endif /* NULL */
3838

39-
#ifndef SIZE_T_DEFINED
40-
#define SIZE_T_DEFINED
39+
#ifndef _SIZE_T_DEFINED
40+
#define _SIZE_T_DEFINED
4141
typedef __SIZE_TYPE__ size_t;
42-
#endif /* SIZE_T_DEFINED */
42+
#endif /* _SIZE_T_DEFINED */
43+
44+
#ifndef _WCHAR_T_DEFINED
45+
#define _WCHAR_T_DEFINED
46+
#ifndef __cplusplus
47+
typedef __WCHAR_TYPE__ wchar_t;
48+
#endif /* __cplusplus */
49+
#endif /* _WCHAR_T_DEFINED */
4350

4451
#endif /* _CDEFS_H */

src/libc/include/inttypes.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -177,21 +177,21 @@ typedef struct {
177177

178178
__BEGIN_DECLS
179179

180-
extern intmax_t imaxabs(intmax_t __n) __NOEXCEPT_CONST;
180+
intmax_t imaxabs(intmax_t __n) __NOEXCEPT_CONST;
181181

182-
extern imaxdiv_t imaxdiv(intmax_t __numer, intmax_t __denom) __NOEXCEPT_CONST;
182+
imaxdiv_t imaxdiv(intmax_t __numer, intmax_t __denom) __NOEXCEPT_CONST;
183183

184-
intmax_t strtoimax(
185-
const char *__restrict nptr,
186-
char **__restrict endptr,
187-
int base
188-
) __attribute__((nonnull(1)));
184+
intmax_t strtoimax(const char *__restrict nptr, char **__restrict endptr, int base)
185+
__attribute__((nonnull(1)));
189186

190-
uintmax_t strtoumax(
191-
const char *__restrict nptr,
192-
char **__restrict endptr,
193-
int base
194-
) __attribute__((nonnull(1)));
187+
uintmax_t strtoumax(const char *__restrict nptr, char **__restrict endptr, int base)
188+
__attribute__((nonnull(1)));
189+
190+
intmax_t wcstoimax(const wchar_t *__restrict nptr, wchar_t **__restrict endptr, int base)
191+
__attribute__((nonnull(1)));
192+
193+
uintmax_t wcstoumax(const wchar_t *__restrict nptr, wchar_t **__restrict endptr, int base)
194+
__attribute__((nonnull(1)));
195195

196196
__END_DECLS
197197

src/libc/include/limits.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,8 @@
4848
#define ULLONG_MAX __ULONG_LONG_MAX__
4949
#define ULLONG_WIDTH __LLONG_WIDTH__
5050

51+
#ifndef MB_LEN_MAX
52+
#define MB_LEN_MAX 1
53+
#endif /* MB_LEN_MAX */
54+
5155
#endif /* _LIMITS_H */

src/libc/include/locale.h

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#ifndef _LOCALE_H
2+
#define _LOCALE_H
3+
4+
#include <cdefs.h>
5+
6+
struct lconv {
7+
char* decimal_point; /* "." */
8+
char* thousands_sep; /* "" */
9+
char* grouping; /* "" */
10+
char* mon_decimal_point; /* "" */
11+
char* mon_thousands_sep; /* "" */
12+
char* mon_grouping; /* "" */
13+
char* positive_sign; /* "" */
14+
char* negative_sign; /* "" */
15+
char* currency_symbol; /* "" */
16+
char frac_digits; /* CHAR_MAX */
17+
char p_cs_precedes; /* CHAR_MAX */
18+
char n_cs_precedes; /* CHAR_MAX */
19+
char p_sep_by_space; /* CHAR_MAX */
20+
char n_sep_by_space; /* CHAR_MAX */
21+
char p_sign_posn; /* CHAR_MAX */
22+
char n_sign_posn; /* CHAR_MAX */
23+
char* int_curr_symbol; /* "" */
24+
char int_frac_digits; /* CHAR_MAX */
25+
char int_p_cs_precedes; /* CHAR_MAX */
26+
char int_n_cs_precedes; /* CHAR_MAX */
27+
char int_p_sep_by_space; /* CHAR_MAX */
28+
char int_n_sep_by_space; /* CHAR_MAX */
29+
char int_p_sign_posn; /* CHAR_MAX */
30+
char int_n_sign_posn; /* CHAR_MAX */
31+
};
32+
33+
#define LC_COLLATE (0x010)
34+
#define LC_CTYPE (0x020)
35+
#define LC_MONETARY (0x040)
36+
#define LC_NUMERIC (0x080)
37+
#define LC_TIME (0x100)
38+
#define LC_MESSAGES (0x200)
39+
#define LC_ALL (LC_COLLATE | LC_CTYPE | LC_MONETARY | LC_NUMERIC | LC_TIME | LC_MESSAGES)
40+
41+
#ifdef __cplusplus
42+
extern "C" {
43+
#endif
44+
45+
char* setlocale(int category, const char* locale);
46+
47+
struct lconv* localeconv(void);
48+
49+
#ifdef __cplusplus
50+
}
51+
#endif
52+
53+
#endif /* _LOCALE_H */

src/libc/include/stddef.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,6 @@
77

88
typedef __PTRDIFF_TYPE__ ptrdiff_t;
99

10-
#ifndef _WCHAR_T_DEFINED
11-
#define _WCHAR_T_DEFINED
12-
#ifndef __cplusplus
13-
typedef __WCHAR_TYPE__ wchar_t;
14-
#endif /* __cplusplus */
15-
#endif /* _WCHAR_T_DEFINED */
16-
1710
#if __STDC_VERSION__ >= 199901L || __cplusplus >= 201103L
1811
typedef struct {
1912
long long __max_align_ll __attribute__((__aligned__(__alignof__( long long))));

src/libc/include/stdlib.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,20 @@ lldiv_t lldiv(long long numer, long long denom);
123123
i48div_t i48div(signed __int48 numer, signed __int48 denom) __NOEXCEPT_CONST;
124124
#endif /* __SIZEOF_INT48__ */
125125

126+
int mblen(const char* s, size_t n);
127+
128+
int mbtowc(wchar_t* pwc, const char* s, size_t n);
129+
130+
int wctomb(char* s, wchar_t wchar);
131+
132+
size_t mbstowcs(wchar_t* pwcs, const char* s, size_t n);
133+
134+
size_t wcstombs(char* s, const wchar_t* pwcs, size_t n);
135+
136+
int __mb_cur_max(void);
137+
138+
#define MB_CUR_MAX __mb_cur_max()
139+
126140
__END_DECLS
127141

128142
#endif /* _STDLIB_H */

src/libc/include/string.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ int strncasecmp(const char *s1, const char *s2, size_t n)
118118

119119
char* strerror(int errnum);
120120

121+
int strcoll(const char *s1, const char *s2);
122+
123+
size_t strxfrm(char *__restrict dest, const char *__restrict src, size_t n);
124+
121125
__END_DECLS
122126

123127
#endif /* _STRING_H */

src/libc/include/wchar.h

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@
22
#define _WCHAR_H
33

44
#include <__wchar_def.h>
5+
#include <stdio.h>
6+
#include <time.h>
7+
8+
typedef struct {
9+
int __count;
10+
union {
11+
wint_t __value;
12+
unsigned char __bytes[sizeof(wint_t)];
13+
};
14+
} mbstate_t;
515

616
__BEGIN_DECLS
717

@@ -65,6 +75,86 @@ int wcscmp(const wchar_t *s1, const wchar_t *s2)
6575
int wcsncmp(const wchar_t *s1, const wchar_t *s2, size_t n)
6676
__attribute__((nonnull(1, 2)));
6777

78+
int wprintf(const wchar_t *__restrict format, ...);
79+
80+
int vwprintf(const wchar_t *__restrict format, va_list va);
81+
82+
int swprintf(wchar_t *__restrict buffer, size_t count, const wchar_t *__restrict format, ...);
83+
84+
int vswprintf(wchar_t *__restrict buffer, size_t count, const wchar_t *__restrict format, va_list va);
85+
86+
int fwprintf(FILE *__restrict stream, const wchar_t *__restrict format, ...);
87+
88+
int vfwprintf(FILE *__restrict stream, const wchar_t *__restrict format, va_list va);
89+
90+
int wscanf(const wchar_t *__restrict format, ...);
91+
92+
int vwscanf(const wchar_t *__restrict format, va_list arg);
93+
94+
int swscanf(const wchar_t *__restrict s, const wchar_t *__restrict format, ...);
95+
96+
int vswscanf(const wchar_t *__restrict s, const wchar_t *__restrict format, va_list arg);
97+
98+
int fwscanf(FILE *__restrict stream, const wchar_t *__restrict format, ...);
99+
100+
int vfwscanf(FILE *__restrict stream, const wchar_t *__restrict format, va_list arg);
101+
102+
wint_t fgetwc(FILE *stream);
103+
104+
wchar_t *fgetws(wchar_t *__restrict s, int n, FILE *__restrict stream);
105+
106+
wint_t fputwc(wchar_t c, FILE *stream);
107+
108+
int fputws(const wchar_t *__restrict s, FILE *__restrict stream);
109+
110+
int fwide(FILE *stream, int mode);
111+
112+
wint_t getwc(FILE *stream);
113+
114+
wint_t getwchar(void);
115+
116+
wint_t putwc(wchar_t c, FILE *stream);
117+
118+
wint_t putwchar(wchar_t c);
119+
120+
wint_t ungetwc(wint_t c, FILE *stream);
121+
122+
float wcstof(const wchar_t *__restrict nptr, wchar_t * *__restrict endptr);
123+
124+
double wcstod(const wchar_t *__restrict nptr, wchar_t **__restrict endptr);
125+
126+
long double wcstold(const wchar_t *__restrict nptr, wchar_t **__restrict endptr);
127+
128+
long wcstol(const wchar_t *__restrict nptr, wchar_t **__restrict endptr, int base);
129+
130+
long long wcstoll(const wchar_t *__restrict nptr, wchar_t **__restrict endptr, int base);
131+
132+
unsigned long wcstoul(const wchar_t *__restrict nptr, wchar_t **__restrict endptr, int base);
133+
134+
unsigned long long wcstoull(const wchar_t *__restrict nptr, wchar_t **__restrict endptr, int base);
135+
136+
size_t wcsftime(wchar_t *__restrict s, size_t maxsize, const wchar_t *__restrict format, const struct tm *__restrict timeptr);
137+
138+
int wcscoll(const wchar_t* s1, const wchar_t* s2);
139+
140+
size_t wcsxfrm(wchar_t *__restrict s1, const wchar_t *__restrict s2, size_t n);
141+
142+
wint_t btowc(int c);
143+
144+
int wctob(wint_t c);
145+
146+
int mbsinit(const mbstate_t* ps);
147+
148+
size_t mbrlen(const char *__restrict s, size_t n, mbstate_t *__restrict ps);
149+
150+
size_t mbrtowc(wchar_t *__restrict pwc, const char *__restrict s, size_t n, mbstate_t *__restrict ps);
151+
152+
size_t wcrtomb(char *__restrict s, wchar_t wc, mbstate_t *__restrict ps);
153+
154+
size_t mbsrtowcs(wchar_t *__restrict dst, const char* *__restrict src, size_t len, mbstate_t *__restrict ps);
155+
156+
size_t wcsrtombs(char *__restrict dst, const wchar_t **__restrict src, size_t len, mbstate_t *__restrict ps);
157+
68158
__END_DECLS
69159

70160
#endif /* _WCHAR_H */

0 commit comments

Comments
 (0)