9os

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit a7b2bad255fadede36a068ffe7a6dca15ac78f9f
parent ec44b05ba3449a519f99e5ce4124a1366a1b921e
Author: Roberto Vargas <roberto.vargas@arm.com>
Date:   Thu,  8 Nov 2018 15:31:53 +0000

Merge "[libc] Synchronize with scc libc"
Diffstat:
Minclude/assert.h | 4+---
Minclude/bits/amd64/arch/limits.h | 1+
Minclude/bits/amd64/arch/string.h | 3+++
Minclude/bits/arm64/arch/limits.h | 1+
Minclude/bits/arm64/arch/stdlib.h | 5+++++
Minclude/bits/arm64/arch/string.h | 2++
Ainclude/bits/i386/arch/limits.h | 18++++++++++++++++++
Ainclude/bits/i386/arch/stddef.h | 14++++++++++++++
Ainclude/bits/i386/arch/stdint.h | 115+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Ainclude/bits/i386/arch/stdio.h | 15+++++++++++++++
Ainclude/bits/i386/arch/stdlib.h | 14++++++++++++++
Ainclude/bits/i386/arch/string.h | 5+++++
Ainclude/bits/i386/arch/time.h | 8++++++++
Ainclude/bits/z80/arch/limits.h | 18++++++++++++++++++
Ainclude/bits/z80/arch/stddef.h | 14++++++++++++++
Ainclude/bits/z80/arch/stdint.h | 115+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Ainclude/bits/z80/arch/stdio.h | 15+++++++++++++++
Ainclude/bits/z80/arch/stdlib.h | 14++++++++++++++
Ainclude/bits/z80/arch/string.h | 5+++++
Ainclude/bits/z80/arch/time.h | 8++++++++
Minclude/limits.h | 1-
Ainclude/math.h | 4++++
Minclude/stdlib.h | 5+++++
Ainclude/wchar.h | 92+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Ainclude/wctype.h | 30++++++++++++++++++++++++++++++
Msrc/libc/stdio/vfprintf.c | 55+++++++++++++++++++++++++++++++++++++++++++++++++++++--
Msrc/libc/string/strcspn.c | 2+-
Msrc/libc/string/strpbrk.c | 2+-
Msrc/libc/string/strspn.c | 2+-
29 files changed, 578 insertions(+), 9 deletions(-)

diff --git a/include/assert.h b/include/assert.h @@ -1,5 +1,4 @@ - -void __assert(char *exp, char *file, long line); +extern void __assert(char *exp, char *file, long line); #undef assert #ifndef NDEBUG @@ -7,4 +6,3 @@ void __assert(char *exp, char *file, long line); #else # define assert(exp) ((void)0) #endif - diff --git a/include/bits/amd64/arch/limits.h b/include/bits/amd64/arch/limits.h @@ -1,3 +1,4 @@ +#define CHAR_BIT 8 #define SCHAR_MAX 0x7F #define SCHAR_MIN (-SCHAR_MIN-1) #define CHAR_MAX 0x7F diff --git a/include/bits/amd64/arch/string.h b/include/bits/amd64/arch/string.h @@ -1,3 +1,5 @@ #ifndef _SIZET typedef unsigned long size_t; #endif + +#define __NUMCHARS 128 +\ No newline at end of file diff --git a/include/bits/arm64/arch/limits.h b/include/bits/arm64/arch/limits.h @@ -1,3 +1,4 @@ +#define CHAR_BIT 8 #define SCHAR_MAX 0x7F #define SCHAR_MIN (-SCHAR_MIN - 1) #define CHAR_MAX 0x7F diff --git a/include/bits/arm64/arch/stdlib.h b/include/bits/arm64/arch/stdlib.h @@ -6,4 +6,9 @@ typedef unsigned long size_t; #define EXIT_FAILURE 1 #define EXIT_SUCCESS 0 +#ifndef _WCHAR_T +typedef int wchar_t; +#define _WCHAR_T +#endif + #define _ALIGNTYPE long double diff --git a/include/bits/arm64/arch/string.h b/include/bits/arm64/arch/string.h @@ -2,3 +2,5 @@ typedef unsigned long size_t; #define SIZET_ #endif + +#define __NUMCHARS 128 diff --git a/include/bits/i386/arch/limits.h b/include/bits/i386/arch/limits.h @@ -0,0 +1,18 @@ +#define CHAR_BIT 8 +#define SCHAR_MAX 0x7F +#define SCHAR_MIN (-SCHAR_MIN-1) +#define CHAR_MAX 0x7F +#define CHAR_MIN (-CHAR_MAX-1) +#define UCHAR_MAX 0xFF +#define SHRT_MAX 0x7FFF +#define SHRT_MIN (-SHRT_MAX-1) +#define USHRT_MAX 0xFFFF +#define INT_MAX 0x7FFFFFFF +#define INT_MIN (-INT_MAX-1) +#define UINT_MAX 0xFFFFFFFF +#define LONG_MAX 0x7FFFFFFF +#define LONG_MIN (-LONG_MAX-1) +#define ULONG_MAX 0xFFFFFFFF +#define LLONG_MAX 0x7FFFFFFFFFFFFFFF +#define LLONG_MIN (-LLONG_MAX-1) +#define ULLONG_MAX 0xFFFFFFFFFFFFFFFF diff --git a/include/bits/i386/arch/stddef.h b/include/bits/i386/arch/stddef.h @@ -0,0 +1,14 @@ +#ifndef _SIZET +typedef unsigned long size_t; +#define _SIZET +#endif + +#ifndef _WCHAR_T +typedef int wchar_t; +#define _WCHAR_T +#endif + +#ifndef _PTRDIFF_T +typedef long ptrdiff_t; +#define _PTRDIFF_T +#endif diff --git a/include/bits/i386/arch/stdint.h b/include/bits/i386/arch/stdint.h @@ -0,0 +1,115 @@ +#define INT8_MAX 0x7F +#define INT8_MIN (-INT8_MAX-1) +#define UINT8_MAX 0xFF + +#define INT16_MAX 0x7FFF +#define INT16_MIN (-INT16_MAX-1) +#define UINT16_MAX 0xFFFF + +#define INT32_MAX 0x7FFFFFFF +#define INT32_MIN (-INT32_MAX-1) +#define UINT32_MAX 0xFFFFFFFF + +#define INT64_MAX 0x7FFFFFFFFFFFFFFF +#define INT64_MIN (-INT64_MAX-1) +#define UINT64_MAX 0xFFFFFFFFFFFFFFFF + +#define INT_LEAST8_MIN INT8_MIN +#define INT_LEAST8_MAX INT8_MAX +#define UINT_LEAST8_MAX UINT8_MAX + +#define INT_LEAST16_MIN INT16_MIN +#define INT_LEAST16_MAX INT16_MAX +#define UINT_LEAST16_MAX UINT16_MAX + +#define INT_LEAST32_MIN INT32_MIN +#define INT_LEAST32_MAX INT32_MAX +#define UINT_LEAST32_MAX UINT32_MAX + +#define INT_LEAST64_MIN INT64_MIN +#define INT_LEAST64_MAX INT64_MAX +#define UINT_LEAST64_MAX UINT64_MAX + +#define INT_FAST8_MIN INT32_MIN +#define INT_FAST8_MAX INT32_MAX +#define UINT_FAST8_MAX UINT32_MAX + +#define INT_FAST16_MIN INT32_MIN +#define INT_FAST16_MAX INT32_MAX +#define UINT_FAST16_MAX UINT32_MAX + +#define INT_FAST32_MIN INT32_MIN +#define INT_FAST32_MAX INT32_MAX +#define UINT_FAST32_MAX UINT32_MAX + +#define INT_FAST64_MIN INT64_MIN +#define INT_FAST64_MAX INT64_MAX +#define UINT_FAST64_MAX UINT64_MAX + +#define INTPTR_MIN INT32_MIN +#define INTPTR_MAX INT32_MAX +#define UINTPTR_MAX UINT32_MAX + +#define INTMAX_MIN INT64_MIN +#define INTMAX_MAX INT64_MAX +#define UINTMAX_MAX UINT64_MAX + +#define PTRDIFF_MIN INT32_MIN +#define PTRDIFF_MAX INT32_MAX + +#define SIG_ATOMIC_MIN INT32_MIN +#define SIG_ATOMIC_MAX INT32_MAX + +#define SIZE_MAX UINT32_MAX + +#define WCHAR_MIN INT32_MIN +#define WCHAR_MAX INT32_MAX + +#define INT8_C(x) x +#define INT16_C(x) x +#define INT32_C(x) x +#define INT64_C(x) x ## LL + +#define UINT8_C(x) x +#define UINT16_C(x) x +#define UINT32_C(x) x ## U +#define UINT64_C(x) x ## ULL + +#define INTMAX_C(x) x ## LL +#define UINTMAX_C(x) x ## ULL + +typedef signed char int8_t; +typedef short int16_t; +typedef int int32_t; +typedef long long int64_t; + +typedef unsigned char uint8_t; +typedef unsigned short uint16_t; +typedef unsigned uint32_t; +typedef unsigned long long uint64_t; + +typedef signed char int8_least_t; +typedef short int16_least_t; +typedef int int32_least_t; +typedef long long int64_least_t; + +typedef unsigned char uint8_least_t; +typedef unsigned short uint16_least_t; +typedef unsigned uint32_least_t; +typedef unsigned long long uint64_least_t; + +typedef int int8_fast_t; +typedef int int16_fast_t; +typedef int int32_fast_t; +typedef long long int64_fast_t; + +typedef unsigned uint8_fast_t; +typedef unsigned uint16_fast_t; +typedef unsigned uint32_fast_t; +typedef unsigned long long uint64_fast_t; + +typedef int intptr_t; +typedef unsigned uintptr_t; + +typedef long long intmax_t; +typedef unsigned long long uintmax_t; diff --git a/include/bits/i386/arch/stdio.h b/include/bits/i386/arch/stdio.h @@ -0,0 +1,15 @@ +#ifndef _SIZET +typedef unsigned long size_t; +#define _SIZET +#endif + +#define BUFSIZ 512 +#define FILENAME_MAX 256 +#define FOPEN_MAX 16 + +#define TMP_MAX 25 +#define L_tmpnam 256 + +#define _TMPNAME "/tmp/tmp.0000000" + +typedef long fpos_t; diff --git a/include/bits/i386/arch/stdlib.h b/include/bits/i386/arch/stdlib.h @@ -0,0 +1,14 @@ +#ifndef _SIZET +typedef unsigned long size_t; +#define _SIZET +#endif + +#define EXIT_FAILURE 1 +#define EXIT_SUCCESS 0 + +#ifndef _WCHAR_T +typedef int wchar_t; +#define _WCHAR_T +#endif + +#define _ALIGNTYPE long double diff --git a/include/bits/i386/arch/string.h b/include/bits/i386/arch/string.h @@ -0,0 +1,5 @@ +#ifndef _SIZET +typedef unsigned long size_t; +#endif + +#define __NUMCHARS 128 diff --git a/include/bits/i386/arch/time.h b/include/bits/i386/arch/time.h @@ -0,0 +1,8 @@ +#ifndef _SIZET +typedef unsigned long size_t; +#define _SIZET +#endif + +#define _MAXYEAR 2037 + +typedef long int time_t; diff --git a/include/bits/z80/arch/limits.h b/include/bits/z80/arch/limits.h @@ -0,0 +1,18 @@ +#define CHAR_BIT 8 +#define SCHAR_MAX 0x7F +#define SCHAR_MIN (-SCHAR_MIN-1) +#define CHAR_MAX 0xFF +#define CHAR_MIN 0 +#define UCHAR_MAX 0xFF +#define SHRT_MAX 0x7FFF +#define SHRT_MIN (-SHRT_MAX-1) +#define USHRT_MAX 0xFFFF +#define INT_MAX 0x7FFF +#define INT_MIN (-INT_MAX-1) +#define UINT_MAX 0xFFFF +#define LONG_MAX 0x7FFFFFFF +#define LONG_MIN (-LONG_MAX-1) +#define ULONG_MAX 0xFFFFFFFF +#define LLONG_MAX 0x7FFFFFFFFFFFFFFF +#define LLONG_MIN (-LLONG_MAX-1) +#define ULLONG_MAX 0xFFFFFFFFFFFFFFFF diff --git a/include/bits/z80/arch/stddef.h b/include/bits/z80/arch/stddef.h @@ -0,0 +1,14 @@ +#ifndef _SIZET +typedef unsigned size_t; +#define _SIZET +#endif + +#ifndef _WCHAR_T +typedef short wchar_t; +#define _WCHAR_T +#endif + +#ifndef _PTRDIFF_T +typedef short ptrdiff_t; +#define _PTRDIFF_T +#endif diff --git a/include/bits/z80/arch/stdint.h b/include/bits/z80/arch/stdint.h @@ -0,0 +1,115 @@ +#define INT8_MAX 0x7F +#define INT8_MIN (-INT8_MAX-1) +#define UINT8_MAX 0xFF + +#define INT16_MAX 0x7FFF +#define INT16_MIN (-INT16_MAX-1) +#define UINT16_MAX 0xFFFF + +#define INT32_MAX 0x7FFFFFFF +#define INT32_MIN (-INT32_MAX-1) +#define UINT32_MAX 0xFFFFFFFF + +#define INT64_MAX 0x7FFFFFFFFFFFFFFF +#define INT64_MIN (-INT64_MAX-1) +#define UINT64_MAX 0xFFFFFFFFFFFFFFFF + +#define INT_LEAST8_MIN INT8_MIN +#define INT_LEAST8_MAX INT8_MAX +#define UINT_LEAST8_MAX UINT8_MAX + +#define INT_LEAST16_MIN INT16_MIN +#define INT_LEAST16_MAX INT16_MAX +#define UINT_LEAST16_MAX UINT16_MAX + +#define INT_LEAST32_MIN INT32_MIN +#define INT_LEAST32_MAX INT32_MAX +#define UINT_LEAST32_MAX UINT32_MAX + +#define INT_LEAST64_MIN INT64_MIN +#define INT_LEAST64_MAX INT64_MAX +#define UINT_LEAST64_MAX UINT64_MAX + +#define INT_FAST8_MIN INT16_MIN +#define INT_FAST8_MAX INT16_MAX +#define UINT_FAST8_MAX UINT16_MAX + +#define INT_FAST16_MIN INT16_MIN +#define INT_FAST16_MAX INT16_MAX +#define UINT_FAST16_MAX UINT16_MAX + +#define INT_FAST32_MIN INT32_MIN +#define INT_FAST32_MAX INT32_MAX +#define UINT_FAST32_MAX UINT32_MAX + +#define INT_FAST64_MIN INT64_MIN +#define INT_FAST64_MAX INT64_MAX +#define UINT_FAST64_MAX UINT64_MAX + +#define INTPTR_MIN INT16_MIN +#define INTPTR_MAX INT16_MAX +#define UINTPTR_MAX UINT16_MAX + +#define INTMAX_MIN INT64_MIN +#define INTMAX_MAX INT64_MAX +#define UINTMAX_MAX UINT64_MAX + +#define PTRDIFF_MIN INT16_MIN +#define PTRDIFF_MAX INT16_MAX + +#define SIG_ATOMIC_MIN INT16_MIN +#define SIG_ATOMIC_MAX INT16_MAX + +#define SIZE_MAX UINT64_MAX + +#define WCHAR_MIN INT16_MIN +#define WCHAR_MAX INT16_MAX + +#define INT8_C(x) x +#define INT16_C(x) x +#define INT32_C(x) x ## L +#define INT64_C(x) x ## LL + +#define UINT8_C(x) x +#define UINT16_C(x) x ## U +#define UINT32_C(x) x ## UL +#define UINT64_C(x) x ## ULL + +#define INTMAX_C(x) x ## LL +#define UINTMAX_C(x) x ## ULL + +typedef signed char int8_t; +typedef int int16_t; +typedef long int32_t; +typedef long long int64_t; + +typedef unsigned char uint8_t; +typedef unsigned uint16_t; +typedef unsigned long uint32_t; +typedef unsigned long long uint64_t; + +typedef signed char int8_least_t; +typedef int int16_least_t; +typedef long int32_least_t; +typedef long long int64_least_t; + +typedef unsigned char uint8_least_t; +typedef unsigned uint16_least_t; +typedef unsigned long uint32_least_t; +typedef unsigned long long uint64_least_t; + +typedef signed char int8_fast_t; +typedef int int16_fast_t; +typedef long int32_fast_t; +typedef long long int64_fast_t; + +typedef unsigned char uint8_fast_t; +typedef unsigned uint16_fast_t; +typedef unsigned long uint32_fast_t; +typedef unsigned long long uint64_fast_t; + +typedef int intptr_t; +typedef unsigned uintptr_t; + +typedef long long intmax_t; +typedef unsigned long long uintmax_t; diff --git a/include/bits/z80/arch/stdio.h b/include/bits/z80/arch/stdio.h @@ -0,0 +1,15 @@ +#ifndef _SIZET +typedef unsigned size_t; +#define _SIZET +#endif + +#define BUFSIZ 512 +#define FILENAME_MAX 256 +#define FOPEN_MAX 16 + +#define TMP_MAX 25 +#define L_tmpnam 256 + +#define _TMPNAME "TMP.000" + +typedef long fpos_t; diff --git a/include/bits/z80/arch/stdlib.h b/include/bits/z80/arch/stdlib.h @@ -0,0 +1,14 @@ +#ifndef _SIZET +typedef unsigned size_t; +#define _SIZET +#endif + +#define EXIT_FAILURE 1 +#define EXIT_SUCCESS 0 + +#ifndef _WCHAR_T +typedef short wchar_t; +#define _WCHAR_T +#endif + +#define _ALIGNTYPE int diff --git a/include/bits/z80/arch/string.h b/include/bits/z80/arch/string.h @@ -0,0 +1,5 @@ +#ifndef _SIZET +typedef unsigned size_t; +#endif + +#define __NUMCHARS 128 diff --git a/include/bits/z80/arch/time.h b/include/bits/z80/arch/time.h @@ -0,0 +1,8 @@ +#ifndef _SIZET +typedef unsigned size_t; +#define _SIZET +#endif + +#define _MAXYEAR 2037 + +typedef long time_t; diff --git a/include/limits.h b/include/limits.h @@ -3,7 +3,6 @@ #include <arch/limits.h> -#define CHAR_BIT 8 #define MB_LEN_MAX 1 #endif diff --git a/include/math.h b/include/math.h @@ -0,0 +1,4 @@ +#ifndef _MATH_H +#define _MATH_H +#error math.h is not supported yet +#endif diff --git a/include/stdlib.h b/include/stdlib.h @@ -60,5 +60,10 @@ extern long long int llabs(long long int j); extern div_t div(int numer, int denom); extern ldiv_t ldiv(long int numer, long int denom); extern lldiv_t lldiv(long long int numer, long long int denom); +extern int mblen(const char *s, size_t n); +extern int mbtowc(wchar_t * restrict pwc, const char * restrict s, size_t n); +extern int wctomb(char *s, wchar_t wchar); +extern size_t mbstowcs(wchar_t * restrict pwcs, const char * restrict s, size_t n); +extern size_t wcstombs(char * restrict s, const wchar_t * restrict pwcs, size_t n); #endif diff --git a/include/wchar.h b/include/wchar.h @@ -0,0 +1,92 @@ +#ifndef _WCHAR_H +#define _WCHAR_H + +/* TODO: This is only a placeholder */ +typedef long wchar_t; +/* typedef long size_t; */ +typedef long mbstate_t; +typedef long wint_t; +struct tm; + +/* #define WCHAR_MAX 1 */ +/* #define WCHAR_MIN 1 */ +/* #define WEOF -1 */ +/* #define NULL 0 */ + +#ifdef _STDARG_H +extern int vswscanf(const wchar_t * restrict s, const wchar_t * restrict format, va_list arg); +extern int vwprintf(const wchar_t * restrict format, va_list arg); +extern int vwscanf(const wchar_t * restrict format, va_list arg); +#endif + +#ifdef _STDIO_H +extern int fwprintf(FILE * restrict stream, const wchar_t * restrict format, ...); +extern int fwscanf(FILE * restrict stream, const wchar_t * restrict format, ...); + +#ifdef _STDARG_H +extern int vfwprintf(FILE * restrict stream, const wchar_t * restrict format, va_list arg); +extern int vfwscanf(FILE * restrict stream, const wchar_t * restrict format, va_list arg); +extern int vswprintf(wchar_t * restrict s, size_t n, const wchar_t * restrict format, va_list arg); +#endif + +extern wint_t fgetwc(FILE *stream); +extern wint_t fputwc(wchar_t c, FILE *stream); +extern wint_t getwc(FILE *stream); +extern wint_t putwc(wchar_t c, FILE *stream); +extern int fwide(FILE *stream, int mode); +extern wint_t ungetwc(wint_t c, FILE *stream); +extern wchar_t *fgetws(wchar_t * restrict s, int n, FILE * restrict stream); +extern int fputws(const wchar_t * restrict s, FILE * restrict stream); +#endif + +extern int swprintf(wchar_t * restrict s, size_t n, const wchar_t * restrict format, ...); +extern int swscanf(const wchar_t * restrict s, const wchar_t * restrict format, ...); +extern int wprintf(const wchar_t * restrict format, ...); +extern int wscanf(const wchar_t * restrict format, ...); + +extern wint_t getwchar(void); +extern wint_t putwchar(wchar_t c); + +extern double wcstod(const wchar_t * restrict nptr, wchar_t ** restrict endptr); +extern float wcstof(const wchar_t * restrict nptr, wchar_t ** restrict endptr); +extern long double wcstold(const wchar_t * restrict nptr, wchar_t ** restrict endptr); + +extern long int wcstol(const wchar_t * restrict nptr, wchar_t ** restrict endptr, int base); +extern long long int wcstoll(const wchar_t * restrict nptr, wchar_t ** restrict endptr, int base); +extern unsigned long int wcstoul(const wchar_t * restrict nptr, wchar_t ** restrict endptr, int base); +extern unsigned long long int wcstoull(const wchar_t * restrict nptr, wchar_t ** restrict endptr, int base); + +extern wchar_t *wcscpy(wchar_t * restrict s1, const wchar_t * restrict s2); +extern wchar_t *wcsncpy(wchar_t * restrict s1, const wchar_t * restrict s2, size_t n); + +extern wchar_t *wmemcpy(wchar_t * restrict s1, const wchar_t * restrict s2, size_t n); +extern wchar_t *wmemmove(wchar_t *s1, const wchar_t *s2, size_t n); +extern wchar_t *wcscat(wchar_t * restrict s1, const wchar_t * restrict s2); +extern wchar_t *wcsncat(wchar_t * restrict s1, const wchar_t * restrict s2, size_t n); +extern int wcscmp(const wchar_t *s1, const wchar_t *s2); +extern int wcscoll(const wchar_t *s1, const wchar_t *s2); +extern int wcsncmp(const wchar_t *s1, const wchar_t *s2, size_t n); +extern size_t wcsxfrm(wchar_t * restrict s1, const wchar_t * restrict s2, size_t n); +extern int wmemcmp(const wchar_t *s1, const wchar_t *s2, size_t n); +extern wchar_t *wcschr(const wchar_t *s, wchar_t c); +extern size_t wcscspn(const wchar_t *s1, const wchar_t *s2); +extern wchar_t *wcspbrk(const wchar_t *s1, const wchar_t *s2); +extern wchar_t *wcsrchr(const wchar_t *s, wchar_t c); +extern size_t wcsspn(const wchar_t *s1, const wchar_t *s2); +extern wchar_t *wcsstr(const wchar_t *s1, const wchar_t *s2); +extern wchar_t *wcstok(wchar_t * restrict s1, const wchar_t * restrict s2, wchar_t ** restrict ptr); +extern wchar_t *wmemchr(const wchar_t *s, wchar_t c, size_t n); +extern size_t wcslen(const wchar_t *s); +extern wchar_t *wmemset(wchar_t *s, wchar_t c, size_t n); +extern size_t wcsftime(wchar_t * restrict s, size_t maxsize, const wchar_t * restrict format, const struct tm * restrict timeptr); +extern wint_t btowc(int c); +extern int wctob(wint_t c); +extern int mbsinit(const mbstate_t *ps); +extern size_t mbrlen(const char * restrict s, size_t n, mbstate_t * restrict ps); +extern size_t mbrtowc(wchar_t * restrict pwc, const char * restrict s, size_t n, mbstate_t * restrict ps); +extern size_t wcrtomb(char * restrict s, wchar_t wc, mbstate_t * restrict ps); +extern size_t mbsrtowcs(wchar_t * restrict dst, const char ** restrict src, size_t len, mbstate_t * restrict ps); +extern size_t wcsrtombs(char * restrict dst, const wchar_t ** restrict src, size_t len, mbstate_t * restrict ps); + + +#endif diff --git a/include/wctype.h b/include/wctype.h @@ -0,0 +1,30 @@ +#ifndef _WCTYPE_H +#define _WCTYPE_H + +/* TODO: This is only a placeholder */ +typedef int wint_t; +typedef int wctrans_t; +typedef int wctype_t; + +#define WEOF -1 + +extern int iswalnum(wint_t wc); +extern int iswalpha(wint_t wc); +extern int iswblank(wint_t wc); +extern int iswcntrl(wint_t wc); +extern int iswdigit(wint_t wc); +extern int iswgraph(wint_t wc); +extern int iswlower(wint_t wc); +extern int iswprint(wint_t wc); +extern int iswpunct(wint_t wc); +extern int iswspace(wint_t wc); +extern int iswupper(wint_t wc); +extern int iswxdigit(wint_t wc); +extern int iswctype(wint_t wc, wctype_t desc); +extern wctype_t wctype(const char *property); +extern wint_t towlower(wint_t wc); +extern wint_t towupper(wint_t wc); +extern wint_t towctrans(wint_t wc, wctrans_t desc); +extern wctrans_t wctrans(const char *property); + +#endif diff --git a/src/libc/stdio/vfprintf.c b/src/libc/stdio/vfprintf.c @@ -4,6 +4,7 @@ #include <stdint.h> #include <stdio.h> #include <string.h> +#include <wchar.h> #undef vfprintf enum { @@ -114,6 +115,37 @@ savecnt(va_list *va, int flags, int cnt) } static size_t +wstrout(wchar_t *ws, size_t len, int width, int fill, FILE * restrict fp) +{ + int left = 0, adjust; + size_t cnt = 0; + wchar_t wc; +#if 0 + + if (width < 0) { + left = 1; + width = -width; + } + + len *= sizeof(wchar_t); + adjust = (len < width) ? width - len : 0; + cnt = adjust + len; + if (left) + adjust = -adjust; + + for ( ; adjust > 0; adjust++) + putc(fill, fp); + + while (wc = *ws++) + putwc(wc, fp); + + for ( ; adjust < 0; adjust--) + putc(' ', fp); +#endif + return cnt; +} + +static size_t strout(char *s, size_t len, int width, int fill, FILE * restrict fp) { int left = 0, adjust, ch, prefix; @@ -160,8 +192,10 @@ vfprintf(FILE * restrict fp, const char *fmt, va_list va) int ch, n, flags, width, left, fill, cnt = 0; size_t inc, len; char *s; + wchar_t *ws; struct conv conv; char buf[MAXPREC+1]; + wchar_t wbuf[2]; va_list va2; va_copy(va2, va); @@ -239,6 +273,13 @@ flags: ch = '%'; goto cout; case 'c': + if (flags & LONG) { + wbuf[0] = va_arg(va2, wint_t); + wbuf[1] = L'\0'; + ws = wbuf; + len = 1; + goto wstrout; + } ch = va_arg(va2, int); cout: buf[0] = ch; @@ -293,8 +334,18 @@ flags: case 'G': /* TODO */ case 's': - s = va_arg(va2, char *); - len = strnlen(s, conv.prec); + if (flags & LONG) { + ws = va_arg(va2, wchar_t *); + /* len = wcsnlen(ws, conv.prec); */ + goto wstrout; + } else { + s = va_arg(va2, char *); + len = strnlen(s, conv.prec); + goto strout; + } + wstrout: + inc = wstrout(ws, len, width, fill, fp); + break; strout: inc = strout(s, len, width, fill, fp); break; diff --git a/src/libc/string/strcspn.c b/src/libc/string/strcspn.c @@ -8,7 +8,7 @@ strcspn(const char *s1, const char *s2) const unsigned char *accept = s2; unsigned ch; size_t n; - char buf[256]; + char buf[__NUMCHARS]; memset(buf, 0, sizeof(buf)); while (ch = *accept++) diff --git a/src/libc/string/strpbrk.c b/src/libc/string/strpbrk.c @@ -7,7 +7,7 @@ strpbrk(const char *s1, const char *s2) const unsigned char *s = s1; const unsigned char *accept = s2; unsigned ch; - char buf[256]; + char buf[__NUMCHARS]; memset(buf, 0, sizeof(buf)); while (ch = *accept++) diff --git a/src/libc/string/strspn.c b/src/libc/string/strspn.c @@ -8,7 +8,7 @@ strspn(const char *s1, const char *s2) const unsigned char *accept = s2; unsigned ch; size_t n; - char buf[256]; + char buf[__NUMCHARS]; memset(buf, 0, sizeof(buf)); while (ch = *accept++)