Guard fortify inlines with __ANDROID_API__.
Test: make checkbuild with libc ndk_library patches applied
Change-Id: Ic5e248994c4f2702b0f4d6dfeda787187ea86017
diff --git a/libc/include/poll.h b/libc/include/poll.h
index d75c2d0..0fa55d2 100644
--- a/libc/include/poll.h
+++ b/libc/include/poll.h
@@ -53,6 +53,7 @@
#if defined(__BIONIC_FORTIFY)
+#if __ANDROID_API__ >= 23
__BIONIC_FORTIFY_INLINE
int poll(struct pollfd* fds, nfds_t fd_count, int timeout) {
#if defined(__clang__)
@@ -84,6 +85,7 @@
return __ppoll_real(fds, fd_count, timeout, mask);
#endif
}
+#endif /* __ANDROID_API__ >= 23 */
#endif
diff --git a/libc/include/stdio.h b/libc/include/stdio.h
index 03effcd..1bbd669 100644
--- a/libc/include/stdio.h
+++ b/libc/include/stdio.h
@@ -266,6 +266,7 @@
#if defined(__BIONIC_FORTIFY)
+#if __ANDROID_API__ >= 17
__BIONIC_FORTIFY_INLINE
__printflike(3, 0) int vsnprintf(char* dest, size_t size, const char* _Nonnull format, __va_list ap) {
return __builtin___vsnprintf_chk(dest, size, 0, __bos(dest), format, ap);
@@ -299,7 +300,9 @@
return __builtin___sprintf_chk(dest, 0, __bos(dest), format, __builtin_va_arg_pack());
}
#endif
+#endif /* __ANDROID_API__ >= 17 */
+#if __ANDROID_API__ >= 24
__BIONIC_FORTIFY_INLINE
size_t fread(void * __restrict buf, size_t size, size_t count, FILE * __restrict stream) {
size_t bos = __bos0(buf);
@@ -351,6 +354,7 @@
return __fwrite_chk(buf, size, count, stream, bos);
}
+#endif /* __ANDROID_API__ >= 24 */
#if !defined(__clang__)
diff --git a/libc/include/string.h b/libc/include/string.h
index c5bcd22..18b12bd 100644
--- a/libc/include/string.h
+++ b/libc/include/string.h
@@ -148,6 +148,7 @@
#if defined(__BIONIC_FORTIFY)
+#if __ANDROID_API__ >= 23
__BIONIC_FORTIFY_INLINE
void* memchr(const void* s, int c, size_t n) {
size_t bos = __bos(s);
@@ -189,7 +190,9 @@
return __memrchr_chk(s, c, n, bos);
}
+#endif /* __ANDROID_API__ >= 23 */
+#if __ANDROID_API__ >= 17
__BIONIC_FORTIFY_INLINE
void* memcpy(void* _Nonnull __restrict dst, const void* _Nonnull __restrict src, size_t copy_amount) {
return __builtin___memcpy_chk(dst, src, copy_amount, __bos0(dst));
@@ -199,17 +202,23 @@
void* memmove(void* _Nonnull dst, const void* _Nonnull src, size_t len) {
return __builtin___memmove_chk(dst, src, len, __bos0(dst));
}
+#endif /* __ANDROID_API__ >= 17 */
+#if __ANDROID_API__ >= 21
__BIONIC_FORTIFY_INLINE
char* stpcpy(char* _Nonnull __restrict dst, const char* _Nonnull __restrict src) {
return __builtin___stpcpy_chk(dst, src, __bos(dst));
}
+#endif /* __ANDROID_API__ >= 21 */
+#if __ANDROID_API__ >= 17
__BIONIC_FORTIFY_INLINE
char* strcpy(char* _Nonnull __restrict dst, const char* _Nonnull __restrict src) {
return __builtin___strcpy_chk(dst, src, __bos(dst));
}
+#endif /* __ANDROID_API__ >= 17 */
+#if __ANDROID_API__ >= 21
__BIONIC_FORTIFY_INLINE
char* stpncpy(char* _Nonnull __restrict dst, const char* _Nonnull __restrict src, size_t n) {
size_t bos_dst = __bos(dst);
@@ -230,7 +239,9 @@
return __stpncpy_chk2(dst, src, n, bos_dst, bos_src);
}
+#endif /* __ANDROID_API__ >= 21 */
+#if __ANDROID_API__ >= 17
__BIONIC_FORTIFY_INLINE
char* strncpy(char* _Nonnull __restrict dst, const char* _Nonnull __restrict src, size_t n) {
size_t bos_dst = __bos(dst);
@@ -326,7 +337,9 @@
return __strlen_chk(s, bos);
}
+#endif /* __ANDROID_API__ >= 17 */
+#if __ANDROID_API__ >= 18
__BIONIC_FORTIFY_INLINE
char* strchr(const char* _Nonnull s, int c) {
size_t bos = __bos(s);
@@ -364,7 +377,7 @@
return __strrchr_chk(s, c, bos);
}
-
+#endif /* __ANDROID_API__ >= 18 */
#endif /* defined(__BIONIC_FORTIFY) */
diff --git a/libc/include/sys/socket.h b/libc/include/sys/socket.h
index 40b9d37..223c3b2 100644
--- a/libc/include/sys/socket.h
+++ b/libc/include/sys/socket.h
@@ -300,6 +300,7 @@
#if defined(__BIONIC_FORTIFY)
+#if __ANDROID_API__ >= 24
__BIONIC_FORTIFY_INLINE
ssize_t recvfrom(int fd, void* buf, size_t len, int flags, const struct sockaddr* src_addr, socklen_t* addr_len) {
size_t bos = __bos0(buf);
@@ -320,6 +321,7 @@
return __recvfrom_chk(fd, buf, len, bos, flags, src_addr, addr_len);
}
+#endif /* __ANDROID_API__ >= 24 */
__BIONIC_FORTIFY_INLINE
ssize_t recv(int socket, void* buf, size_t len, int flags) {
diff --git a/libc/include/sys/stat.h b/libc/include/sys/stat.h
index 0d350e0..775fb08 100644
--- a/libc/include/sys/stat.h
+++ b/libc/include/sys/stat.h
@@ -163,6 +163,7 @@
#if defined(__BIONIC_FORTIFY)
+#if __ANDROID_API__ >= 18
__BIONIC_FORTIFY_INLINE
mode_t umask(mode_t mode) {
#if !defined(__clang__)
@@ -175,6 +176,8 @@
#endif
return __umask_chk(mode);
}
+#endif /* __ANDROID_API__ >= 18 */
+
#endif /* defined(__BIONIC_FORTIFY) */
#if __ANDROID_API__ >= 21
diff --git a/libc/include/unistd.h b/libc/include/unistd.h
index c45a2e6..c792289 100644
--- a/libc/include/unistd.h
+++ b/libc/include/unistd.h
@@ -286,6 +286,7 @@
#if defined(__BIONIC_FORTIFY)
+#if __ANDROID_API__ >= 24
__BIONIC_FORTIFY_INLINE
char* getcwd(char* buf, size_t size) {
size_t bos = __bos(buf);
@@ -316,6 +317,7 @@
return __getcwd_chk(buf, size, bos);
}
+#endif /* __ANDROID_API__ >= 24 */
#if defined(__USE_FILE_OFFSET64)
#define __PREAD_PREFIX(x) __pread64_ ## x
@@ -323,6 +325,7 @@
#define __PREAD_PREFIX(x) __pread_ ## x
#endif
+#if __ANDROID_API__ >= 23
__BIONIC_FORTIFY_INLINE
ssize_t pread(int fd, void* buf, size_t count, off_t offset) {
size_t bos = __bos0(buf);
@@ -372,6 +375,7 @@
return __pread64_chk(fd, buf, count, offset, bos);
}
+#endif /* __ANDROID_API__ >= 23 */
#if defined(__USE_FILE_OFFSET64)
#define __PWRITE_PREFIX(x) __pwrite64_ ## x
@@ -379,6 +383,7 @@
#define __PWRITE_PREFIX(x) __pwrite_ ## x
#endif
+#if __ANDROID_API__ >= 24
__BIONIC_FORTIFY_INLINE
ssize_t pwrite(int fd, const void* buf, size_t count, off_t offset) {
size_t bos = __bos0(buf);
@@ -428,7 +433,9 @@
return __pwrite64_chk(fd, buf, count, offset, bos);
}
+#endif /* __ANDROID_API__ >= 24 */
+#if __ANDROID_API__ >= 21
__BIONIC_FORTIFY_INLINE
ssize_t read(int fd, void* buf, size_t count) {
size_t bos = __bos0(buf);
@@ -453,7 +460,9 @@
return __read_chk(fd, buf, count, bos);
}
+#endif /* __ANDROID_API__ >= 21 */
+#if __ANDROID_API__ >= 24
__BIONIC_FORTIFY_INLINE
ssize_t write(int fd, const void* buf, size_t count) {
size_t bos = __bos0(buf);
@@ -480,6 +489,7 @@
return __write_chk(fd, buf, count, bos);
}
+#endif /* __ANDROID_API__ >= 24 */
__BIONIC_FORTIFY_INLINE
ssize_t readlink(const char* path, char* buf, size_t size) {