blob: 88805c75fc17112ba4f39ea47680e674b1701d7b [file] [log] [blame]
Mark Salyzyn6d753fa2016-03-10 08:25:33 -08001/*
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
Mark Salyzynfacf94c2016-03-01 13:45:42 -080017#ifndef _LIBLOG_PORTABILITY_H__
18#define _LIBLOG_PORTABILITY_H__
Mark Salyzyn6d753fa2016-03-10 08:25:33 -080019
20#include <sys/cdefs.h>
Mark Salyzynfacf94c2016-03-01 13:45:42 -080021#include <unistd.h>
22
23/* Helpful private sys/cdefs.h like definitions */
Mark Salyzyn6d753fa2016-03-10 08:25:33 -080024
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
Mark Salyzyn2ed51d72017-03-09 08:09:43 -080049#define LIBLOG_WEAK __attribute__((weak, visibility("default")))
Mark Salyzyn6d753fa2016-03-10 08:25:33 -080050#endif
51
Mark Salyzynfacf94c2016-03-01 13:45:42 -080052/* possible missing definitions in sys/cdefs.h */
53
54/* DECLS */
55#ifndef __BEGIN_DECLS
56#if defined(__cplusplus)
Mark Salyzyn2ed51d72017-03-09 08:09:43 -080057#define __BEGIN_DECLS extern "C" {
58#define __END_DECLS }
Mark Salyzynfacf94c2016-03-01 13:45:42 -080059#else
60#define __BEGIN_DECLS
61#define __END_DECLS
62#endif
63#endif
64
Mark Salyzyn6d753fa2016-03-10 08:25:33 -080065/* Unused argument. For C code only, remove symbol name for C++ */
66#ifndef __unused
Mark Salyzyn2ed51d72017-03-09 08:09:43 -080067#define __unused __attribute__((__unused__))
Mark Salyzyn6d753fa2016-03-10 08:25:33 -080068#endif
69
Mark Salyzynfacf94c2016-03-01 13:45:42 -080070/* possible missing definitions in unistd.h */
71
72#ifndef TEMP_FAILURE_RETRY
73/* Used to retry syscalls that can return EINTR. */
Mark Salyzyn2ed51d72017-03-09 08:09:43 -080074#define TEMP_FAILURE_RETRY(exp) \
75 ({ \
Mark Salyzynfacf94c2016-03-01 13:45:42 -080076 __typeof__(exp) _rc; \
77 do { \
Mark Salyzyn2ed51d72017-03-09 08:09:43 -080078 _rc = (exp); \
Mark Salyzynfacf94c2016-03-01 13:45:42 -080079 } while (_rc == -1 && errno == EINTR); \
Mark Salyzyn2ed51d72017-03-09 08:09:43 -080080 _rc; \
81 })
Mark Salyzynfacf94c2016-03-01 13:45:42 -080082#endif
83
84#endif /* _LIBLOG_PORTABILITY_H__ */