libc fixes

This commit is contained in:
K. Lange 2018-06-25 18:15:02 +09:00
parent 8080b5272f
commit 92fec3ece8
5 changed files with 33 additions and 11 deletions

View File

@ -2,6 +2,6 @@
#include <locale.h>
char * setlocale(int category, const char *locale) {
return NULL; /* Unsupported */
return "en_US";
}

View File

@ -109,6 +109,7 @@ size_t xvasprintf(char * buf, const char * fmt, va_list args) {
unsigned int arg_width = 0;
int align = 1; /* right */
int fill_zero = 0;
int big = 0;
if (*f == '-') {
align = 0;
++f;
@ -126,19 +127,36 @@ size_t xvasprintf(char * buf, const char * fmt, va_list args) {
arg_width += *f - '0';
++f;
}
if (*f == 'l') {
big = 1;
++f;
}
/* fmt[i] == '%' */
switch (*f) {
case 's': /* String pointer -> String */
{
s = (char *)va_arg(args, char *);
if (s == NULL) {
s = "(null)";
}
size_t count = 0;
while (*s) {
*b++ = *s++;
count++;
if (arg_width && count == arg_width) break;
if (big) {
wchar_t * ws = (wchar_t *)va_arg(args, wchar_t *);
if (ws == NULL) {
ws = L"(null)";
}
size_t count = 0;
while (*ws) {
*b++ = *ws++;
count++;
if (arg_width && count == arg_width) break;
}
} else {
s = (char *)va_arg(args, char *);
if (s == NULL) {
s = "(null)";
}
while (*s) {
*b++ = *s++;
count++;
if (arg_width && count == arg_width) break;
}
}
while (count < arg_width) {
*b++ = ' ';

View File

@ -6,6 +6,8 @@ size_t wcstombs(char * dest, const wchar_t *src, size_t n) {
while (c < n && *src) {
*dest = *src;
c++;
src++;
dest++;
}
return c;
}
@ -16,6 +18,8 @@ size_t mbstowcs(wchar_t * dest, const char *src, size_t n) {
while (c < n && *src) {
*dest = *src;
c++;
src++;
dest++;
}
return c;
}

View File

@ -3,8 +3,8 @@
wchar_t * wcsncpy(wchar_t * dest, const wchar_t * src, size_t n) {
wchar_t * out = dest;
while (n > 0) {
if (!*src) break;
*dest = *src;
if (!*src) break;
dest++;
src++;
n--;

View File

@ -32,7 +32,7 @@ wchar_t *wcspbrk(const wchar_t *wcs, const wchar_t *accept) {
}
wchar_t * wcschr(const wchar_t *wcs, wchar_t wc) {
while (*wcs != wc && *wcs != L'0') {
while (*wcs != wc && *wcs != 0) {
wcs++;
}
if (!*wcs) return NULL;