diff options
Diffstat (limited to 'lib/btowc.c')
-rw-r--r-- | lib/btowc.c | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/lib/btowc.c b/lib/btowc.c index b8239af..4defbdd 100644 --- a/lib/btowc.c +++ b/lib/btowc.c @@ -1,5 +1,5 @@ /* Convert unibyte character to wide character. - Copyright (C) 2008, 2010-2021 Free Software Foundation, Inc. + Copyright (C) 2008, 2010-2023 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2008. This file is free software: you can redistribute it and/or modify @@ -22,6 +22,7 @@ #include <stdio.h> #include <stdlib.h> +#include <string.h> wint_t btowc (int c) @@ -32,7 +33,14 @@ btowc (int c) wchar_t wc; buf[0] = c; +#if HAVE_MBRTOWC + mbstate_t state; + memset (&state, 0, sizeof (mbstate_t)); + size_t ret = mbrtowc (&wc, buf, 1, &state); + if (!(ret == (size_t)(-1) || ret == (size_t)(-2))) +#else if (mbtowc (&wc, buf, 1) >= 0) +#endif return wc; } return WEOF; |