xref: /freebsd/contrib/llvm-project/libcxx/include/__mbstate_t.h (revision 1db9f3b21e39176dd5b67cf8ac378633b172463e)
1 // -*- C++ -*-
2 //===----------------------------------------------------------------------===//
3 //
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #ifndef _LIBCPP___MBSTATE_T_H
11 #define _LIBCPP___MBSTATE_T_H
12 
13 #include <__config>
14 
15 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16 #  pragma GCC system_header
17 #endif
18 
19 // The goal of this header is to provide mbstate_t without requiring all of
20 // <uchar.h> or <wchar.h>. It's also used by the libc++ versions of <uchar.h>
21 // and <wchar.h> to get mbstate_t when the C library doesn't provide <uchar.h>
22 // or <wchar.h>, hence the #include_next of those headers instead of #include.
23 // (e.g. if <wchar.h> isn't present in the C library, the libc++ <wchar.h>
24 // will include this header. This header needs to not turn around and cyclically
25 // include <wchar.h>, but fall through to <uchar.h>.)
26 //
27 // This does not define std::mbstate_t -- this only brings in the declaration
28 // in the global namespace.
29 
30 // We define this here to support older versions of glibc <wchar.h> that do
31 // not define this for clang. This is also set in libc++'s <wchar.h> header,
32 // and we need to do so here too to avoid a different function signature given
33 // a different include order.
34 #ifdef __cplusplus
35 #  define __CORRECT_ISO_CPP_WCHAR_H_PROTO
36 #endif
37 
38 #if defined(_LIBCPP_HAS_MUSL_LIBC)
39 #  define __NEED_mbstate_t
40 #  include <bits/alltypes.h>
41 #  undef __NEED_mbstate_t
42 #elif __has_include(<bits/types/mbstate_t.h>)
43 #  include <bits/types/mbstate_t.h> // works on most Unixes
44 #elif __has_include(<sys/_types/_mbstate_t.h>)
45 #  include <sys/_types/_mbstate_t.h> // works on Darwin
46 #elif !defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS) && __has_include_next(<wchar.h>)
47 #  include_next <wchar.h> // fall back to the C standard provider of mbstate_t
48 #elif __has_include_next(<uchar.h>)
49 #  include_next <uchar.h> // <uchar.h> is also required to make mbstate_t visible
50 #else
51 #  error "We don't know how to get the definition of mbstate_t without <wchar.h> on your platform."
52 #endif
53 
54 #endif // _LIBCPP___MBSTATE_T_H
55