summaryrefslogtreecommitdiffstats
path: root/gl/btowc.c
diff options
context:
space:
mode:
Diffstat (limited to 'gl/btowc.c')
-rw-r--r--gl/btowc.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/gl/btowc.c b/gl/btowc.c
index caadbd7..8bf21aa 100644
--- a/gl/btowc.c
+++ b/gl/btowc.c
@@ -1,5 +1,5 @@
1/* Convert unibyte character to wide character. 1/* Convert unibyte character to wide character.
2 Copyright (C) 2008, 2010-2023 Free Software Foundation, Inc. 2 Copyright (C) 2008, 2010-2024 Free Software Foundation, Inc.
3 Written by Bruno Haible <bruno@clisp.org>, 2008. 3 Written by Bruno Haible <bruno@clisp.org>, 2008.
4 4
5 This file is free software: you can redistribute it and/or modify 5 This file is free software: you can redistribute it and/or modify
@@ -22,6 +22,7 @@
22 22
23#include <stdio.h> 23#include <stdio.h>
24#include <stdlib.h> 24#include <stdlib.h>
25#include <string.h>
25 26
26wint_t 27wint_t
27btowc (int c) 28btowc (int c)
@@ -32,7 +33,14 @@ btowc (int c)
32 wchar_t wc; 33 wchar_t wc;
33 34
34 buf[0] = c; 35 buf[0] = c;
36#if HAVE_MBRTOWC
37 mbstate_t state;
38 mbszero (&state);
39 size_t ret = mbrtowc (&wc, buf, 1, &state);
40 if (!(ret == (size_t)(-1) || ret == (size_t)(-2)))
41#else
35 if (mbtowc (&wc, buf, 1) >= 0) 42 if (mbtowc (&wc, buf, 1) >= 0)
43#endif
36 return wc; 44 return wc;
37 } 45 }
38 return WEOF; 46 return WEOF;