xref: /llvm-project/libc/src/wchar/btowc.cpp (revision 1ae0dae368e4bbf2177603d5c310e794c4fd0bd8)
146b50872SMichael Jones //===-- Implementation of btowc -------------------------------------------===//
246b50872SMichael Jones //
346b50872SMichael Jones // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
446b50872SMichael Jones // See https://llvm.org/LICENSE.txt for license information.
546b50872SMichael Jones // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
646b50872SMichael Jones //
746b50872SMichael Jones //===----------------------------------------------------------------------===//
846b50872SMichael Jones 
946b50872SMichael Jones #include "src/wchar/btowc.h"
1046b50872SMichael Jones #include "src/__support/common.h"
115ff3ff33SPetr Hosek #include "src/__support/macros/config.h"
1246b50872SMichael Jones #include "src/__support/wctype_utils.h"
1346b50872SMichael Jones 
1495d4c97aSlntue #include "hdr/types/wint_t.h"
15*1ae0dae3SMichael Jones #include "hdr/wchar_macros.h" // for WEOF.
1646b50872SMichael Jones 
175ff3ff33SPetr Hosek namespace LIBC_NAMESPACE_DECL {
1846b50872SMichael Jones 
19*1ae0dae3SMichael Jones LLVM_LIBC_FUNCTION(wint_t, btowc, (int c)) {
2046b50872SMichael Jones   auto result = internal::btowc(c);
2146b50872SMichael Jones   if (result.has_value()) {
2246b50872SMichael Jones     return result.value();
2346b50872SMichael Jones   } else {
2446b50872SMichael Jones     return WEOF;
2546b50872SMichael Jones   }
2646b50872SMichael Jones }
2746b50872SMichael Jones 
285ff3ff33SPetr Hosek } // namespace LIBC_NAMESPACE_DECL
29