+// We may be able to use a special feature of glibc's <wchar.h> to
+// get a definition of mbstate_t and nothing else. If used, it exposes
+// __mbstate_t rather than mbstate_t (the latter is a typedef to the
+// former when the full header is included, so we have no linkage issues).
+// This header provides the macro _GLIBCXX_MBSTATE_T which expands to
+// mbstate_t or __mbstate_t as appropriate.
+//
+// N.B. The special feature does not work if used via <cwchar>, nor does
+// it work if we attempt to force the <wchar.h> definitions into a
+// namespace.
+
+#if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 1)
+
+ #define __need_mbstate_t
+ #include <wchar.h>
+ #define _GLIBCXX_MBSTATE_T ::__mbstate_t
+
+#else
+
+ #include <cwchar>
+ #define _GLIBCXX_MBSTATE_T mbstate_t
+
+#endif