fortify(fcntl): emit diagnostics regardless of API level
Bug: 141267932
Test: m checkbuild on internal-master
Change-Id: I2037548cc2061e46c379931588194c21dfe234b4
diff --git a/libc/include/bits/fortify/fcntl.h b/libc/include/bits/fortify/fcntl.h
index 4bb441e..ded62ee 100644
--- a/libc/include/bits/fortify/fcntl.h
+++ b/libc/include/bits/fortify/fcntl.h
@@ -45,7 +45,6 @@
/* O_TMPFILE shares bits with O_DIRECTORY. */
#define __open_modes_useful(flags) (((flags) & O_CREAT) || ((flags) & O_TMPFILE) == O_TMPFILE)
-#if __ANDROID_API__ >= __ANDROID_API_J_MR1__
__BIONIC_ERROR_FUNCTION_VISIBILITY
int open(const char* pathname, int flags, mode_t modes, ...) __overloadable
__errorattr(__open_too_many_args_error);
@@ -60,7 +59,11 @@
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__ >= __ANDROID_API_J_MR1__
return __open_2(pathname, flags);
+#else
+ return __open_real(pathname, flags);
+#endif /* __ANDROID_API__ >= __ANDROID_API_J_MR1__ */
}
__BIONIC_FORTIFY_INLINE
@@ -80,7 +83,11 @@
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__ >= __ANDROID_API_J_MR1__
return __openat_2(dirfd, pathname, flags);
+#else
+ return __openat_real(dirfd, pathname, flags);
+#endif /* __ANDROID_API__ >= __ANDROID_API_J_MR1__ */
}
__BIONIC_FORTIFY_INLINE
@@ -90,13 +97,9 @@
"'openat' " __open_useless_modes_warning) {
return __openat_real(dirfd, pathname, flags, modes);
}
-#endif /* __ANDROID_API__ >= __ANDROID_API_J_MR1__ */
-#if __ANDROID_API__ >= __ANDROID_API_R__
-int __open64_2(const char*, int) __INTRODUCED_IN(30);
-int __openat64_2(int, const char*, int) __INTRODUCED_IN(30);
-int __open64_real(const char* __path, int __flags, ...) __RENAME(open64);
-int __openat64_real(int, const char*, int, ...) __RENAME(openat64);
+#if __ANDROID_API__ >= __ANDROID_API_L__
+/* Note that open == open64, so we reuse those bits in the open64 variants below. */
__BIONIC_ERROR_FUNCTION_VISIBILITY
int open64(const char* pathname, int flags, mode_t modes, ...) __overloadable
@@ -106,7 +109,7 @@
int open64(const char* const __pass_object_size pathname, int flags)
__overloadable
__clang_error_if(__open_modes_useful(flags), "'open64' " __open_too_few_args_error) {
- return __open64_2(pathname, flags);
+ return __open_2(pathname, flags);
}
__BIONIC_FORTIFY_INLINE
@@ -114,7 +117,7 @@
__overloadable
__clang_warning_if(!__open_modes_useful(flags) && modes,
"'open64' " __open_useless_modes_warning) {
- return __open64_real(pathname, flags, modes);
+ return __open_real(pathname, flags, modes);
}
__BIONIC_ERROR_FUNCTION_VISIBILITY
@@ -126,7 +129,7 @@
int openat64(int dirfd, const char* const __pass_object_size pathname, int flags)
__overloadable
__clang_error_if(__open_modes_useful(flags), "'openat64' " __open_too_few_args_error) {
- return __openat64_2(dirfd, pathname, flags);
+ return __openat_2(dirfd, pathname, flags);
}
__BIONIC_FORTIFY_INLINE
@@ -134,9 +137,9 @@
__overloadable
__clang_warning_if(!__open_modes_useful(flags) && modes,
"'openat64' " __open_useless_modes_warning) {
- return __openat64_real(dirfd, pathname, flags, modes);
+ return __openat_real(dirfd, pathname, flags, modes);
}
-#endif /* __ANDROID_API__ >= __ANDROID_API_R__ */
+#endif /* __ANDROID_API__ >= __ANDROID_API_L__ */
#undef __open_too_many_args_error
#undef __open_too_few_args_error