aboutsummaryrefslogtreecommitdiffstats
path: root/pc/gawkmisc.pc
diff options
context:
space:
mode:
Diffstat (limited to 'pc/gawkmisc.pc')
-rw-r--r--pc/gawkmisc.pc22
1 files changed, 22 insertions, 0 deletions
diff --git a/pc/gawkmisc.pc b/pc/gawkmisc.pc
index 43f81ff9..64b42396 100644
--- a/pc/gawkmisc.pc
+++ b/pc/gawkmisc.pc
@@ -547,6 +547,28 @@ usleep(unsigned int usec)
return usec - msecf * 1000 < 0 ? 0 : (int)(usec - msecf * 1000);
}
+/* The implementation of wctob in the MS runtime is problematic
+ because it doesn't allow to distinguish between WEOF and 0xff, due
+ to integer sign extension. It also causes failures in dfa.c when
+ characters with the 8th bit set are involved. This replacement
+ version fixes that. */
+
+#include <wchar.h>
+
+int
+wctob (wint_t wc)
+{
+ char buf[64];
+
+ if (!(MB_CUR_MAX <= sizeof (buf)))
+ abort ();
+ /* Handle the case where WEOF is a value that does not fit in a wchar_t. */
+ if (wc == (wchar_t)wc)
+ if (wctomb (buf, (wchar_t)wc) == 1)
+ return (unsigned char) buf[0];
+ return EOF;
+}
+
#endif /* __MINGW32__ */
#ifdef __DJGPP__