xref: /freebsd/contrib/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_errno.h (revision 81ad626541db97eb356e2c1d4a20eb2a26a766ab)
10b57cec5SDimitry Andric //===-- sanitizer_errno.h ---------------------------------------*- C++ -*-===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric //
90b57cec5SDimitry Andric // This file is shared between sanitizers run-time libraries.
100b57cec5SDimitry Andric //
110b57cec5SDimitry Andric // Defines errno to avoid including errno.h and its dependencies into sensitive
120b57cec5SDimitry Andric // files (e.g. interceptors are not supposed to include any system headers).
130b57cec5SDimitry Andric // It's ok to use errno.h directly when your file already depend on other system
140b57cec5SDimitry Andric // includes though.
150b57cec5SDimitry Andric //
160b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
170b57cec5SDimitry Andric 
180b57cec5SDimitry Andric #ifndef SANITIZER_ERRNO_H
190b57cec5SDimitry Andric #define SANITIZER_ERRNO_H
200b57cec5SDimitry Andric 
210b57cec5SDimitry Andric #include "sanitizer_errno_codes.h"
220b57cec5SDimitry Andric #include "sanitizer_platform.h"
230b57cec5SDimitry Andric 
24*81ad6265SDimitry Andric #if SANITIZER_FREEBSD || SANITIZER_APPLE
250b57cec5SDimitry Andric #  define __errno_location __error
26fe6060f1SDimitry Andric #elif SANITIZER_ANDROID || SANITIZER_NETBSD
270b57cec5SDimitry Andric #  define __errno_location __errno
280b57cec5SDimitry Andric #elif SANITIZER_SOLARIS
290b57cec5SDimitry Andric #  define __errno_location ___errno
300b57cec5SDimitry Andric #elif SANITIZER_WINDOWS
310b57cec5SDimitry Andric #  define __errno_location _errno
320b57cec5SDimitry Andric #endif
330b57cec5SDimitry Andric 
340b57cec5SDimitry Andric extern "C" int *__errno_location();
350b57cec5SDimitry Andric 
360b57cec5SDimitry Andric #define errno (*__errno_location())
370b57cec5SDimitry Andric 
380b57cec5SDimitry Andric #endif  // SANITIZER_ERRNO_H
39