// Minimal wchar.h for the W65816 runtime. // // wchar_t is 16-bit (matches `int` on this target). No real // multi-byte / locale support — mbtowc/wctomb assume a one-byte = // one-wchar mapping (essentially Latin-1). The wcs* functions // mirror the str* family. #ifndef _WCHAR_H #define _WCHAR_H #ifndef _WCHAR_T_DEFINED # define _WCHAR_T_DEFINED typedef int wchar_t; // matches clang builtin signature #endif typedef unsigned long size_t; typedef long wint_t; #define WEOF ((wint_t)-1) #ifndef NULL #define NULL ((void *)0) #endif size_t wcslen (const wchar_t *s); int wcscmp (const wchar_t *a, const wchar_t *b); int wcsncmp(const wchar_t *a, const wchar_t *b, size_t n); wchar_t *wcscpy (wchar_t *dst, const wchar_t *src); wchar_t *wcsncpy(wchar_t *dst, const wchar_t *src, size_t n); wchar_t *wcscat (wchar_t *dst, const wchar_t *src); wchar_t *wcschr (const wchar_t *s, wchar_t c); wchar_t *wcsrchr(const wchar_t *s, wchar_t c); // Multi-byte conversion. Trivial 1:1 in our impl: each byte maps // to the wide char with the same numeric value (zero-extended). int mbtowc (wchar_t *pwc, const char *s, size_t n); int wctomb (char *s, wchar_t wc); size_t mbstowcs(wchar_t *pwcs, const char *s, size_t n); size_t wcstombs(char *s, const wchar_t *pwcs, size_t n); int mblen (const char *s, size_t n); // Wide-char `memXXX` family — operate on wchar_t arrays. Under our // Latin-1 model these are equivalent to the byte versions scaled by // sizeof(wchar_t) for memcpy/memmove, and explicit loops for set/cmp // /chr (since the byte versions can't compare a 16-bit wchar_t value // against an 8-bit memory cell). wchar_t *wmemcpy (wchar_t *dst, const wchar_t *src, size_t n); wchar_t *wmemmove(wchar_t *dst, const wchar_t *src, size_t n); wchar_t *wmemset (wchar_t *dst, wchar_t c, size_t n); int wmemcmp (const wchar_t *a, const wchar_t *b, size_t n); wchar_t *wmemchr (const wchar_t *s, wchar_t c, size_t n); // Wide-char string-numeric conversion. Each routine narrows the wide // source to bytes first (1:1 Latin-1), then delegates to the strXXX // equivalent. endptr is reported in wide-char position so callers can // resume scanning from where the conversion stopped. long wcstol (const wchar_t *nptr, wchar_t **endptr, int base); unsigned long wcstoul (const wchar_t *nptr, wchar_t **endptr, int base); long long wcstoll (const wchar_t *nptr, wchar_t **endptr, int base); unsigned long long wcstoull(const wchar_t *nptr, wchar_t **endptr, int base); double wcstod (const wchar_t *nptr, wchar_t **endptr); float wcstof (const wchar_t *nptr, wchar_t **endptr); // Wide-char printf-family. Narrow the format string + any %s/%c args, // route through the byte snprintf, then widen the result back into the // wchar_t buffer. Limits the format-spec set to what byte snprintf // supports (no %ls / %lc — wide args route as plain chars). #include int swprintf (wchar_t *buf, size_t n, const wchar_t *fmt, ...); int vswprintf(wchar_t *buf, size_t n, const wchar_t *fmt, va_list ap); // Wide-char calendar formatting — same surface as strftime but writes // wchar_t. Implementation defers to strftime via a byte buffer. struct tm; size_t wcsftime(wchar_t *buf, size_t n, const wchar_t *fmt, const struct tm *tm); #endif