Merge changes Id513b72a,I92cd0116,I62393b58,I90ac2224,I527f88ac
* changes:
Provide fake definitions for libstdc++.
Provide static inlines for in6addr things.
Provide an inline __cmsg_nxthdr.
Correct more fortify availability guards.
Move strncpy fortify into android-21.
diff --git a/libc/include/bits/wctype.h b/libc/include/bits/wctype.h
index b98e500..c968d71 100644
--- a/libc/include/bits/wctype.h
+++ b/libc/include/bits/wctype.h
@@ -58,8 +58,8 @@
int iswctype(wint_t, wctype_t);
typedef const void* wctrans_t;
-wint_t towctrans(wint_t, wctrans_t) __INTRODUCED_IN_FUTURE;
-wctrans_t wctrans(const char*) __INTRODUCED_IN_FUTURE;
+wint_t towctrans(wint_t, wctrans_t) __INTRODUCED_IN_FUTURE __VERSIONER_NO_GUARD;
+wctrans_t wctrans(const char*) __INTRODUCED_IN_FUTURE __VERSIONER_NO_GUARD;
__END_DECLS
diff --git a/libc/include/locale.h b/libc/include/locale.h
index a681a17..c1b6299 100644
--- a/libc/include/locale.h
+++ b/libc/include/locale.h
@@ -96,7 +96,7 @@
char int_n_sign_posn;
};
-struct lconv* localeconv(void) __INTRODUCED_IN(21);
+struct lconv* localeconv(void) __INTRODUCED_IN(21) __VERSIONER_NO_GUARD;
locale_t duplocale(locale_t) __INTRODUCED_IN(21);
void freelocale(locale_t) __INTRODUCED_IN(21);
diff --git a/libc/include/math.h b/libc/include/math.h
index 37aa2cc..3b12764 100644
--- a/libc/include/math.h
+++ b/libc/include/math.h
@@ -259,11 +259,12 @@
long double fabsl(long double) __pure2;
long double fdiml(long double, long double);
long double floorl(long double);
-long double fmal(long double, long double, long double) __INTRODUCED_IN(21);
+long double fmal(long double, long double, long double) __INTRODUCED_IN(21) __VERSIONER_NO_GUARD;
long double fmaxl(long double, long double) __pure2;
long double fminl(long double, long double) __pure2;
long double fmodl(long double, long double) __INTRODUCED_IN(21);
-long double frexpl(long double value, int*) __INTRODUCED_IN(21); /* fundamentally !__pure2 */
+long double frexpl(long double value, int*)
+ __INTRODUCED_IN(21) __VERSIONER_NO_GUARD; /* fundamentally !__pure2 */
long double hypotl(long double, long double) __INTRODUCED_IN(21);
int ilogbl(long double) __pure2;
long double ldexpl(long double, int);
@@ -280,10 +281,10 @@
long double modfl(long double, long double*) __INTRODUCED_IN(21); /* fundamentally !__pure2 */
long double nanl(const char*) __pure2 __INTRODUCED_IN(13);
long double nearbyintl(long double) __INTRODUCED_IN(21);
-long double nextafterl(long double, long double) __INTRODUCED_IN(21);
-double nexttoward(double, long double) __INTRODUCED_IN(18);
+long double nextafterl(long double, long double) __INTRODUCED_IN(21) __VERSIONER_NO_GUARD;
+double nexttoward(double, long double) __INTRODUCED_IN(18) __VERSIONER_NO_GUARD;
float nexttowardf(float, long double);
-long double nexttowardl(long double, long double) __INTRODUCED_IN(18);
+long double nexttowardl(long double, long double) __INTRODUCED_IN(18) __VERSIONER_NO_GUARD;
long double powl(long double, long double) __INTRODUCED_IN(21);
long double remainderl(long double, long double) __INTRODUCED_IN(21);
long double remquol(long double, long double, int*) __INTRODUCED_IN(21);
diff --git a/libc/include/netinet/in.h b/libc/include/netinet/in.h
index 00b5cf9..3574976 100644
--- a/libc/include/netinet/in.h
+++ b/libc/include/netinet/in.h
@@ -47,8 +47,13 @@
int bindresvport(int, struct sockaddr_in*);
+#if __ANDROID_API__ >= 24
extern const struct in6_addr in6addr_any __INTRODUCED_IN(24);
extern const struct in6_addr in6addr_loopback __INTRODUCED_IN(24);
+#else
+static const struct in6_addr in6addr_any = IN6ADDR_ANY_INIT;
+static const struct in6_addr in6addr_loopback = IN6ADDR_LOOPBACK_INIT;
+#endif /* __ANDROID_API__ >= 24 */
__END_DECLS
diff --git a/libc/include/stdlib.h b/libc/include/stdlib.h
index 28cd4a8..6b0ec12 100644
--- a/libc/include/stdlib.h
+++ b/libc/include/stdlib.h
@@ -147,14 +147,23 @@
const char* getprogname(void) __INTRODUCED_IN(21);
void setprogname(const char*) __INTRODUCED_IN(21);
-int mblen(const char*, size_t) __INTRODUCED_IN_FUTURE;
+int mblen(const char*, size_t) __INTRODUCED_IN_FUTURE __VERSIONER_NO_GUARD;
size_t mbstowcs(wchar_t*, const char*, size_t);
-int mbtowc(wchar_t*, const char*, size_t) __INTRODUCED_IN(21);
-int wctomb(char*, wchar_t) __INTRODUCED_IN(21);
+int mbtowc(wchar_t*, const char*, size_t) __INTRODUCED_IN(21) __VERSIONER_NO_GUARD;
+int wctomb(char*, wchar_t) __INTRODUCED_IN(21) __VERSIONER_NO_GUARD;
+
size_t wcstombs(char*, const wchar_t*, size_t);
+#if __ANDROID_API__ >= 21
size_t __ctype_get_mb_cur_max(void) __INTRODUCED_IN(21);
#define MB_CUR_MAX __ctype_get_mb_cur_max()
+#else
+/*
+ * 4 is only true for UTF-8 locales, but that's what we default to. We'll need
+ * the NDK compatibility library to fix this properly.
+ */
+#define MB_CUR_MAX 4
+#endif
#if defined(__BIONIC_FORTIFY)
diff --git a/libc/include/string.h b/libc/include/string.h
index 18b12bd..4a83c4e 100644
--- a/libc/include/string.h
+++ b/libc/include/string.h
@@ -239,9 +239,7 @@
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);
@@ -262,7 +260,9 @@
return __strncpy_chk2(dst, src, n, bos_dst, bos_src);
}
+#endif /* __ANDROID_API__ >= 21 */
+#if __ANDROID_API__ >= 17
__BIONIC_FORTIFY_INLINE
char* strcat(char* _Nonnull __restrict dst, const char* _Nonnull __restrict src) {
return __builtin___strcat_chk(dst, src, __bos(dst));
diff --git a/libc/include/sys/select.h b/libc/include/sys/select.h
index 0f454b0..5a8a81d 100644
--- a/libc/include/sys/select.h
+++ b/libc/include/sys/select.h
@@ -61,7 +61,7 @@
void __FD_SET_chk(int, fd_set*, size_t) __INTRODUCED_IN(21);
int __FD_ISSET_chk(int, fd_set*, size_t) __INTRODUCED_IN(21);
-#if defined(__BIONIC_FORTIFY)
+#if defined(__BIONIC_FORTIFY) && __ANDROID_API__ >= 21
#define FD_CLR(fd, set) __FD_CLR_chk(fd, set, __bos(set))
#define FD_SET(fd, set) __FD_SET_chk(fd, set, __bos(set))
#define FD_ISSET(fd, set) __FD_ISSET_chk(fd, set, __bos(set))
@@ -69,7 +69,7 @@
#define FD_CLR(fd, set) (__FDS_BITS(set)[__FDELT(fd)] &= ~__FDMASK(fd))
#define FD_SET(fd, set) (__FDS_BITS(set)[__FDELT(fd)] |= __FDMASK(fd))
#define FD_ISSET(fd, set) ((__FDS_BITS(set)[__FDELT(fd)] & __FDMASK(fd)) != 0)
-#endif /* defined(__BIONIC_FORTIFY) */
+#endif /* defined(__BIONIC_FORTIFY) && __ANDROID_API >= 21 */
int select(int, fd_set*, fd_set*, fd_set*, struct timeval*);
int pselect(int, fd_set*, fd_set*, fd_set*, const struct timespec*, const sigset_t*);
diff --git a/libc/include/sys/socket.h b/libc/include/sys/socket.h
index 910fee1..03dc849 100644
--- a/libc/include/sys/socket.h
+++ b/libc/include/sys/socket.h
@@ -114,7 +114,22 @@
? (struct cmsghdr*) (msg)->msg_control : (struct cmsghdr*) NULL)
#define CMSG_OK(mhdr, cmsg) ((cmsg)->cmsg_len >= sizeof(struct cmsghdr) && (cmsg)->cmsg_len <= (unsigned long) ((mhdr)->msg_controllen - ((char*)(cmsg) - (char*)(mhdr)->msg_control)))
+#if __ANDROID_API__ >= 21
struct cmsghdr* __cmsg_nxthdr(struct msghdr*, struct cmsghdr*) __INTRODUCED_IN(21);
+#else
+/* TODO(danalbert): Move this into libandroid_support. */
+static inline struct cmsghdr* __cmsg_nxthdr(struct msghdr* msg, struct cmsghdr* cmsg) {
+ struct cmsghdr* ptr =
+ __BIONIC_CAST(reinterpret_cast, struct cmsghdr*,
+ (__BIONIC_CAST(reinterpret_cast, char*, cmsg) + CMSG_ALIGN(cmsg->cmsg_len)));
+ size_t len = __BIONIC_CAST(reinterpret_cast, char*, ptr + 1) -
+ __BIONIC_CAST(reinterpret_cast, char*, msg->msg_control);
+ if (len > msg->msg_controllen) {
+ return NULL;
+ }
+ return ptr;
+}
+#endif /* __ANDROID_API__ >= 21 */
#define SCM_RIGHTS 0x01
#define SCM_CREDENTIALS 0x02
diff --git a/libc/include/unistd.h b/libc/include/unistd.h
index ac7d4c2..ab8108a 100644
--- a/libc/include/unistd.h
+++ b/libc/include/unistd.h
@@ -489,6 +489,7 @@
}
#endif /* __ANDROID_API__ >= 24 */
+#if __ANDROID_API__ >= 23
__BIONIC_FORTIFY_INLINE
ssize_t readlink(const char* path, char* buf, size_t size) {
size_t bos = __bos(buf);
@@ -538,6 +539,7 @@
return __readlinkat_chk(dirfd, path, buf, size, bos);
}
+#endif /* __ANDROID_API__ >= 23 */
#endif /* defined(__BIONIC_FORTIFY) */