libc/include: remove easy __ANDROID_API__ tautologies.

The next NDK to take these headers only supports API 21 and later, so
clean up some of the trivial cruft.

This doesn't include the remaining "legacy inlines", since they're a bit
more complicated. I'll remove those in later changes.

Test: treehugger
Change-Id: I94c32f6393dd3ae831165917303ea591222baa0d
This commit is contained in:
Elliott Hughes 2023-02-23 17:38:37 +00:00
parent d3ebc2f7c4
commit f4ace9d634
15 changed files with 21 additions and 94 deletions

View file

@ -59,7 +59,7 @@ __BIONIC_FORTIFY_INLINE
int open(const char* const __pass_object_size pathname, int flags)
__overloadable
__clang_error_if(__open_modes_useful(flags), "'open' " __open_too_few_args_error) {
#if __ANDROID_API__ >= 17 && __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED
#if __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED
return __open_2(pathname, flags);
#else
return __open_real(pathname, flags);
@ -83,7 +83,7 @@ __BIONIC_FORTIFY_INLINE
int openat(int dirfd, const char* const __pass_object_size pathname, int flags)
__overloadable
__clang_error_if(__open_modes_useful(flags), "'openat' " __open_too_few_args_error) {
#if __ANDROID_API__ >= 17 && __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED
#if __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED
return __openat_2(dirfd, pathname, flags);
#else
return __openat_real(dirfd, pathname, flags);
@ -98,7 +98,6 @@ int openat(int dirfd, const char* const __pass_object_size pathname, int flags,
return __openat_real(dirfd, pathname, flags, modes);
}
#if __ANDROID_API__ >= 21
/* Note that open == open64, so we reuse those bits in the open64 variants below. */
__BIONIC_ERROR_FUNCTION_VISIBILITY
@ -139,7 +138,6 @@ int openat64(int dirfd, const char* const __pass_object_size pathname, int flags
"'openat64' " __open_useless_modes_warning) {
return openat(dirfd, pathname, flags, modes);
}
#endif /* __ANDROID_API__ >= 21 */
#undef __open_too_many_args_error
#undef __open_too_few_args_error

View file

@ -54,7 +54,6 @@ int poll(struct pollfd* const fds __pass_object_size, nfds_t fd_count, int timeo
return __call_bypassing_fortify(poll)(fds, fd_count, timeout);
}
#if __ANDROID_API__ >= 21
__BIONIC_FORTIFY_INLINE
int ppoll(struct pollfd* const fds __pass_object_size, nfds_t fd_count, const struct timespec* timeout, const sigset_t* mask)
__overloadable
@ -69,7 +68,6 @@ int ppoll(struct pollfd* const fds __pass_object_size, nfds_t fd_count, const st
#endif
return __call_bypassing_fortify(ppoll)(fds, fd_count, timeout, mask);
}
#endif /* __ANDROID_API__ >= 21 */
#if __ANDROID_API__ >= 28
__BIONIC_FORTIFY_INLINE

View file

@ -39,7 +39,7 @@ mode_t umask(mode_t mode)
__overloadable
__enable_if(1, "")
__clang_error_if(mode & ~0777, "'umask' called with invalid mode") {
#if __ANDROID_API__ >= 18 && __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED
#if __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED
return __umask_chk(mode);
#else
return __umask_real(mode);

View file

@ -36,7 +36,7 @@ size_t __fwrite_chk(const void*, size_t, size_t, FILE*, size_t) __INTRODUCED_IN(
#if defined(__BIONIC_FORTIFY) && !defined(__BIONIC_NO_STDIO_FORTIFY)
#if __ANDROID_API__ >= 17 && __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED
#if __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED
/* No diag -- clang diagnoses misuses of this on its own. */
__BIONIC_FORTIFY_INLINE __printflike(3, 0)
int vsnprintf(char* const __pass_object_size dest, size_t size, const char* format, va_list ap)
@ -58,7 +58,7 @@ int sprintf(char* dest, const char* format)
"format string will always overflow destination buffer")
__errorattr("format string will always overflow destination buffer");
#if __ANDROID_API__ >= 17 && __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED
#if __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED
__BIONIC_FORTIFY_VARIADIC __printflike(2, 3)
int sprintf(char* const __pass_object_size dest, const char* format, ...) __overloadable {
va_list va;
@ -126,7 +126,7 @@ char* fgets(char* const __pass_object_size dest, int size, FILE* stream)
__clang_error_if(size < 0, "in call to 'fgets', size should not be negative")
__clang_error_if(__bos_unevaluated_lt(__bos(dest), size),
"in call to 'fgets', size is larger than the destination buffer") {
#if __ANDROID_API__ >= 17 && __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED
#if __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED
size_t bos = __bos(dest);
if (!__bos_dynamic_check_impl_and(bos, >=, (size_t)size, size >= 0)) {

View file

@ -40,7 +40,7 @@ size_t __strlcat_chk(char*, const char*, size_t, size_t) __INTRODUCED_IN(17);
#if defined(__BIONIC_FORTIFY)
extern void* __memrchr_real(const void*, int, size_t) __RENAME(memrchr);
#if __ANDROID_API__ >= 17 && __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED
#if __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED
/* No diag -- clang diagnoses misuses of this on its own. */
__BIONIC_FORTIFY_INLINE
void* memcpy(void* const dst __pass_object_size0, const void* src, size_t copy_amount)
@ -82,7 +82,7 @@ char* stpcpy(char* const dst __pass_object_size, const char* src)
__overloadable
__clang_error_if(__bos_unevaluated_le(__bos(dst), __builtin_strlen(src)),
"'stpcpy' called with string bigger than buffer") {
#if __ANDROID_API__ >= 21 && __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED
#if __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED
return __builtin___stpcpy_chk(dst, src, __bos(dst));
#else
return __builtin_stpcpy(dst, src);
@ -95,7 +95,7 @@ char* strcpy(char* const dst __pass_object_size, const char* src)
__overloadable
__clang_error_if(__bos_unevaluated_le(__bos(dst), __builtin_strlen(src)),
"'strcpy' called with string bigger than buffer") {
#if __ANDROID_API__ >= 17 && __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED
#if __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED
return __builtin___strcpy_chk(dst, src, __bos(dst));
#else
return __builtin_strcpy(dst, src);
@ -107,14 +107,14 @@ char* strcat(char* const dst __pass_object_size, const char* src)
__overloadable
__clang_error_if(__bos_unevaluated_le(__bos(dst), __builtin_strlen(src)),
"'strcat' called with string bigger than buffer") {
#if __ANDROID_API__ >= 17 && __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED
#if __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED
return __builtin___strcat_chk(dst, src, __bos(dst));
#else
return __builtin_strcat(dst, src);
#endif
}
#if __ANDROID_API__ >= 17 && __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED
#if __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED
/* No diag -- clang diagnoses misuses of this on its own. */
__BIONIC_FORTIFY_INLINE
char* strncat(char* const dst __pass_object_size, const char* src, size_t n)
@ -130,7 +130,7 @@ void* memset(void* const s __pass_object_size0, int c, size_t n) __overloadable
__diagnose_as_builtin(__builtin_memset, 1, 2, 3)
/* If you're a user who wants this warning to go away: use `(&memset)(foo, bar, baz)`. */
__clang_warning_if(c && !n, "'memset' will set 0 bytes; maybe the arguments got flipped?") {
#if __ANDROID_API__ >= 17 && __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED
#if __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED
return __builtin___memset_chk(s, c, n, __bos0(s));
#else
return __builtin_memset(s, c, n);
@ -161,7 +161,7 @@ void* __memrchr_fortify(const void* const __pass_object_size s, int c, size_t n)
}
#endif
#if __ANDROID_API__ >= 21 && __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED
#if __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED
/* No diag -- clang diagnoses misuses of this on its own. */
__BIONIC_FORTIFY_INLINE
char* stpncpy(char* const dst __pass_object_size, const char* const src __pass_object_size, size_t n)
@ -200,7 +200,7 @@ size_t strlcpy(char* const dst __pass_object_size, const char* src, size_t size)
__overloadable
__clang_error_if(__bos_unevaluated_lt(__bos(dst), size),
"'strlcpy' called with size bigger than buffer") {
#if __ANDROID_API__ >= 17 && __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED
#if __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED
return __strlcpy_chk(dst, src, size, __bos(dst));
#else
return __call_bypassing_fortify(strlcpy)(dst, src, size);
@ -212,14 +212,14 @@ size_t strlcat(char* const dst __pass_object_size, const char* src, size_t size)
__overloadable
__clang_error_if(__bos_unevaluated_lt(__bos(dst), size),
"'strlcat' called with size bigger than buffer") {
#if __ANDROID_API__ >= 17 && __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED
#if __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED
return __strlcat_chk(dst, src, size, __bos(dst));
#else
return __call_bypassing_fortify(strlcat)(dst, src, size);
#endif
}
#if __ANDROID_API__ >= 17 && __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED
#if __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED
__BIONIC_FORTIFY_INLINE
size_t strlen(const char* const s __pass_object_size0) __overloadable {
return __strlen_chk(s, __bos0(s));
@ -228,7 +228,7 @@ size_t strlen(const char* const s __pass_object_size0) __overloadable {
__BIONIC_FORTIFY_INLINE
char* strchr(const char* const s __pass_object_size, int c) __overloadable {
#if __ANDROID_API__ >= 18 && __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED
#if __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED
size_t bos = __bos(s);
if (bos != __BIONIC_FORTIFY_UNKNOWN_SIZE) {
@ -240,7 +240,7 @@ char* strchr(const char* const s __pass_object_size, int c) __overloadable {
__BIONIC_FORTIFY_INLINE
char* strrchr(const char* const s __pass_object_size, int c) __overloadable {
#if __ANDROID_API__ >= 18 && __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED
#if __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED
size_t bos = __bos(s);
if (bos != __BIONIC_FORTIFY_UNKNOWN_SIZE) {

View file

@ -33,7 +33,7 @@ void __bionic_bcopy(const void *src, void* const dst __pass_object_size0, size_t
__overloadable
__clang_error_if(__bos_unevaluated_lt(__bos0(dst), len),
"'bcopy' called with size bigger than buffer") {
#if __ANDROID_API__ >= 17 && __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED
#if __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED
size_t bos = __bos0(dst);
if (!__bos_trivially_ge(bos, len)) {
__builtin___memmove_chk(dst, src, len, bos);
@ -48,7 +48,7 @@ void __bionic_bzero(void* const b __pass_object_size0, size_t len)
__overloadable
__clang_error_if(__bos_unevaluated_lt(__bos0(b), len),
"'bzero' called with size bigger than buffer") {
#if __ANDROID_API__ >= 17 && __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED
#if __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED
size_t bos = __bos0(b);
if (!__bos_trivially_ge(bos, len)) {
__builtin___memset_chk(b, 0, len, bos);

View file

@ -152,7 +152,7 @@ ssize_t read(int fd, void* const __pass_object_size0 buf, size_t count)
__overloadable
__error_if_overflows_ssizet(count, read)
__error_if_overflows_objectsize(count, __bos0(buf), read) {
#if __ANDROID_API__ >= 21 && __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED
#if __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED
size_t bos = __bos0(buf);
if (!__bos_trivially_ge_no_overflow(bos, count)) {
@ -192,7 +192,6 @@ ssize_t readlink(const char* path, char* const __pass_object_size buf, size_t si
return __call_bypassing_fortify(readlink)(path, buf, size);
}
#if __ANDROID_API__ >= 21
__BIONIC_FORTIFY_INLINE
ssize_t readlinkat(int dirfd, const char* path, char* const __pass_object_size buf, size_t size)
__overloadable
@ -207,7 +206,6 @@ ssize_t readlinkat(int dirfd, const char* path, char* const __pass_object_size b
#endif
return __call_bypassing_fortify(readlinkat)(dirfd, path, buf, size);
}
#endif /* __ANDROID_API__ >= 21 */
#undef __bos_trivially_ge_no_overflow
#undef __enable_if_no_overflow_ssizet

View file

@ -84,7 +84,6 @@ __BEGIN_DECLS
/** Flag for open(). */
#define O_RSYNC O_SYNC
#if __ANDROID_API__ >= 21
/** Flag for splice(). */
#define SPLICE_F_MOVE 1
/** Flag for splice(). */
@ -93,7 +92,6 @@ __BEGIN_DECLS
#define SPLICE_F_MORE 4
/** Flag for splice(). */
#define SPLICE_F_GIFT 8
#endif
#if __ANDROID_API__ >= 26
/** Flag for sync_file_range(). */

View file

@ -58,9 +58,7 @@ enum {
#define PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP { { ((PTHREAD_MUTEX_ERRORCHECK & 3) << 14) } }
#define PTHREAD_COND_INITIALIZER { { 0 } }
#if __ANDROID_API__ >= 21
#define PTHREAD_COND_INITIALIZER_MONOTONIC_NP { { 1 << 1 } }
#endif
#define PTHREAD_RWLOCK_INITIALIZER { { 0 } }

View file

@ -136,20 +136,8 @@ int ungetc(int __ch, FILE* __fp);
int vfprintf(FILE* __fp, const char* __fmt, va_list __args) __printflike(2, 0);
int vprintf(const char* __fp, va_list __args) __printflike(1, 0);
#if __ANDROID_API__ >= 21
int dprintf(int __fd, const char* __fmt, ...) __printflike(2, 3) __INTRODUCED_IN(21);
int vdprintf(int __fd, const char* __fmt, va_list __args) __printflike(2, 0) __INTRODUCED_IN(21);
#else
/*
* Old versions of Android called these fdprintf and vfdprintf out of fears that the glibc names
* would collide with user debug printfs.
*
* Allow users to just use dprintf and vfdprintf on any version by renaming those calls to their
* legacy equivalents if needed.
*/
int dprintf(int __fd, const char* __fmt, ...) __RENAME(fdprintf) __printflike(2, 3);
int vdprintf(int __fd, const char* __fmt, va_list __args) __RENAME(vfdprintf) __printflike(2, 0);
#endif
#if (defined(__STDC_VERSION__) && __STDC_VERSION__ < 201112L) || \
(defined(__cplusplus) && __cplusplus <= 201103L)

View file

@ -43,11 +43,7 @@ __BEGIN_DECLS
__noreturn void abort(void) __attribute__((__nomerge__));
__noreturn void exit(int __status);
#if __ANDROID_API__ >= 21
__noreturn void _Exit(int __status) __INTRODUCED_IN(21);
#else
__noreturn void _Exit(int) __RENAME(_exit);
#endif
int atexit(void (* _Nonnull __fn)(void));

View file

@ -40,21 +40,6 @@ __BEGIN_DECLS
int epoll_create(int __size);
int epoll_create1(int __flags) __INTRODUCED_IN(21);
/*
* Some third-party code uses the existence of EPOLL_CLOEXEC to detect the
* availability of epoll_create1. This is not correct, since having up-to-date
* UAPI headers says nothing about the C library, but for the time being we
* don't want to harm adoption to the unified headers. We'll undef EPOLL_CLOEXEC
* if we don't have epoll_create1 for the time being, and maybe revisit this
* later.
*
* https://github.com/android-ndk/ndk/issues/302
* https://github.com/android-ndk/ndk/issues/394
*/
#if __ANDROID_API__ < 21 && defined(EPOLL_CLOEXEC)
#undef EPOLL_CLOEXEC
#endif
int epoll_ctl(int __epoll_fd, int __op, int __fd, struct epoll_event* __BIONIC_COMPLICATED_NULLNESS __event);
int epoll_wait(int __epoll_fd, struct epoll_event* _Nonnull __events, int __event_count, int __timeout_ms);
int epoll_pwait(int __epoll_fd, struct epoll_event* _Nonnull __events, int __event_count, int __timeout_ms, const sigset_t* _Nullable __mask) __INTRODUCED_IN(21);

View file

@ -37,21 +37,8 @@
__BEGIN_DECLS
/*
* Some third-party code uses the existence of IN_CLOEXEC/IN_NONBLOCK to detect
* the availability of inotify_init1. This is not correct, since
* `syscall(__NR_inotify_init1, IN_CLOEXEC)` is still valid even if the C
* library doesn't have that function, but for the time being we don't want to
* harm adoption to the unified headers. We'll avoid defining IN_CLOEXEC and
* IN_NONBLOCK if we don't have inotify_init1 for the time being, and maybe
* revisit this later.
*
* https://github.com/android-ndk/ndk/issues/394
*/
#if __ANDROID_API__ >= 21
#define IN_CLOEXEC O_CLOEXEC
#define IN_NONBLOCK O_NONBLOCK
#endif
int inotify_init(void);
int inotify_init1(int __flags) __INTRODUCED_IN(21);

View file

@ -79,8 +79,6 @@ int __FD_ISSET_chk(int, const fd_set*, size_t) __INTRODUCED_IN(21);
#define __FD_SET(fd, set) (__FDS_BITS(fd_set*,set)[__FDELT(fd)] |= __FDMASK(fd))
#define __FD_ISSET(fd, set) ((__FDS_BITS(const fd_set*,set)[__FDELT(fd)] & __FDMASK(fd)) != 0)
#if __ANDROID_API__ >= 21
/** Removes `fd` from the given set. Use <poll.h> instead. */
#define FD_CLR(fd, set) __FD_CLR_chk(fd, set, __bos(set))
/** Adds `fd` to the given set. Use <poll.h> instead. */
@ -88,17 +86,6 @@ int __FD_ISSET_chk(int, const fd_set*, size_t) __INTRODUCED_IN(21);
/** Tests whether `fd` is in the given set. Use <poll.h> instead. */
#define FD_ISSET(fd, set) __FD_ISSET_chk(fd, set, __bos(set))
#else
/** Removes `fd` from the given set. Use <poll.h> instead. */
#define FD_CLR(fd, set) __FD_CLR(fd, set)
/** Adds `fd` to the given set. Use <poll.h> instead. */
#define FD_SET(fd, set) __FD_SET(fd, set)
/** Tests whether `fd` is in the given set. Use <poll.h> instead. */
#define FD_ISSET(fd, set) __FD_ISSET(fd, set)
#endif /* __ANDROID_API >= 21 */
/**
* [select(2)](http://man7.org/linux/man-pages/man2/select.2.html) waits on a
* set of file descriptors.

View file

@ -303,13 +303,7 @@ int ttyname_r(int __fd, char* _Nonnull __buf, size_t __buf_size);
int acct(const char* _Nullable __path);
#if __ANDROID_API__ >= 21
int getpagesize(void) __INTRODUCED_IN(21);
#else
static __inline__ int getpagesize(void) {
return sysconf(_SC_PAGESIZE);
}
#endif
long syscall(long __number, ...);