xref: /freebsd/contrib/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_errno.h (revision 02e9120893770924227138ba49df1edb3896112a)
1 //===-- sanitizer_errno.h ---------------------------------------*- C++ -*-===//
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 // This file is shared between sanitizers run-time libraries.
10 //
11 // Defines errno to avoid including errno.h and its dependencies into sensitive
12 // files (e.g. interceptors are not supposed to include any system headers).
13 // It's ok to use errno.h directly when your file already depend on other system
14 // includes though.
15 //
16 //===----------------------------------------------------------------------===//
17 
18 #ifndef SANITIZER_ERRNO_H
19 #define SANITIZER_ERRNO_H
20 
21 #include "sanitizer_errno_codes.h"
22 #include "sanitizer_platform.h"
23 
24 #if SANITIZER_FREEBSD || SANITIZER_APPLE
25 #  define __errno_location __error
26 #elif SANITIZER_ANDROID || SANITIZER_NETBSD
27 #  define __errno_location __errno
28 #elif SANITIZER_SOLARIS
29 #  define __errno_location ___errno
30 #elif SANITIZER_WINDOWS
31 #  define __errno_location _errno
32 #endif
33 
34 extern "C" int *__errno_location();
35 
36 #define errno (*__errno_location())
37 
38 #endif  // SANITIZER_ERRNO_H
39