blob: 100eab0ce08e5e74813ec11d88cd458114b65bdf [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 wcrtomb(char *s, wchar_t wc, mbstate_t *ps) {
//char buffer[MB_CUR_MAX];
char buffer[4];
unsigned long int r;
/*
if(!s) {
s = buffer;
wc = 0;
}*/
if(!ps) ps = &state_private;
long int status = RtlUnicodeToMultiByteN(buffer, sizeof buffer, &r, &wc, MB_LEN_MAX);
if(status < 0) {
errno = EILSEQ;
return (size_t)-1;
}
//return r;
if(*ps == r) return r;
s[*ps] = buffer[*ps];
return ++(*ps);
}