/**
 * This file has no copyright assigned and is placed in the Public Domain.
 * This file is part of the mingw-w64 runtime package.
 * No warranty is given; refer to the file DISCLAIMER.PD within this package.
 */

#define __LARGE_MBSTATE_T

#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#include <locale.h>
#include <limits.h>
#include <wchar.h>
#include <stdio.h>
#include <windows.h>

wint_t btowc (int c)
{
  if (c == EOF)
    return (WEOF);

  /* Use dummy string so that mbrtowc will never return (size_t)-2 */
  char str[MB_LEN_MAX] = {(unsigned char) c, 0, 0, 0, 0};

  wint_t    wc = WEOF;
  mbstate_t state = {0};

  if (mbrtowc (&wc, (char *) str, MB_CUR_MAX, &state) == (size_t) -1) {
    return WEOF;
  }

  return wc;
}

wint_t (__cdecl *__MINGW_IMP_SYMBOL (btowc)) (int) = btowc;
