xref: /freebsd/contrib/llvm-project/libcxx/include/__mbstate_t.h (revision cb14a3fe5122c879eae1fb480ed7ce82a699ddb6)
1349cc55cSDimitry Andric // -*- C++ -*-
2349cc55cSDimitry Andric //===----------------------------------------------------------------------===//
3349cc55cSDimitry Andric //
4349cc55cSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5349cc55cSDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
6349cc55cSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7349cc55cSDimitry Andric //
8349cc55cSDimitry Andric //===----------------------------------------------------------------------===//
9349cc55cSDimitry Andric 
10349cc55cSDimitry Andric #ifndef _LIBCPP___MBSTATE_T_H
11349cc55cSDimitry Andric #define _LIBCPP___MBSTATE_T_H
12349cc55cSDimitry Andric 
13349cc55cSDimitry Andric #include <__config>
14349cc55cSDimitry Andric 
15349cc55cSDimitry Andric #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16349cc55cSDimitry Andric #  pragma GCC system_header
17349cc55cSDimitry Andric #endif
18349cc55cSDimitry Andric 
19*06c3fb27SDimitry Andric // The goal of this header is to provide mbstate_t without requiring all of
20*06c3fb27SDimitry Andric // <uchar.h> or <wchar.h>. It's also used by the libc++ versions of <uchar.h>
21*06c3fb27SDimitry Andric // and <wchar.h> to get mbstate_t when the C library doesn't provide <uchar.h>
22*06c3fb27SDimitry Andric // or <wchar.h>, hence the #include_next of those headers instead of #include.
23*06c3fb27SDimitry Andric // (e.g. if <wchar.h> isn't present in the C library, the libc++ <wchar.h>
24*06c3fb27SDimitry Andric // will include this header. This header needs to not turn around and cyclically
25*06c3fb27SDimitry Andric // include <wchar.h>, but fall through to <uchar.h>.)
26349cc55cSDimitry Andric //
27*06c3fb27SDimitry Andric // This does not define std::mbstate_t -- this only brings in the declaration
28*06c3fb27SDimitry Andric // in the global namespace.
29349cc55cSDimitry Andric 
30*06c3fb27SDimitry Andric // We define this here to support older versions of glibc <wchar.h> that do
31*06c3fb27SDimitry Andric // not define this for clang. This is also set in libc++'s <wchar.h> header,
32*06c3fb27SDimitry Andric // and we need to do so here too to avoid a different function signature given
33*06c3fb27SDimitry Andric // a different include order.
34*06c3fb27SDimitry Andric #ifdef __cplusplus
35*06c3fb27SDimitry Andric #  define __CORRECT_ISO_CPP_WCHAR_H_PROTO
36*06c3fb27SDimitry Andric #endif
37*06c3fb27SDimitry Andric 
38*06c3fb27SDimitry Andric #if defined(_LIBCPP_HAS_MUSL_LIBC)
39*06c3fb27SDimitry Andric #  define __NEED_mbstate_t
40*06c3fb27SDimitry Andric #  include <bits/alltypes.h>
41*06c3fb27SDimitry Andric #  undef __NEED_mbstate_t
42349cc55cSDimitry Andric #elif __has_include(<bits/types/mbstate_t.h>)
43349cc55cSDimitry Andric #  include <bits/types/mbstate_t.h> // works on most Unixes
44349cc55cSDimitry Andric #elif __has_include(<sys/_types/_mbstate_t.h>)
45349cc55cSDimitry Andric #  include <sys/_types/_mbstate_t.h> // works on Darwin
46*06c3fb27SDimitry Andric #elif !defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS) && __has_include_next(<wchar.h>)
47*06c3fb27SDimitry Andric #  include_next <wchar.h> // fall back to the C standard provider of mbstate_t
48*06c3fb27SDimitry Andric #elif __has_include_next(<uchar.h>)
49*06c3fb27SDimitry Andric #  include_next <uchar.h> // <uchar.h> is also required to make mbstate_t visible
50349cc55cSDimitry Andric #else
51*06c3fb27SDimitry Andric #  error "We don't know how to get the definition of mbstate_t without <wchar.h> on your platform."
52349cc55cSDimitry Andric #endif
53349cc55cSDimitry Andric 
54349cc55cSDimitry Andric #endif // _LIBCPP___MBSTATE_T_H
55