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-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #include "libc_errno.h" 10 11 #ifdef LIBC_TARGET_ARCH_IS_GPU 12 // LIBC_THREAD_LOCAL on GPU currently does nothing. So essentially this is just 13 // a global errno for gpu to use for now. 14 extern "C" { 15 LIBC_THREAD_LOCAL int __llvmlibc_gpu_errno; 16 } 17 operator =(int a)18void LIBC_NAMESPACE::Errno::operator=(int a) { __llvmlibc_gpu_errno = a; } operator int()19LIBC_NAMESPACE::Errno::operator int() { return __llvmlibc_gpu_errno; } 20 21 #elif !defined(LIBC_COPT_PUBLIC_PACKAGING) 22 // This mode is for unit testing. We just use our internal errno. 23 LIBC_THREAD_LOCAL int __llvmlibc_internal_errno; 24 operator =(int a)25void LIBC_NAMESPACE::Errno::operator=(int a) { __llvmlibc_internal_errno = a; } operator int()26LIBC_NAMESPACE::Errno::operator int() { return __llvmlibc_internal_errno; } 27 28 #elif defined(LIBC_FULL_BUILD) 29 // This mode is for public libc archive, hermetic, and integration tests. 30 // In full build mode, we provide the errno storage ourselves. 31 extern "C" { 32 LIBC_THREAD_LOCAL int __llvmlibc_errno; 33 } 34 operator =(int a)35void LIBC_NAMESPACE::Errno::operator=(int a) { __llvmlibc_errno = a; } operator int()36LIBC_NAMESPACE::Errno::operator int() { return __llvmlibc_errno; } 37 38 #else operator =(int a)39void LIBC_NAMESPACE::Errno::operator=(int a) { errno = a; } operator int()40LIBC_NAMESPACE::Errno::operator int() { return errno; } 41 42 #endif // LIBC_FULL_BUILD 43 44 namespace LIBC_NAMESPACE { 45 // Define the global `libc_errno` instance. 46 Errno libc_errno; 47 } // namespace LIBC_NAMESPACE 48