blob: 4f3be8a8d100a3a0cca562cdf17a699790e4e29f [file] [log] [blame] [raw]
/* A part of the Native C Library for Windows NT
Copyright 2007-2015 PC GO Ld.
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*/
#include <wchar.h>
#include <windows.h>
#include <nt.h>
#include <errno.h>
#include <limits.h>
static mbstate_t state_private = 0;
size_t mbrtowc(wchar_t *pwc, const char *s, size_t n, mbstate_t *ps) {
wchar_t buffer;
unsigned long int rsize;
if(!ps) ps = &state_private;
if(!s) {
*ps = 0;
return 0;
}
long int status = RtlMultiByteToUnicodeN(&buffer, sizeof buffer, &rsize, s + *ps, n);
//printf("nativelibc debug: mbrtowc: status = 0x%lx\n", status);
if(status < 0) {
errno = EILSEQ;
return (size_t)-1;
}
if(pwc) *pwc = buffer;
if(!buffer) {
*ps = 0;
return 0;
}
*ps += rsize;
return n;
}