1 /*
2  * Copyright (C) 2016 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef _LIBLOG_PORTABILITY_H__
18 #define _LIBLOG_PORTABILITY_H__
19 
20 #include <sys/cdefs.h>
21 #include <unistd.h>
22 
23 /* Helpful private sys/cdefs.h like definitions */
24 
25 /* Declare this library function hidden and internal */
26 #if defined(_WIN32)
27 #define LIBLOG_HIDDEN
28 #else
29 #define LIBLOG_HIDDEN __attribute__((visibility("hidden")))
30 #endif
31 
32 /* Declare this library function visible and external */
33 #if defined(_WIN32)
34 #define LIBLOG_ABI_PUBLIC
35 #else
36 #define LIBLOG_ABI_PUBLIC __attribute__((visibility("default")))
37 #endif
38 
39 /* Declare this library function visible but private */
40 #define LIBLOG_ABI_PRIVATE LIBLOG_ABI_PUBLIC
41 
42 /*
43  * Declare this library function as reimplementation.
44  * Prevent circular dependencies, but allow _real_ library to hijack
45  */
46 #if defined(_WIN32)
47 #define LIBLOG_WEAK static /* Accept that it is totally private */
48 #else
49 #define LIBLOG_WEAK __attribute__((weak,visibility("default")))
50 #endif
51 
52 /* possible missing definitions in sys/cdefs.h */
53 
54 /* DECLS */
55 #ifndef __BEGIN_DECLS
56 #if defined(__cplusplus)
57 #define __BEGIN_DECLS           extern "C" {
58 #define __END_DECLS             }
59 #else
60 #define __BEGIN_DECLS
61 #define __END_DECLS
62 #endif
63 #endif
64 
65 /* Unused argument. For C code only, remove symbol name for C++ */
66 #ifndef __unused
67 #define __unused        __attribute__((__unused__))
68 #endif
69 
70 /* possible missing definitions in unistd.h */
71 
72 #ifndef TEMP_FAILURE_RETRY
73 /* Used to retry syscalls that can return EINTR. */
74 #define TEMP_FAILURE_RETRY(exp) ({         \
75     __typeof__(exp) _rc;                   \
76     do {                                   \
77         _rc = (exp);                       \
78     } while (_rc == -1 && errno == EINTR); \
79     _rc; })
80 #endif
81 
82 #endif /* _LIBLOG_PORTABILITY_H__ */
83