brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.5 KiB · e8960fc Raw
57 lines · cpp
1//===-- Implementation of libc_errno --------------------------------------===//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/__support/libc_errno.h"10#include "src/__support/macros/attributes.h"11#include "src/__support/macros/config.h"12 13namespace LIBC_NAMESPACE_DECL {14 15#if LIBC_ERRNO_MODE != LIBC_ERRNO_MODE_SYSTEM_INLINE16 17#if LIBC_ERRNO_MODE == LIBC_ERRNO_MODE_UNDEFINED18 19void Errno::operator=(int) {}20Errno::operator int() { return 0; }21 22#elif LIBC_ERRNO_MODE == LIBC_ERRNO_MODE_THREAD_LOCAL23 24namespace {25LIBC_THREAD_LOCAL int thread_errno;26}27 28extern "C" int *__llvm_libc_errno() noexcept { return &thread_errno; }29 30void Errno::operator=(int a) { thread_errno = a; }31Errno::operator int() { return thread_errno; }32 33#elif LIBC_ERRNO_MODE == LIBC_ERRNO_MODE_SHARED34 35namespace {36int shared_errno;37}38 39extern "C" int *__llvm_libc_errno() noexcept { return &shared_errno; }40 41void Errno::operator=(int a) { shared_errno = a; }42Errno::operator int() { return shared_errno; }43 44#elif LIBC_ERRNO_MODE == LIBC_ERRNO_MODE_EXTERNAL45 46void Errno::operator=(int a) { *__llvm_libc_errno() = a; }47Errno::operator int() { return *__llvm_libc_errno(); }48 49#endif50 51// Define the global `libc_errno` instance.52Errno libc_errno;53 54#endif // LIBC_ERRNO_MODE != LIBC_ERRNO_MODE_SYSTEM_INLINE55 56} // namespace LIBC_NAMESPACE_DECL57