Files
semi-libc/src/stdio/vswscanf.c
T
Isaac Dunham 14f0272ea1 Add ABI compatability aliases.
GNU used several extensions that were incompatible with C99 and POSIX,
so they used alternate names for the standard functions.

The result is that we need these to run standards-conformant programs
that were linked with glibc.
2013-04-05 23:20:28 -07:00

40 lines
741 B
C

#include "stdio_impl.h"
#include "libc.h"
#include <wchar.h>
static size_t wstring_read(FILE *f, unsigned char *buf, size_t len)
{
const wchar_t *src = f->cookie;
size_t k;
if (!src) return 0;
k = wcsrtombs((void *)f->buf, &src, f->buf_size, 0);
if (k==(size_t)-1) {
f->rpos = f->rend = 0;
return 0;
}
f->rpos = f->buf;
f->rend = f->buf + k;
f->cookie = (void *)src;
if (!len || !k) return 0;
*buf = *f->rpos++;
return 1;
}
int vswscanf(const wchar_t *restrict s, const wchar_t *restrict fmt, va_list ap)
{
unsigned char buf[256];
FILE f = {
.buf = buf, .buf_size = sizeof buf,
.cookie = (void *)s,
.read = wstring_read, .lock = -1
};
return vfwscanf(&f, fmt, ap);
}
weak_alias(vswscanf,__isoc99_vswscanf);