From b8e1b705d187886decb5970f791358f928f93d75 Mon Sep 17 00:00:00 2001 From: Josh Gao Date: Wed, 13 Apr 2016 17:18:20 -0700 Subject: [PATCH] Make the legacy inline headers compile standalone. It's useful to have the legacy inlines compile by themselves, both to make header unification easier, and to ensure that the inline versions match the regular declarations. Notably, this wasn't true for sigismember, which took a const sigset_t* in the regular header, and sigset_t* in the inline version. Bug: http://b/28178111 Change-Id: Id8a3b7dcb1bfa61eed93c9fb50d3192744f8bef5 --- libc/include/android/legacy_errno_inlines.h | 4 +++ libc/include/android/legacy_signal_inlines.h | 7 ++++- libc/include/android/legacy_stdlib_inlines.h | 4 +++ libc/include/android/legacy_sys_atomics_inlines.h | 3 +++ libc/include/android/legacy_sys_stat_inlines.h | 4 +++ libc/include/android/legacy_termios_inlines.h | 3 +++ libc/include/errno.h | 6 ++--- libc/include/signal.h | 18 ++++++------- libc/include/stdlib.h | 26 +++++++++--------- libc/include/sys/atomics.h | 2 -- libc/include/sys/cdefs.h | 6 +++++ libc/include/sys/stat.h | 8 +++--- libc/include/termios.h | 32 +++++++++++------------ 13 files changed, 70 insertions(+), 53 deletions(-) diff --git a/libc/include/android/legacy_errno_inlines.h b/libc/include/android/legacy_errno_inlines.h index 71096fc49..93cba1fab 100644 --- a/libc/include/android/legacy_errno_inlines.h +++ b/libc/include/android/legacy_errno_inlines.h @@ -29,8 +29,11 @@ #ifndef _ANDROID_LEGACY_ERRNO_INLINES_H #define _ANDROID_LEGACY_ERRNO_INLINES_H +#include #include +#if __ANDROID_API__ < 21 + __BEGIN_DECLS static __inline int __attribute__((deprecated)) __set_errno(int n) { @@ -40,4 +43,5 @@ static __inline int __attribute__((deprecated)) __set_errno(int n) { __END_DECLS +#endif #endif /* _ANDROID_LEGACY_ERRNO_INLINES_H */ diff --git a/libc/include/android/legacy_signal_inlines.h b/libc/include/android/legacy_signal_inlines.h index 1b6e68712..bf895dabc 100644 --- a/libc/include/android/legacy_signal_inlines.h +++ b/libc/include/android/legacy_signal_inlines.h @@ -29,14 +29,18 @@ #ifndef _ANDROID_LEGACY_SIGNAL_INLINES_H_ #define _ANDROID_LEGACY_SIGNAL_INLINES_H_ +#include +#include #include #include +#if __ANDROID_API__ < 21 + __BEGIN_DECLS extern sighandler_t bsd_signal(int signum, sighandler_t handler); -static __inline int sigismember(sigset_t *set, int signum) { +static __inline int sigismember(const sigset_t *set, int signum) { /* Signal numbers start at 1, but bit positions start at 0. */ int bit = signum - 1; const unsigned long *local_set = (const unsigned long *)set; @@ -95,4 +99,5 @@ static __inline sighandler_t signal(int s, sighandler_t f) { __END_DECLS +#endif #endif /* _ANDROID_LEGACY_SIGNAL_INLINES_H_ */ diff --git a/libc/include/android/legacy_stdlib_inlines.h b/libc/include/android/legacy_stdlib_inlines.h index 58a2a9e5e..93554e596 100644 --- a/libc/include/android/legacy_stdlib_inlines.h +++ b/libc/include/android/legacy_stdlib_inlines.h @@ -29,8 +29,11 @@ #ifndef _ANDROID_LEGACY_STDLIB_INLINES_H_ #define _ANDROID_LEGACY_STDLIB_INLINES_H_ +#include #include +#if __ANDROID_API__ < 21 + __BEGIN_DECLS static __inline float strtof(const char *nptr, char **endptr) { @@ -61,4 +64,5 @@ static __inline int grantpt(int __fd __attribute((unused))) { __END_DECLS +#endif #endif /* _ANDROID_LEGACY_STDLIB_INLINES_H_ */ diff --git a/libc/include/android/legacy_sys_atomics_inlines.h b/libc/include/android/legacy_sys_atomics_inlines.h index 85cbade7d..3314e35fb 100644 --- a/libc/include/android/legacy_sys_atomics_inlines.h +++ b/libc/include/android/legacy_sys_atomics_inlines.h @@ -31,6 +31,8 @@ #include +#if __ANDROID_API__ < 21 + __BEGIN_DECLS /* Note: atomic operations that were exported by the C library didn't @@ -69,4 +71,5 @@ __ATOMIC_INLINE__ int __atomic_inc(volatile int *ptr) { __END_DECLS +#endif #endif /* _ANDROID_LEGACY_SYS_ATOMICS_INLINES_H_ */ diff --git a/libc/include/android/legacy_sys_stat_inlines.h b/libc/include/android/legacy_sys_stat_inlines.h index f6d3c0f3a..c08edfab9 100644 --- a/libc/include/android/legacy_sys_stat_inlines.h +++ b/libc/include/android/legacy_sys_stat_inlines.h @@ -30,6 +30,9 @@ #define _ANDROID_LEGACY_SYS_STAT_INLINES_H_ #include +#include + +#if __ANDROID_API__ < 21 __BEGIN_DECLS @@ -39,4 +42,5 @@ static __inline int mkfifo(const char *__p, mode_t __m) { __END_DECLS +#endif #endif /* _ANDROID_LEGACY_SYS_STAT_INLINES_H_ */ diff --git a/libc/include/android/legacy_termios_inlines.h b/libc/include/android/legacy_termios_inlines.h index fb61f2710..41ea9557a 100644 --- a/libc/include/android/legacy_termios_inlines.h +++ b/libc/include/android/legacy_termios_inlines.h @@ -34,6 +34,8 @@ #include #include +#if __ANDROID_API__ < 21 + __BEGIN_DECLS static __inline int tcgetattr(int fd, struct termios *s) { @@ -90,4 +92,5 @@ static __inline void cfmakeraw(struct termios *s) { __END_DECLS +#endif #endif /* _ANDROID_LEGACY_TERMIOS_INLINES_H_ */ diff --git a/libc/include/errno.h b/libc/include/errno.h index 82f4b429f..2ff136930 100644 --- a/libc/include/errno.h +++ b/libc/include/errno.h @@ -46,10 +46,8 @@ extern volatile int* __errno(void) __pure2; /* a macro expanding to the errno l-value */ #define errno (*__errno()) -#if __ANDROID_API__ < 21 -#include -#endif - __END_DECLS +#include + #endif /* _ERRNO_H */ diff --git a/libc/include/signal.h b/libc/include/signal.h index 763bae982..567940253 100644 --- a/libc/include/signal.h +++ b/libc/include/signal.h @@ -110,15 +110,15 @@ struct sigaction { extern int sigaction(int, const struct sigaction*, struct sigaction*); -extern sighandler_t signal(int, sighandler_t) __INTRODUCED_IN(21); +__BIONIC_LEGACY_INLINE sighandler_t signal(int, sighandler_t); extern int siginterrupt(int, int); -extern int sigaddset(sigset_t*, int) __INTRODUCED_IN(21); -extern int sigdelset(sigset_t*, int) __INTRODUCED_IN(21); -extern int sigemptyset(sigset_t*) __INTRODUCED_IN(21); -extern int sigfillset(sigset_t*) __INTRODUCED_IN(21); -extern int sigismember(const sigset_t*, int) __INTRODUCED_IN(21); +__BIONIC_LEGACY_INLINE int sigaddset(sigset_t*, int); +__BIONIC_LEGACY_INLINE int sigdelset(sigset_t*, int); +__BIONIC_LEGACY_INLINE int sigemptyset(sigset_t*); +__BIONIC_LEGACY_INLINE int sigfillset(sigset_t*); +__BIONIC_LEGACY_INLINE int sigismember(const sigset_t*, int); extern int sigpending(sigset_t*) __nonnull((1)); extern int sigprocmask(int, const sigset_t*, sigset_t*); @@ -147,10 +147,8 @@ extern int sigqueue(pid_t, int, const union sigval); extern int sigtimedwait(const sigset_t*, siginfo_t*, const struct timespec*); extern int sigwaitinfo(const sigset_t*, siginfo_t*); -#if __ANDROID_API__ < 21 -#include -#endif - __END_DECLS +#include + #endif /* _SIGNAL_H_ */ diff --git a/libc/include/stdlib.h b/libc/include/stdlib.h index 88930b155..d0fb0e82e 100644 --- a/libc/include/stdlib.h +++ b/libc/include/stdlib.h @@ -76,10 +76,10 @@ extern unsigned long long strtoull(const char *, char **, int); extern int posix_memalign(void **memptr, size_t alignment, size_t size); -extern double atof(const char*) __INTRODUCED_IN(21); +__BIONIC_LEGACY_INLINE double atof(const char*); extern double strtod(const char*, char**) __LIBC_ABI_PUBLIC__; -extern float strtof(const char*, char**) __LIBC_ABI_PUBLIC__ __INTRODUCED_IN(21); +__BIONIC_LEGACY_INLINE float strtof(const char*, char**) __LIBC_ABI_PUBLIC__; extern long double strtold(const char*, char**) __LIBC_ABI_PUBLIC__; extern long double strtold_l(const char *, char **, locale_t) __LIBC_ABI_PUBLIC__; @@ -90,9 +90,9 @@ extern int atoi(const char*) __purefunc; extern long atol(const char*) __purefunc; extern long long atoll(const char*) __purefunc; -extern int abs(int) __pure2 __INTRODUCED_IN(21); -extern long labs(long) __pure2 __INTRODUCED_IN(21); -extern long long llabs(long long) __pure2 __INTRODUCED_IN(21); +__BIONIC_LEGACY_INLINE int abs(int) __pure2; +__BIONIC_LEGACY_INLINE long labs(long) __pure2; +__BIONIC_LEGACY_INLINE long long llabs(long long) __pure2; extern char * realpath(const char *path, char *resolved); extern int system(const char *string); @@ -109,9 +109,9 @@ void arc4random_buf(void*, size_t); #define RAND_MAX 0x7fffffff -int rand(void) __INTRODUCED_IN(21); +__BIONIC_LEGACY_INLINE int rand(void); int rand_r(unsigned int*); -void srand(unsigned int) __INTRODUCED_IN(21); +__BIONIC_LEGACY_INLINE void srand(unsigned int); double drand48(void); double erand48(unsigned short[3]); @@ -124,12 +124,12 @@ unsigned short* seed48(unsigned short[3]); void srand48(long); char* initstate(unsigned int, char*, size_t); -long random(void) __INTRODUCED_IN(21); +__BIONIC_LEGACY_INLINE long random(void); char* setstate(char*); -void srandom(unsigned int) __INTRODUCED_IN(21); +__BIONIC_LEGACY_INLINE void srandom(unsigned int); int getpt(void); -int grantpt(int) __INTRODUCED_IN(21); +__BIONIC_LEGACY_INLINE int grantpt(int); int posix_openpt(int); char* ptsname(int); int ptsname_r(int, char*, size_t); @@ -174,10 +174,6 @@ extern size_t wcstombs(char *, const wchar_t *, size_t); extern size_t __ctype_get_mb_cur_max(void); #define MB_CUR_MAX __ctype_get_mb_cur_max() -#if __ANDROID_API__ < 21 -#include -#endif - #if defined(__BIONIC_FORTIFY) extern char* __realpath_real(const char*, char*) __RENAME(realpath); @@ -201,4 +197,6 @@ char* realpath(const char* path, char* resolved) { __END_DECLS +#include + #endif /* _STDLIB_H */ diff --git a/libc/include/sys/atomics.h b/libc/include/sys/atomics.h index 38ab3662e..b9b2ba37e 100644 --- a/libc/include/sys/atomics.h +++ b/libc/include/sys/atomics.h @@ -38,8 +38,6 @@ * sys/atomics.h header was removed, so we'll just add these somewhere we can be * sure they will be included. */ -#if __ANDROID_API__ < 21 #include -#endif #endif /* _SYS_ATOMICS_H_ */ diff --git a/libc/include/sys/cdefs.h b/libc/include/sys/cdefs.h index f51942b78..2bd058eb5 100644 --- a/libc/include/sys/cdefs.h +++ b/libc/include/sys/cdefs.h @@ -443,6 +443,12 @@ /* Used to rename functions so that the compiler emits a call to 'x' rather than the function this was applied to. */ #define __RENAME(x) __asm__(#x) +#if __ANDROID_API__ < 21 +#define __BIONIC_LEGACY_INLINE static __inline +#else +#define __BIONIC_LEGACY_INLINE extern +#endif + #ifdef __clang__ #define __AVAILABILITY(...) __attribute__((availability(android,__VA_ARGS__))) #define __INTRODUCED_IN(api_level) __AVAILABILITY(introduced=api_level) diff --git a/libc/include/sys/stat.h b/libc/include/sys/stat.h index 86668f628..ae85f62df 100644 --- a/libc/include/sys/stat.h +++ b/libc/include/sys/stat.h @@ -177,7 +177,7 @@ mode_t umask(mode_t mode) { } #endif /* defined(__BIONIC_FORTIFY) */ -extern int mkfifo(const char*, mode_t) __INTRODUCED_IN(21); +__BIONIC_LEGACY_INLINE int mkfifo(const char*, mode_t); extern int mkfifoat(int, const char*, mode_t); extern int fchmodat(int, const char*, mode_t, int); @@ -189,10 +189,8 @@ extern int mknodat(int, const char*, mode_t, dev_t); extern int utimensat(int fd, const char *path, const struct timespec times[2], int flags); extern int futimens(int fd, const struct timespec times[2]); -#if __ANDROID_API__ < 21 -#include -#endif - __END_DECLS +#include + #endif /* _SYS_STAT_H_ */ diff --git a/libc/include/termios.h b/libc/include/termios.h index 683fde22e..e604747c4 100644 --- a/libc/include/termios.h +++ b/libc/include/termios.h @@ -35,24 +35,22 @@ __BEGIN_DECLS -#if __ANDROID_API__ >= 21 -speed_t cfgetispeed(const struct termios*); -speed_t cfgetospeed(const struct termios*); -void cfmakeraw(struct termios*); -int cfsetispeed(struct termios*, speed_t); -int cfsetospeed(struct termios*, speed_t); -int cfsetspeed(struct termios*, speed_t); -int tcdrain(int); -int tcflow(int, int); -int tcflush(int, int); -int tcgetattr(int, struct termios*); -pid_t tcgetsid(int); -int tcsendbreak(int, int); -int tcsetattr(int, int, const struct termios*); -#else -#include -#endif +__BIONIC_LEGACY_INLINE speed_t cfgetispeed(const struct termios*); +__BIONIC_LEGACY_INLINE speed_t cfgetospeed(const struct termios*); +__BIONIC_LEGACY_INLINE void cfmakeraw(struct termios*); +__BIONIC_LEGACY_INLINE int cfsetispeed(struct termios*, speed_t); +__BIONIC_LEGACY_INLINE int cfsetospeed(struct termios*, speed_t); +__BIONIC_LEGACY_INLINE int cfsetspeed(struct termios*, speed_t); +__BIONIC_LEGACY_INLINE int tcdrain(int); +__BIONIC_LEGACY_INLINE int tcflow(int, int); +__BIONIC_LEGACY_INLINE int tcflush(int, int); +__BIONIC_LEGACY_INLINE int tcgetattr(int, struct termios*); +__BIONIC_LEGACY_INLINE pid_t tcgetsid(int); +__BIONIC_LEGACY_INLINE int tcsendbreak(int, int); +__BIONIC_LEGACY_INLINE int tcsetattr(int, int, const struct termios*); __END_DECLS +#include + #endif /* _TERMIOS_H_ */ -- 2.11.0