brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.0 KiB · 9b6773b Raw
29 lines · cpp
1//===-- Implementation of wctob -------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9#include "src/wchar/wctob.h"10#include "src/__support/common.h"11#include "src/__support/macros/config.h"12 13#include "hdr/stdio_macros.h" // for EOF.14#include "hdr/types/wint_t.h"15 16namespace LIBC_NAMESPACE_DECL {17 18LLVM_LIBC_FUNCTION(int, wctob, (wint_t c)) {19  // The standard states that wint_t may either be an alias of wchar_t or20  // an alias of an integer type, different platforms define this type with21  // different signedness. This is equivalent to `(c > 127) || (c < 0)` but also22  // works without -Wtype-limits warnings when `wint_t` is unsigned.23  if ((c & ~127) != 0)24    return EOF;25  return static_cast<int>(c);26}27 28} // namespace LIBC_NAMESPACE_DECL29