Merge "Fix misc-macro-parentheses warnings in bionic."
diff --git a/libc/Android.bp b/libc/Android.bp
index 4a44fc6..ba62592 100644
--- a/libc/Android.bp
+++ b/libc/Android.bp
@@ -1373,6 +1373,7 @@
"bionic/syslog.cpp",
"bionic/sys_siglist.c",
"bionic/sys_signame.c",
+ "bionic/sys_time.cpp",
"bionic/system_properties.cpp",
"bionic/tdestroy.cpp",
"bionic/termios.cpp",
@@ -1380,7 +1381,6 @@
"bionic/tmpfile.cpp",
"bionic/umount.cpp",
"bionic/unlink.cpp",
- "bionic/utimes.cpp",
"bionic/wait.cpp",
"bionic/wchar.cpp",
"bionic/wctype.cpp",
diff --git a/libc/bionic/bionic_netlink.h b/libc/bionic/bionic_netlink.h
index 4b103f3..bc0e3f0 100644
--- a/libc/bionic/bionic_netlink.h
+++ b/libc/bionic/bionic_netlink.h
@@ -50,10 +50,4 @@
size_t size_;
};
-#if !defined(__clang__)
-// GCC gets confused by NLMSG_DATA and doesn't realize that the old-style
-// cast is from a system header and should be ignored.
-#pragma GCC diagnostic ignored "-Wold-style-cast"
-#endif
-
#endif
diff --git a/libc/bionic/utimes.cpp b/libc/bionic/sys_time.cpp
similarity index 67%
rename from libc/bionic/utimes.cpp
rename to libc/bionic/sys_time.cpp
index 0b66e6c..3d0cd87 100644
--- a/libc/bionic/utimes.cpp
+++ b/libc/bionic/sys_time.cpp
@@ -26,22 +26,40 @@
* SUCH DAMAGE.
*/
+#include <sys/time.h>
+
#include <errno.h>
#include <fcntl.h>
#include <sys/stat.h>
-#include <sys/time.h>
#include "private/bionic_time_conversions.h"
-int utimes(const char* path, const timeval tv[2]) {
+static int futimesat(int fd, const char* path, const timeval tv[2], int flags) {
timespec ts[2];
- timespec* ts_ptr = NULL;
- if (tv != NULL) {
- if (!timespec_from_timeval(ts[0], tv[0]) || !timespec_from_timeval(ts[1], tv[1])) {
- errno = EINVAL;
- return -1;
- }
- ts_ptr = ts;
+ if (tv && (!timespec_from_timeval(ts[0], tv[0]) || !timespec_from_timeval(ts[1], tv[1]))) {
+ errno = EINVAL;
+ return -1;
}
- return utimensat(AT_FDCWD, path, ts_ptr, 0);
+ return utimensat(fd, path, tv ? ts : nullptr, flags);
+}
+
+int utimes(const char* path, const timeval tv[2]) {
+ return futimesat(AT_FDCWD, path, tv, 0);
+}
+
+int lutimes(const char* path, const timeval tv[2]) {
+ return futimesat(AT_FDCWD, path, tv, AT_SYMLINK_NOFOLLOW);
+}
+
+int futimesat(int fd, const char* path, const timeval tv[2]) {
+ return futimesat(fd, path, tv, 0);
+}
+
+int futimes(int fd, const timeval tv[2]) {
+ timespec ts[2];
+ if (tv && (!timespec_from_timeval(ts[0], tv[0]) || !timespec_from_timeval(ts[1], tv[1]))) {
+ errno = EINVAL;
+ return -1;
+ }
+ return futimens(fd, tv ? ts : nullptr);
}
diff --git a/libc/include/android/set_abort_message.h b/libc/include/android/set_abort_message.h
index aebedba..18881a3 100644
--- a/libc/include/android/set_abort_message.h
+++ b/libc/include/android/set_abort_message.h
@@ -37,4 +37,4 @@
__END_DECLS
-#endif // _SET_ABORT_MESSAGE_H
+#endif
diff --git a/libc/include/assert.h b/libc/include/assert.h
index 361a5ff..dea8382 100644
--- a/libc/include/assert.h
+++ b/libc/include/assert.h
@@ -52,14 +52,18 @@
# define _assert(e) ((void)0)
#else
# define _assert(e) assert(e)
-# if __ISO_C_VISIBLE >= 1999
+# if __STDC_VERSION__ >= 199901L
# define assert(e) ((e) ? (void)0 : __assert2(__FILE__, __LINE__, __func__, #e))
# else
# define assert(e) ((e) ? (void)0 : __assert(__FILE__, __LINE__, #e))
# endif
#endif
+#if !defined(__cplusplus) && __STDC_VERSION__ >= 201112L
+#define static_assert _Static_assert
+#endif
+
__BEGIN_DECLS
-__dead void __assert(const char *, int, const char *) __noreturn;
-__dead void __assert2(const char *, int, const char *, const char *) __noreturn;
+void __assert(const char*, int, const char*) __noreturn;
+void __assert2(const char*, int, const char*, const char*) __noreturn;
__END_DECLS
diff --git a/libc/include/complex.h b/libc/include/complex.h
index 66ea97e..e874e1c 100644
--- a/libc/include/complex.h
+++ b/libc/include/complex.h
@@ -43,7 +43,7 @@
#define complex _Complex
#define I _Complex_I
-#if __ISO_C_VISIBLE >= 2011
+#if __STDC_VERSION__ >= 201112L
#ifdef __clang__
#define CMPLX(x, y) ((double complex){ x, y })
#define CMPLXF(x, y) ((float complex){ x, y })
@@ -53,7 +53,7 @@
#define CMPLXF(x, y) __builtin_complex((float)(x), (float)(y))
#define CMPLXL(x, y) __builtin_complex((long double)(x), (long double)(y))
#endif
-#endif /* __ISO_C_VISIBLE >= 2011 */
+#endif
__BEGIN_DECLS
#pragma GCC visibility push(default)
diff --git a/libc/include/ctype.h b/libc/include/ctype.h
index 199f810..302a88e 100644
--- a/libc/include/ctype.h
+++ b/libc/include/ctype.h
@@ -56,11 +56,11 @@
__BEGIN_DECLS
-extern const char *_ctype_;
+extern const char* _ctype_;
-#if defined(__GNUC__) || defined(_ANSI_LIBRARY) || defined(lint)
int isalnum(int);
int isalpha(int);
+int isblank(int);
int iscntrl(int);
int isdigit(int);
int isgraph(int);
@@ -87,20 +87,10 @@
int isxdigit_l(int, locale_t) __INTRODUCED_IN(21);
int tolower_l(int, locale_t) __INTRODUCED_IN(21);
int toupper_l(int, locale_t) __INTRODUCED_IN(21);
-
-#if __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 || __POSIX_VISIBLE > 200112 \
- || __XPG_VISIBLE > 600
-int isblank(int);
-#endif
-
-#if __BSD_VISIBLE || __XPG_VISIBLE
int isascii(int);
int toascii(int);
int _tolower(int) __INTRODUCED_IN(21);
int _toupper(int) __INTRODUCED_IN(21);
-#endif /* __BSD_VISIBLE || __XPG_VISIBLE */
-
-#endif /* __GNUC__ || _ANSI_LIBRARY || lint */
__END_DECLS
diff --git a/libc/include/fcntl.h b/libc/include/fcntl.h
index ee4d5e2..4aa2ea0 100644
--- a/libc/include/fcntl.h
+++ b/libc/include/fcntl.h
@@ -106,12 +106,12 @@
int open(const char* pathname, int flags, ...) {
if (__builtin_constant_p(flags)) {
if ((flags & O_CREAT) && __builtin_va_arg_pack_len() == 0) {
- __creat_missing_mode(); // compile time error
+ __creat_missing_mode(); /* Compile time error. */
}
}
if (__builtin_va_arg_pack_len() > 1) {
- __creat_too_many_args(); // compile time error
+ __creat_too_many_args(); /* Compile time error. */
}
if ((__builtin_va_arg_pack_len() == 0) && !__builtin_constant_p(flags)) {
@@ -125,12 +125,12 @@
int openat(int dirfd, const char* pathname, int flags, ...) {
if (__builtin_constant_p(flags)) {
if ((flags & O_CREAT) && __builtin_va_arg_pack_len() == 0) {
- __creat_missing_mode(); // compile time error
+ __creat_missing_mode(); /* Compile time error. */
}
}
if (__builtin_va_arg_pack_len() > 1) {
- __creat_too_many_args(); // compile time error
+ __creat_too_many_args(); /* Compile time error. */
}
if ((__builtin_va_arg_pack_len() == 0) && !__builtin_constant_p(flags)) {
diff --git a/libc/include/grp.h b/libc/include/grp.h
index 373ca8f..498d1b8 100644
--- a/libc/include/grp.h
+++ b/libc/include/grp.h
@@ -47,20 +47,18 @@
__BEGIN_DECLS
struct group* getgrgid(gid_t);
-struct group* getgrnam(const char *);
-#if __POSIX_VISIBLE >= 200112 || __XPG_VISIBLE
-/* Android has thousands and thousands of ids to iterate through */
+struct group* getgrnam(const char*);
+
+/* Android has thousands and thousands of ids to iterate through. */
struct group* getgrent(void)
__attribute__((warning("getgrent is inefficient on Android"))) __INTRODUCED_IN_FUTURE;
+
void setgrent(void) __INTRODUCED_IN_FUTURE;
void endgrent(void) __INTRODUCED_IN_FUTURE;
int getgrgid_r(gid_t, struct group*, char*, size_t, struct group**) __INTRODUCED_IN(24);
int getgrnam_r(const char*, struct group*, char*, size_t, struct group**) __INTRODUCED_IN(24);
-#endif
-
-int getgrouplist (const char *user, gid_t group, gid_t *groups, int *ngroups);
-
-int initgroups (const char *user, gid_t group);
+int getgrouplist (const char*, gid_t, gid_t*, int*);
+int initgroups (const char*, gid_t);
__END_DECLS
diff --git a/libc/include/limits.h b/libc/include/limits.h
index 01b7a49..cb86aec 100644
--- a/libc/include/limits.h
+++ b/libc/include/limits.h
@@ -37,7 +37,6 @@
#include <sys/cdefs.h>
-#if __XPG_VISIBLE
#define PASS_MAX 128 /* _PASSWORD_LEN from <pwd.h> */
#define NL_ARGMAX 9
@@ -48,7 +47,6 @@
#define NL_TEXTMAX 255
#define TMP_MAX 308915776
-#endif /* __XPG_VISIBLE */
#include <sys/limits.h>
@@ -68,12 +66,19 @@
#define ULONG_LONG_MAX ULLONG_MAX
#endif
-/* BSD compatibility definitions. */
-#if __BSD_VISIBLE
+#if defined(__USE_BSD) || defined(__BIONIC__) /* Historically bionic exposed these. */
+#if defined(__LP64__)
#define SIZE_T_MAX ULONG_MAX
-#endif /* __BSD_VISIBLE */
+#else
+#define SIZE_T_MAX UINT_MAX
+#endif
+#endif
+#if defined(__LP64__)
#define SSIZE_MAX LONG_MAX
+#else
+#define SSIZE_MAX INT_MAX
+#endif
#define MB_LEN_MAX 4
diff --git a/libc/include/math.h b/libc/include/math.h
index eae1d3b..1afef4c 100644
--- a/libc/include/math.h
+++ b/libc/include/math.h
@@ -21,11 +21,9 @@
#include <limits.h>
__BEGIN_DECLS
-#pragma GCC visibility push(default)
#define HUGE_VAL __builtin_huge_val()
-#if __ISO_C_VISIBLE >= 1999
#define FP_ILOGB0 (-INT_MAX)
#define FP_ILOGBNAN INT_MAX
@@ -78,80 +76,33 @@
typedef __double_t double_t;
typedef float __float_t;
typedef __float_t float_t;
-#endif /* __ISO_C_VISIBLE >= 1999 */
-/*
- * XOPEN/SVID
- */
-#if __BSD_VISIBLE || __XSI_VISIBLE
-#define M_E 2.7182818284590452354 /* e */
-#define M_LOG2E 1.4426950408889634074 /* log 2e */
-#define M_LOG10E 0.43429448190325182765 /* log 10e */
-#define M_LN2 0.69314718055994530942 /* log e2 */
-#define M_LN10 2.30258509299404568402 /* log e10 */
-#define M_PI 3.14159265358979323846 /* pi */
-#define M_PI_2 1.57079632679489661923 /* pi/2 */
-#define M_PI_4 0.78539816339744830962 /* pi/4 */
-#define M_1_PI 0.31830988618379067154 /* 1/pi */
-#define M_2_PI 0.63661977236758134308 /* 2/pi */
-#define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(pi) */
-#define M_SQRT2 1.41421356237309504880 /* sqrt(2) */
-#define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */
-
-#define MAXFLOAT ((float)3.40282346638528860e+38)
-extern int signgam;
-#endif /* __BSD_VISIBLE || __XSI_VISIBLE */
-
-#if __USE_GNU
-#define M_El 2.718281828459045235360287471352662498L /* e */
-#define M_LOG2El 1.442695040888963407359924681001892137L /* log 2e */
-#define M_LOG10El 0.434294481903251827651128918916605082L /* log 10e */
-#define M_LN2l 0.693147180559945309417232121458176568L /* log e2 */
-#define M_LN10l 2.302585092994045684017991454684364208L /* log e10 */
-#define M_PIl 3.141592653589793238462643383279502884L /* pi */
-#define M_PI_2l 1.570796326794896619231321691639751442L /* pi/2 */
-#define M_PI_4l 0.785398163397448309615660845819875721L /* pi/4 */
-#define M_1_PIl 0.318309886183790671537767526745028724L /* 1/pi */
-#define M_2_PIl 0.636619772367581343075535053490057448L /* 2/pi */
-#define M_2_SQRTPIl 1.128379167095512573896158903121545172L /* 2/sqrt(pi) */
-#define M_SQRT2l 1.414213562373095048801688724209698079L /* sqrt(2) */
-#define M_SQRT1_2l 0.707106781186547524400844362104849039L /* 1/sqrt(2) */
+#if defined(__USE_BSD)
+#define HUGE MAXFLOAT
#endif
-#if __BSD_VISIBLE
-#if 0
-/* Old value from 4.4BSD-Lite math.h; this is probably better. */
-#define HUGE HUGE_VAL
-#else
-#define HUGE MAXFLOAT
-#endif
-#endif /* __BSD_VISIBLE */
-
/*
* Most of these functions depend on the rounding mode and have the side
* effect of raising floating-point exceptions, so they are not declared
* as __pure2. In C99, FENV_ACCESS affects the purity of these functions.
*/
-/*
- * ANSI/POSIX
- */
-int __fpclassifyd(double) __pure2;
-int __fpclassifyf(float) __pure2;
-int __fpclassifyl(long double) __pure2;
-int __isfinitef(float) __pure2;
-int __isfinite(double) __pure2;
-int __isfinitel(long double) __pure2;
-int __isinff(float) __pure2;
-int __isinfl(long double) __pure2;
+int __fpclassifyd(double) __pure2;
+int __fpclassifyf(float) __pure2;
+int __fpclassifyl(long double) __pure2;
+int __isfinitef(float) __pure2;
+int __isfinite(double) __pure2;
+int __isfinitel(long double) __pure2;
+int __isinff(float) __pure2;
+int __isinfl(long double) __pure2;
int __isnanf(float) __pure2 __INTRODUCED_IN(21);
-int __isnanl(long double) __pure2;
-int __isnormalf(float) __pure2;
-int __isnormal(double) __pure2;
-int __isnormall(long double) __pure2;
-int __signbit(double) __pure2;
-int __signbitf(float) __pure2;
-int __signbitl(long double) __pure2;
+int __isnanl(long double) __pure2;
+int __isnormalf(float) __pure2;
+int __isnormal(double) __pure2;
+int __isnormall(long double) __pure2;
+int __signbit(double) __pure2;
+int __signbitf(float) __pure2;
+int __signbitl(long double) __pure2;
double acos(double);
double asin(double);
@@ -180,10 +131,6 @@
double floor(double);
double fmod(double, double);
-/*
- * These functions are not in C90.
- */
-#if __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 || __XSI_VISIBLE
double acosh(double);
double asinh(double);
double atanh(double);
@@ -211,28 +158,9 @@
double nextafter(double, double);
double remainder(double, double);
-double remquo(double, double, int *);
+double remquo(double, double, int*);
double rint(double);
-#endif /* __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 || __XSI_VISIBLE */
-#if __BSD_VISIBLE || __XSI_VISIBLE
-double j0(double);
-double j1(double);
-double jn(int, double);
-double y0(double);
-double y1(double);
-double yn(int, double);
-
-#if __XSI_VISIBLE <= 500 || __BSD_VISIBLE
-double gamma(double);
-#endif
-
-#if __XSI_VISIBLE <= 600 || __BSD_VISIBLE
-double scalb(double, double);
-#endif
-#endif /* __BSD_VISIBLE || __XSI_VISIBLE */
-
-#if __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999
double copysign(double, double) __pure2;
double fdim(double, double);
double fmax(double, double) __pure2;
@@ -243,32 +171,7 @@
double scalbn(double, int);
double tgamma(double);
double trunc(double);
-#endif
-/*
- * BSD math library entry points
- */
-#if __BSD_VISIBLE
-double drem(double, double);
-int finite(double) __pure2;
-int isnanf(float) __pure2;
-long double significandl(long double) __INTRODUCED_IN(21);
-
-/*
- * Reentrant version of gamma & lgamma; passes signgam back by reference
- * as the second argument; user must allocate space for signgam.
- */
-double gamma_r(double, int *);
-double lgamma_r(double, int *);
-
-/*
- * IEEE Test Vector
- */
-double significand(double);
-#endif /* __BSD_VISIBLE */
-
-/* float versions of ANSI/POSIX functions */
-#if __ISO_C_VISIBLE >= 1999
float acosf(float);
float asinf(float);
float atanf(float);
@@ -333,41 +236,7 @@
float fmaf(float, float, float);
float fmaxf(float, float) __pure2;
float fminf(float, float) __pure2;
-#endif
-/*
- * float versions of BSD math library entry points
- */
-#if __BSD_VISIBLE
-float dremf(float, float);
-int finitef(float) __pure2;
-float gammaf(float);
-float j0f(float);
-float j1f(float);
-float jnf(int, float);
-float scalbf(float, float);
-float y0f(float);
-float y1f(float);
-float ynf(int, float);
-
-/*
- * Float versions of reentrant version of gamma & lgamma; passes
- * signgam back by reference as the second argument; user must
- * allocate space for signgam.
- */
-float gammaf_r(float, int *);
-float lgammaf_r(float, int *);
-
-/*
- * float version of IEEE Test Vector
- */
-float significandf(float);
-#endif /* __BSD_VISIBLE */
-
-/*
- * long double versions of ISO/POSIX math functions
- */
-#if __ISO_C_VISIBLE >= 1999
long double acoshl(long double) __INTRODUCED_IN(21);
long double acosl(long double) __INTRODUCED_IN(21);
long double asinhl(long double) __INTRODUCED_IN(21);
@@ -376,8 +245,8 @@
long double atanhl(long double) __INTRODUCED_IN(21);
long double atanl(long double) __INTRODUCED_IN(21);
long double cbrtl(long double) __INTRODUCED_IN(21);
-long double ceill(long double);
-long double copysignl(long double, long double) __pure2;
+long double ceill(long double);
+long double copysignl(long double, long double) __pure2;
long double coshl(long double) __INTRODUCED_IN(21);
long double cosl(long double) __INTRODUCED_IN(21);
long double erfcl(long double) __INTRODUCED_IN(21);
@@ -385,39 +254,39 @@
long double exp2l(long double) __INTRODUCED_IN(21);
long double expl(long double) __INTRODUCED_IN(21);
long double expm1l(long double) __INTRODUCED_IN(21);
-long double fabsl(long double) __pure2;
-long double fdiml(long double, long double);
-long double floorl(long double);
+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 fmaxl(long double, long double) __pure2;
-long double fminl(long double, long double) __pure2;
+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 hypotl(long double, long double) __INTRODUCED_IN(21);
-int ilogbl(long double) __pure2;
-long double ldexpl(long double, int);
+int ilogbl(long double) __pure2;
+long double ldexpl(long double, int);
long double lgammal(long double) __INTRODUCED_IN(21);
long long llrintl(long double) __INTRODUCED_IN(21);
-long long llroundl(long double);
+long long llroundl(long double);
long double log10l(long double) __INTRODUCED_IN(21);
long double log1pl(long double) __INTRODUCED_IN(21);
long double log2l(long double) __INTRODUCED_IN(18);
long double logbl(long double) __INTRODUCED_IN(18);
long double logl(long double) __INTRODUCED_IN(21);
long lrintl(long double) __INTRODUCED_IN(21);
-long lroundl(long double);
+long lroundl(long double);
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);
-float nexttowardf(float, long double);
+float nexttowardf(float, long double);
long double nexttowardl(long double, long double) __INTRODUCED_IN(18);
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);
long double rintl(long double) __INTRODUCED_IN(21);
-long double roundl(long double);
+long double roundl(long double);
long double scalblnl(long double, long) __INTRODUCED_IN_X86(18);
long double scalbnl(long double, int);
long double sinhl(long double) __INTRODUCED_IN(21);
@@ -426,20 +295,76 @@
long double tanhl(long double) __INTRODUCED_IN(21);
long double tanl(long double) __INTRODUCED_IN(21);
long double tgammal(long double) __INTRODUCED_IN(21);
-long double truncl(long double);
-#endif /* __ISO_C_VISIBLE >= 1999 */
+long double truncl(long double);
-#if __BSD_VISIBLE
+#define M_E 2.7182818284590452354 /* e */
+#define M_LOG2E 1.4426950408889634074 /* log 2e */
+#define M_LOG10E 0.43429448190325182765 /* log 10e */
+#define M_LN2 0.69314718055994530942 /* log e2 */
+#define M_LN10 2.30258509299404568402 /* log e10 */
+#define M_PI 3.14159265358979323846 /* pi */
+#define M_PI_2 1.57079632679489661923 /* pi/2 */
+#define M_PI_4 0.78539816339744830962 /* pi/4 */
+#define M_1_PI 0.31830988618379067154 /* 1/pi */
+#define M_2_PI 0.63661977236758134308 /* 2/pi */
+#define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(pi) */
+#define M_SQRT2 1.41421356237309504880 /* sqrt(2) */
+#define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */
+
+#define MAXFLOAT ((float)3.40282346638528860e+38)
+
+#if defined(__USE_BSD) || defined(__USE_GNU)
+extern int signgam;
+double j0(double);
+double j1(double);
+double jn(int, double);
+double y0(double);
+double y1(double);
+double yn(int, double);
+double gamma(double);
+double scalb(double, double);
+double drem(double, double);
+int finite(double) __pure2;
+int isnanf(float) __pure2;
+double gamma_r(double, int*);
+double lgamma_r(double, int*);
+double significand(double);
long double lgammal_r(long double, int*) __INTRODUCED_IN(23);
+long double significandl(long double) __INTRODUCED_IN(21);
+float dremf(float, float);
+int finitef(float) __pure2;
+float gammaf(float);
+float j0f(float);
+float j1f(float);
+float jnf(int, float);
+float scalbf(float, float);
+float y0f(float);
+float y1f(float);
+float ynf(int, float);
+float gammaf_r(float, int *);
+float lgammaf_r(float, int *);
+float significandf(float);
#endif
#if defined(__USE_GNU)
+#define M_El 2.718281828459045235360287471352662498L /* e */
+#define M_LOG2El 1.442695040888963407359924681001892137L /* log 2e */
+#define M_LOG10El 0.434294481903251827651128918916605082L /* log 10e */
+#define M_LN2l 0.693147180559945309417232121458176568L /* log e2 */
+#define M_LN10l 2.302585092994045684017991454684364208L /* log e10 */
+#define M_PIl 3.141592653589793238462643383279502884L /* pi */
+#define M_PI_2l 1.570796326794896619231321691639751442L /* pi/2 */
+#define M_PI_4l 0.785398163397448309615660845819875721L /* pi/4 */
+#define M_1_PIl 0.318309886183790671537767526745028724L /* 1/pi */
+#define M_2_PIl 0.636619772367581343075535053490057448L /* 2/pi */
+#define M_2_SQRTPIl 1.128379167095512573896158903121545172L /* 2/sqrt(pi) */
+#define M_SQRT2l 1.414213562373095048801688724209698079L /* sqrt(2) */
+#define M_SQRT1_2l 0.707106781186547524400844362104849039L /* 1/sqrt(2) */
void sincos(double, double*, double*);
void sincosf(float, float*, float*);
void sincosl(long double, long double*, long double*);
-#endif /* __USE_GNU */
+#endif
-#pragma GCC visibility pop
__END_DECLS
#endif /* !_MATH_H_ */
diff --git a/libc/include/paths.h b/libc/include/paths.h
index 1392cf0..ffb1737 100644
--- a/libc/include/paths.h
+++ b/libc/include/paths.h
@@ -34,7 +34,7 @@
#define _PATH_BSHELL "/system/bin/sh"
#define _PATH_CONSOLE "/dev/console"
-#define _PATH_DEFPATH "/sbin:/vendor/bin:/system/sbin:/system/bin:/system/xbin:/vendor/xbin"
+#define _PATH_DEFPATH "/sbin:/system/sbin:/system/bin:/system/xbin:/vendor/bin:/vendor/xbin"
#define _PATH_DEV "/dev/"
#define _PATH_DEVNULL "/dev/null"
#define _PATH_KLOG "/proc/kmsg"
diff --git a/libc/include/pwd.h b/libc/include/pwd.h
index e881129..0b39a78 100644
--- a/libc/include/pwd.h
+++ b/libc/include/pwd.h
@@ -105,7 +105,7 @@
#ifdef __LP64__
char* pw_gecos;
#else
- // Note: On LP32, we define pw_gecos to pw_passwd since they're both NULL.
+ /* Note: On LP32, we define pw_gecos to pw_passwd since they're both NULL. */
# define pw_gecos pw_passwd
#endif
char* pw_dir;
diff --git a/libc/include/stdio.h b/libc/include/stdio.h
index 83ffc20..ef660d8 100644
--- a/libc/include/stdio.h
+++ b/libc/include/stdio.h
@@ -88,10 +88,6 @@
#define FOPEN_MAX 20 /* must be <= OPEN_MAX <sys/syslimits.h> */
#define FILENAME_MAX 1024 /* must be <= PATH_MAX <sys/syslimits.h> */
-/* System V/ANSI C; this is the wrong way to do this, do *not* use these. */
-#if __BSD_VISIBLE || __XPG_VISIBLE
-#define P_tmpdir "/tmp/"
-#endif
#define L_tmpnam 1024 /* XXX must be == PATH_MAX */
#define TMP_MAX 308915776
@@ -145,8 +141,7 @@
int dprintf(int, const char* __restrict, ...) __printflike(2, 3) __INTRODUCED_IN(21);
int vdprintf(int, const char* __restrict, __va_list) __printflike(2, 0) __INTRODUCED_IN(21);
-#ifndef __AUDIT__
-#if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 201112L
+#if __STDC_VERSION__ < 201112L
char* gets(char*) __attribute__((deprecated("gets is unsafe, use fgets instead")));
#endif
int sprintf(char* __restrict, const char* __restrict, ...)
@@ -154,11 +149,11 @@
int vsprintf(char* __restrict, const char* __restrict, __va_list)
__printflike(2, 0) __warnattr("vsprintf is often misused; please use vsnprintf");
char* tmpnam(char*) __attribute__((deprecated("tmpnam is unsafe, use mkstemp or tmpfile instead")));
-#if __XPG_VISIBLE
+#if defined(__USE_BSD) || defined(__USE_GNU)
+#define P_tmpdir "/tmp/" /* deprecated */
char* tempnam(const char*, const char*)
__attribute__((deprecated("tempnam is unsafe, use mkstemp or tmpfile instead")));
#endif
-#endif
int rename(const char*, const char*);
int renameat(int, const char*, int, const char*);
@@ -208,77 +203,44 @@
FILE* tmpfile(void);
FILE* tmpfile64(void) __INTRODUCED_IN(24);
-#if __ISO_C_VISIBLE >= 1999 || __BSD_VISIBLE
-int snprintf(char * __restrict, size_t, const char * __restrict, ...)
- __printflike(3, 4);
-int vfscanf(FILE * __restrict, const char * __restrict, __va_list)
- __scanflike(2, 0);
-int vscanf(const char *, __va_list)
- __scanflike(1, 0);
-int vsnprintf(char * __restrict, size_t, const char * __restrict, __va_list)
- __printflike(3, 0);
-int vsscanf(const char * __restrict, const char * __restrict, __va_list)
- __scanflike(2, 0);
-#endif /* __ISO_C_VISIBLE >= 1999 || __BSD_VISIBLE */
+int snprintf(char* __restrict, size_t, const char* __restrict, ...) __printflike(3, 4);
+int vfscanf(FILE* __restrict, const char* __restrict, __va_list) __scanflike(2, 0);
+int vscanf(const char*, __va_list) __scanflike(1, 0);
+int vsnprintf(char* __restrict, size_t, const char* __restrict, __va_list) __printflike(3, 0);
+int vsscanf(const char* __restrict, const char* __restrict, __va_list) __scanflike(2, 0);
-/*
- * Functions defined in POSIX 1003.1.
- */
-#if __BSD_VISIBLE || __POSIX_VISIBLE || __XPG_VISIBLE
-#define L_ctermid 1024 /* size for ctermid(); PATH_MAX */
+#define L_ctermid 1024 /* size for ctermid() */
+char* ctermid(char*) __INTRODUCED_IN_FUTURE;
-FILE *fdopen(int, const char *);
-int fileno(FILE *);
+FILE* fdopen(int, const char*);
+int fileno(FILE*);
+int pclose(FILE*);
+FILE* popen(const char*, const char*);
+void flockfile(FILE*);
+int ftrylockfile(FILE*);
+void funlockfile(FILE*);
+int getc_unlocked(FILE*);
+int getchar_unlocked(void);
+int putc_unlocked(int, FILE*);
+int putchar_unlocked(int);
-#if (__POSIX_VISIBLE >= 199209)
-int pclose(FILE *);
-FILE *popen(const char *, const char *);
-#endif
-
-#if __POSIX_VISIBLE >= 199506
-void flockfile(FILE *);
-int ftrylockfile(FILE *);
-void funlockfile(FILE *);
-
-/*
- * These are normally used through macros as defined below, but POSIX
- * requires functions as well.
- */
-int getc_unlocked(FILE *);
-int getchar_unlocked(void);
-int putc_unlocked(int, FILE *);
-int putchar_unlocked(int);
-#endif /* __POSIX_VISIBLE >= 199506 */
-
-#if __POSIX_VISIBLE >= 200809
FILE* fmemopen(void*, size_t, const char*) __INTRODUCED_IN(23);
FILE* open_memstream(char**, size_t*) __INTRODUCED_IN(23);
-#endif /* __POSIX_VISIBLE >= 200809 */
-#endif /* __BSD_VISIBLE || __POSIX_VISIBLE || __XPG_VISIBLE */
-
-/*
- * Routines that are purely local.
- */
-#if __BSD_VISIBLE
-int asprintf(char ** __restrict, const char * __restrict, ...)
- __printflike(2, 3);
-char *fgetln(FILE * __restrict, size_t * __restrict);
-int fpurge(FILE *);
-void setbuffer(FILE *, char *, int);
-int setlinebuf(FILE *);
-int vasprintf(char ** __restrict, const char * __restrict,
- __va_list)
- __printflike(2, 0);
-
+#if defined(__USE_BSD) || defined(__BIONIC__) /* Historically bionic exposed these. */
+int asprintf(char** __restrict, const char* __restrict, ...) __printflike(2, 3);
+char* fgetln(FILE* __restrict, size_t* __restrict);
+int fpurge(FILE*);
+void setbuffer(FILE*, char*, int);
+int setlinebuf(FILE*);
+int vasprintf(char** __restrict, const char* __restrict, __va_list) __printflike(2, 0);
void clearerr_unlocked(FILE*) __INTRODUCED_IN(23);
int feof_unlocked(FILE*) __INTRODUCED_IN(23);
int ferror_unlocked(FILE*) __INTRODUCED_IN(23);
int fileno_unlocked(FILE*) __INTRODUCED_IN(24);
-
#define fropen(cookie, fn) funopen(cookie, fn, 0, 0, 0)
#define fwopen(cookie, fn) funopen(cookie, 0, fn, 0, 0)
-#endif /* __BSD_VISIBLE */
+#endif /* __USE_BSD */
extern char* __fgets_chk(char*, int, FILE*, size_t) __INTRODUCED_IN(17);
extern char* __fgets_real(char*, int, FILE*) __RENAME(fgets);
diff --git a/libc/include/stdlib.h b/libc/include/stdlib.h
index b3e52d5..ffbce10 100644
--- a/libc/include/stdlib.h
+++ b/libc/include/stdlib.h
@@ -46,10 +46,8 @@
extern __noreturn void _Exit(int) __INTRODUCED_IN(21);
extern int atexit(void (*)(void));
-#if __ISO_C_VISIBLE >= 2011 || __cplusplus >= 201103L
-int at_quick_exit(void (*)(void));
-void quick_exit(int) __noreturn;
-#endif
+int at_quick_exit(void (*)(void)) __INTRODUCED_IN(21);
+void quick_exit(int) __noreturn __INTRODUCED_IN(21);
extern char* getenv(const char*);
extern int putenv(char*);
diff --git a/libc/include/sys/cdefs.h b/libc/include/sys/cdefs.h
index 120c29d..8cde1c7 100644
--- a/libc/include/sys/cdefs.h
+++ b/libc/include/sys/cdefs.h
@@ -162,20 +162,6 @@
#define __scanflike(x, y) __attribute__((__format__(scanf, x, y))) __nonnull((x))
/*
- * C99 defines the restrict type qualifier keyword.
- */
-#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
-#define __restrict restrict
-#endif
-
-/*
- * C99 defines the __func__ predefined identifier.
- */
-#if !defined(__STDC_VERSION__) || !(__STDC_VERSION__ >= 199901L)
-#define __func__ __PRETTY_FUNCTION__
-#endif
-
-/*
* GNU C version 2.96 added explicit branch prediction so that
* the CPU back-end can hint the processor and also so that
* code blocks can be reordered such that the predicted path
@@ -230,151 +216,44 @@
#define __SCCSID(_s) /* nothing */
/*
- * _BSD_SOURCE and _GNU_SOURCE are expected to be defined by callers before
- * any standard header file is included. In those header files we test
- * against __USE_BSD and __USE_GNU. glibc does this in <features.h> but we
- * do it in <sys/cdefs.h> instead because that's where our existing
- * _POSIX_C_SOURCE tests were, and we're already confident that <sys/cdefs.h>
- * is included everywhere it should be.
+ * With bionic, you always get all C and POSIX API.
*
- * The _GNU_SOURCE test needs to come before any _BSD_SOURCE or _POSIX* tests
- * because _GNU_SOURCE implies everything else.
+ * If you want BSD and/or GNU extensions, _BSD_SOURCE and/or _GNU_SOURCE are
+ * expected to be defined by callers before *any* standard header file is
+ * included.
+ *
+ * In our header files we test against __USE_BSD and __USE_GNU.
*/
#if defined(_GNU_SOURCE)
+# define __USE_BSD 1
# define __USE_GNU 1
-# undef _POSIX_SOURCE
-# define _POSIX_SOURCE 1
-# undef _POSIX_C_SOURCE
-# define _POSIX_C_SOURCE 200809L
-# undef _BSD_SOURCE
-# define _BSD_SOURCE 1
#endif
#if defined(_BSD_SOURCE)
# define __USE_BSD 1
#endif
-/*
- * _FILE_OFFSET_BITS 64 support.
- */
+/* _FILE_OFFSET_BITS 64 support. */
#if !defined(__LP64__) && defined(_FILE_OFFSET_BITS)
#if _FILE_OFFSET_BITS == 64
#define __USE_FILE_OFFSET64 1
#endif
#endif
-/*-
- * POSIX.1 requires that the macros we test be defined before any standard
- * header file is included.
- *
- * Here's a quick run-down of the versions:
- * defined(_POSIX_SOURCE) 1003.1-1988
- * _POSIX_C_SOURCE == 1 1003.1-1990
- * _POSIX_C_SOURCE == 2 1003.2-1992 C Language Binding Option
- * _POSIX_C_SOURCE == 199309 1003.1b-1993
- * _POSIX_C_SOURCE == 199506 1003.1c-1995, 1003.1i-1995,
- * and the omnibus ISO/IEC 9945-1: 1996
- * _POSIX_C_SOURCE == 200112 1003.1-2001
- * _POSIX_C_SOURCE == 200809 1003.1-2008
- *
- * In addition, the X/Open Portability Guide, which is now the Single UNIX
- * Specification, defines a feature-test macro which indicates the version of
- * that specification, and which subsumes _POSIX_C_SOURCE.
- *
- * Our macros begin with two underscores to avoid namespace screwage.
- */
-
-/* Deal with IEEE Std. 1003.1-1990, in which _POSIX_C_SOURCE == 1. */
-#if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE == 1
-#undef _POSIX_C_SOURCE /* Probably illegal, but beyond caring now. */
-#define _POSIX_C_SOURCE 199009
+/* C99 added the `restrict` type qualifier keyword. Before then, `__restrict` is a GNU extension. */
+#if __STDC_VERSION__ >= 199901L
+#define __restrict restrict
#endif
-/* Deal with IEEE Std. 1003.2-1992, in which _POSIX_C_SOURCE == 2. */
-#if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE == 2
-#undef _POSIX_C_SOURCE
-#define _POSIX_C_SOURCE 199209
-#endif
-
-/* Deal with various X/Open Portability Guides and Single UNIX Spec. */
-#ifdef _XOPEN_SOURCE
-#if _XOPEN_SOURCE - 0 >= 700
-#define __XSI_VISIBLE 700
-#undef _POSIX_C_SOURCE
-#define _POSIX_C_SOURCE 200809
-#elif _XOPEN_SOURCE - 0 >= 600
-#define __XSI_VISIBLE 600
-#undef _POSIX_C_SOURCE
-#define _POSIX_C_SOURCE 200112
-#elif _XOPEN_SOURCE - 0 >= 500
-#define __XSI_VISIBLE 500
-#undef _POSIX_C_SOURCE
-#define _POSIX_C_SOURCE 199506
-#endif
-#endif
-
-/*
- * Deal with all versions of POSIX. The ordering relative to the tests above is
- * important.
- */
-#if defined(_POSIX_SOURCE) && !defined(_POSIX_C_SOURCE)
-#define _POSIX_C_SOURCE 198808
-#endif
-#ifdef _POSIX_C_SOURCE
-#if _POSIX_C_SOURCE >= 200809
-#define __POSIX_VISIBLE 200809
-#define __ISO_C_VISIBLE 1999
-#elif _POSIX_C_SOURCE >= 200112
-#define __POSIX_VISIBLE 200112
-#define __ISO_C_VISIBLE 1999
-#elif _POSIX_C_SOURCE >= 199506
-#define __POSIX_VISIBLE 199506
-#define __ISO_C_VISIBLE 1990
-#elif _POSIX_C_SOURCE >= 199309
-#define __POSIX_VISIBLE 199309
-#define __ISO_C_VISIBLE 1990
-#elif _POSIX_C_SOURCE >= 199209
-#define __POSIX_VISIBLE 199209
-#define __ISO_C_VISIBLE 1990
-#elif _POSIX_C_SOURCE >= 199009
-#define __POSIX_VISIBLE 199009
-#define __ISO_C_VISIBLE 1990
-#else
-#define __POSIX_VISIBLE 198808
-#define __ISO_C_VISIBLE 0
-#endif /* _POSIX_C_SOURCE */
-#else /* Default environment: show everything. */
-#define __POSIX_VISIBLE 200809
-#define __XSI_VISIBLE 700
-#define __BSD_VISIBLE 1
-#define __ISO_C_VISIBLE 1999
-#endif
-
-/*
- * Default values.
- */
-#ifndef __XPG_VISIBLE
-# define __XPG_VISIBLE 700
-#endif
-#ifndef __POSIX_VISIBLE
-# define __POSIX_VISIBLE 200809
-#endif
-#ifndef __ISO_C_VISIBLE
-# define __ISO_C_VISIBLE 1999
-#endif
-#ifndef __BSD_VISIBLE
-# define __BSD_VISIBLE 1
+/* C99 added the `__func__` predefined identifier. */
+#if __STDC_VERSION__ < 199901L
+#define __func__ __PRETTY_FUNCTION__
#endif
#define __BIONIC__ 1
#include <android/api-level.h>
/* glibc compatibility. */
-#if __POSIX_VISIBLE >= 200809
-#define __USE_ISOC99 1
-#define __USE_XOPEN2K 1
-#define __USE_XOPEN2K8 1
-#endif
#if __LP64__
#define __WORDSIZE 64
#else
@@ -427,7 +306,7 @@
#define __AVAILABILITY(...) __attribute__((availability(android,__VA_ARGS__)))
#else
#define __AVAILABILITY(...)
-#endif // __clang__
+#endif
#define __INTRODUCED_IN(api_level) __AVAILABILITY(introduced=api_level)
#define __DEPRECATED_IN(api_level) __AVAILABILITY(deprecated=api_level)
diff --git a/libc/include/sys/endian.h b/libc/include/sys/endian.h
index 449e0d7..b9e4758 100644
--- a/libc/include/sys/endian.h
+++ b/libc/include/sys/endian.h
@@ -64,7 +64,7 @@
#define htonq(x) __swap64(x)
#define ntohq(x) __swap64(x)
-#if __BSD_VISIBLE
+#if defined(__USE_BSD) || defined(__BIONIC__) /* Historically bionic exposed these. */
#define LITTLE_ENDIAN _LITTLE_ENDIAN
#define BIG_ENDIAN _BIG_ENDIAN
#define PDP_ENDIAN _PDP_ENDIAN
@@ -101,6 +101,6 @@
#define le16toh(x) htole16(x)
#define le32toh(x) htole32(x)
#define le64toh(x) htole64(x)
-#endif /* __BSD_VISIBLE */
+#endif /* __USE_BSD */
#endif /* _SYS_ENDIAN_H_ */
diff --git a/libc/include/sys/limits.h b/libc/include/sys/limits.h
index f84253e..5aa3d80 100644
--- a/libc/include/sys/limits.h
+++ b/libc/include/sys/limits.h
@@ -66,16 +66,14 @@
# define LONG_MIN (-0x7fffffffL-1)/* min value for a long */
#endif
-#if __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999
# define ULLONG_MAX 0xffffffffffffffffULL
/* max value for unsigned long long */
# define LLONG_MAX 0x7fffffffffffffffLL
/* max value for a signed long long */
# define LLONG_MIN (-0x7fffffffffffffffLL-1)
/* min value for a signed long long */
-#endif
-#if __BSD_VISIBLE
+#if defined(__USE_BSD) || defined(__BIONIC__) /* Historically bionic exposed these. */
# define UID_MAX UINT_MAX /* max value for a uid_t */
# define GID_MAX UINT_MAX /* max value for a gid_t */
#endif
diff --git a/libc/include/sys/stat.h b/libc/include/sys/stat.h
index f26a492..0a999e4 100644
--- a/libc/include/sys/stat.h
+++ b/libc/include/sys/stat.h
@@ -128,7 +128,7 @@
#define st_mtimensec st_mtim.tv_nsec
#define st_ctimensec st_ctim.tv_nsec
-#ifdef __USE_BSD
+#if defined(__USE_BSD)
/* Permission macros provided by glibc for compatibility with BSDs. */
#define ACCESSPERMS (S_IRWXU | S_IRWXG | S_IRWXO) /* 0777 */
#define ALLPERMS (S_ISUID | S_ISGID | S_ISVTX | S_IRWXU | S_IRWXG | S_IRWXO) /* 07777 */
diff --git a/libc/include/sys/time.h b/libc/include/sys/time.h
index f60c905..ad5844a 100644
--- a/libc/include/sys/time.h
+++ b/libc/include/sys/time.h
@@ -38,13 +38,22 @@
__BEGIN_DECLS
-extern int gettimeofday(struct timeval *, struct timezone *);
-extern int settimeofday(const struct timeval *, const struct timezone *);
+int gettimeofday(struct timeval*, struct timezone*);
+int settimeofday(const struct timeval*, const struct timezone*);
-extern int getitimer(int, struct itimerval *);
-extern int setitimer(int, const struct itimerval *, struct itimerval *);
+int getitimer(int, struct itimerval*);
+int setitimer(int, const struct itimerval*, struct itimerval*);
-extern int utimes(const char *, const struct timeval *);
+int utimes(const char*, const struct timeval*);
+
+#if defined(__USE_BSD)
+int futimes(int, const struct timeval[2]) __INTRODUCED_IN_FUTURE;
+int lutimes(const char*, const struct timeval[2]) __INTRODUCED_IN_FUTURE;
+#endif
+
+#if defined(__USE_GNU)
+int futimesat(int, const char*, const struct timeval[2]) __INTRODUCED_IN_FUTURE;
+#endif
#define timerclear(a) \
((a)->tv_sec = (a)->tv_usec = 0)
diff --git a/libc/include/sys/types.h b/libc/include/sys/types.h
index a422261..2895057 100644
--- a/libc/include/sys/types.h
+++ b/libc/include/sys/types.h
@@ -141,7 +141,7 @@
typedef unsigned int uint_t;
typedef unsigned int uint;
-#ifdef __BSD_VISIBLE
+#if defined(__USE_BSD) || defined(__BIONIC__) /* Historically bionic exposed these. */
#include <sys/sysmacros.h>
typedef unsigned char u_char;
diff --git a/libc/include/sys/ucontext.h b/libc/include/sys/ucontext.h
index 9e3c653..f252a37 100644
--- a/libc/include/sys/ucontext.h
+++ b/libc/include/sys/ucontext.h
@@ -70,9 +70,9 @@
stack_t uc_stack;
mcontext_t uc_mcontext;
sigset_t uc_sigmask;
- // Android has a wrong (smaller) sigset_t on ARM.
+ /* Android has a wrong (smaller) sigset_t on ARM. */
uint32_t __padding_rt_sigset;
- // The kernel adds extra padding after uc_sigmask to match glibc sigset_t on ARM.
+ /* The kernel adds extra padding after uc_sigmask to match glibc sigset_t on ARM. */
char __padding[120];
unsigned long uc_regspace[128] __attribute__((__aligned__(8)));
} ucontext_t;
@@ -92,7 +92,7 @@
struct ucontext *uc_link;
stack_t uc_stack;
sigset_t uc_sigmask;
- // The kernel adds extra padding after uc_sigmask to match glibc sigset_t on ARM64.
+ /* The kernel adds extra padding after uc_sigmask to match glibc sigset_t on ARM64. */
char __padding[128 - sizeof(sigset_t)];
mcontext_t uc_mcontext;
} ucontext_t;
@@ -157,7 +157,7 @@
stack_t uc_stack;
mcontext_t uc_mcontext;
sigset_t uc_sigmask;
- // Android has a wrong (smaller) sigset_t on x86.
+ /* Android has a wrong (smaller) sigset_t on x86. */
uint32_t __padding_rt_sigset;
struct _libc_fpstate __fpregs_mem;
} ucontext_t;
diff --git a/libc/include/uchar.h b/libc/include/uchar.h
index 9a0e2f8..6b995ab 100644
--- a/libc/include/uchar.h
+++ b/libc/include/uchar.h
@@ -34,7 +34,7 @@
__BEGIN_DECLS
-#if __STDC_VERSION__ >= 201112L && !defined(__cplusplus)
+#if !defined(__cplusplus)
typedef __CHAR16_TYPE__ char16_t;
typedef __CHAR32_TYPE__ char32_t;
#endif
diff --git a/libc/include/wchar.h b/libc/include/wchar.h
index 91d6f24..7a1fc07 100644
--- a/libc/include/wchar.h
+++ b/libc/include/wchar.h
@@ -150,11 +150,9 @@
extern size_t wcslcat(wchar_t*, const wchar_t*, size_t);
extern size_t wcslcpy(wchar_t*, const wchar_t*, size_t);
-#if __POSIX_VISIBLE >= 200809
FILE* open_wmemstream(wchar_t**, size_t*) __INTRODUCED_IN(23);
wchar_t* wcsdup(const wchar_t*);
size_t wcsnlen(const wchar_t*, size_t);
-#endif
__END_DECLS
diff --git a/libc/libc.arm.brillo.map b/libc/libc.arm.brillo.map
index 7833d05..9ea1d8b 100644
--- a/libc/libc.arm.brillo.map
+++ b/libc/libc.arm.brillo.map
@@ -1271,13 +1271,17 @@
catclose;
catgets;
catopen;
+ ctermid;
endgrent;
endpwent;
+ futimes;
+ futimesat;
getdomainname;
getgrent;
getpwent;
getsubopt;
hasmntopt;
+ lutimes;
mblen;
pthread_getname_np;
quotactl;
diff --git a/libc/libc.arm.map b/libc/libc.arm.map
index a1b2511..0097c25 100644
--- a/libc/libc.arm.map
+++ b/libc/libc.arm.map
@@ -1271,13 +1271,17 @@
catclose;
catgets;
catopen;
+ ctermid;
endgrent;
endpwent;
+ futimes;
+ futimesat;
getdomainname;
getgrent;
getpwent;
getsubopt;
hasmntopt;
+ lutimes;
mblen;
pthread_getname_np;
quotactl;
diff --git a/libc/libc.arm64.map b/libc/libc.arm64.map
index c853f73..cfa1838 100644
--- a/libc/libc.arm64.map
+++ b/libc/libc.arm64.map
@@ -1194,13 +1194,17 @@
catclose;
catgets;
catopen;
+ ctermid;
endgrent;
endpwent;
+ futimes;
+ futimesat;
getdomainname;
getgrent;
getpwent;
getsubopt;
hasmntopt;
+ lutimes;
mblen;
pthread_getname_np;
quotactl;
diff --git a/libc/libc.map.txt b/libc/libc.map.txt
index d893b8b..aeb39d3 100644
--- a/libc/libc.map.txt
+++ b/libc/libc.map.txt
@@ -1296,13 +1296,17 @@
catclose;
catgets;
catopen;
+ ctermid;
endgrent;
endpwent;
+ futimes;
+ futimesat;
getdomainname;
getgrent;
getpwent;
getsubopt;
hasmntopt;
+ lutimes;
mblen;
pthread_getname_np;
quotactl;
diff --git a/libc/libc.mips.brillo.map b/libc/libc.mips.brillo.map
index 56d4727..ce4d4ad 100644
--- a/libc/libc.mips.brillo.map
+++ b/libc/libc.mips.brillo.map
@@ -1255,13 +1255,17 @@
catclose;
catgets;
catopen;
+ ctermid;
endgrent;
endpwent;
+ futimes;
+ futimesat;
getdomainname;
getgrent;
getpwent;
getsubopt;
hasmntopt;
+ lutimes;
mblen;
pthread_getname_np;
quotactl;
diff --git a/libc/libc.mips.map b/libc/libc.mips.map
index 35c56cb..172a2ae 100644
--- a/libc/libc.mips.map
+++ b/libc/libc.mips.map
@@ -1255,13 +1255,17 @@
catclose;
catgets;
catopen;
+ ctermid;
endgrent;
endpwent;
+ futimes;
+ futimesat;
getdomainname;
getgrent;
getpwent;
getsubopt;
hasmntopt;
+ lutimes;
mblen;
pthread_getname_np;
quotactl;
diff --git a/libc/libc.mips64.map b/libc/libc.mips64.map
index c853f73..cfa1838 100644
--- a/libc/libc.mips64.map
+++ b/libc/libc.mips64.map
@@ -1194,13 +1194,17 @@
catclose;
catgets;
catopen;
+ ctermid;
endgrent;
endpwent;
+ futimes;
+ futimesat;
getdomainname;
getgrent;
getpwent;
getsubopt;
hasmntopt;
+ lutimes;
mblen;
pthread_getname_np;
quotactl;
diff --git a/libc/libc.x86.brillo.map b/libc/libc.x86.brillo.map
index a58d2bc..81b13d0 100644
--- a/libc/libc.x86.brillo.map
+++ b/libc/libc.x86.brillo.map
@@ -1253,13 +1253,17 @@
catclose;
catgets;
catopen;
+ ctermid;
endgrent;
endpwent;
+ futimes;
+ futimesat;
getdomainname;
getgrent;
getpwent;
getsubopt;
hasmntopt;
+ lutimes;
mblen;
pthread_getname_np;
quotactl;
diff --git a/libc/libc.x86.map b/libc/libc.x86.map
index 2fe730f..3611e14 100644
--- a/libc/libc.x86.map
+++ b/libc/libc.x86.map
@@ -1253,13 +1253,17 @@
catclose;
catgets;
catopen;
+ ctermid;
endgrent;
endpwent;
+ futimes;
+ futimesat;
getdomainname;
getgrent;
getpwent;
getsubopt;
hasmntopt;
+ lutimes;
mblen;
pthread_getname_np;
quotactl;
diff --git a/libc/libc.x86_64.map b/libc/libc.x86_64.map
index c853f73..cfa1838 100644
--- a/libc/libc.x86_64.map
+++ b/libc/libc.x86_64.map
@@ -1194,13 +1194,17 @@
catclose;
catgets;
catopen;
+ ctermid;
endgrent;
endpwent;
+ futimes;
+ futimesat;
getdomainname;
getgrent;
getpwent;
getsubopt;
hasmntopt;
+ lutimes;
mblen;
pthread_getname_np;
quotactl;
diff --git a/libc/stdio/stdio.cpp b/libc/stdio/stdio.cpp
index 5df1bb9..3aabbe2 100644
--- a/libc/stdio/stdio.cpp
+++ b/libc/stdio/stdio.cpp
@@ -36,6 +36,7 @@
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
+#include <paths.h>
#include <stdlib.h>
#include <string.h>
#include <sys/param.h>
@@ -598,3 +599,7 @@
}
return fp;
}
+
+char* ctermid(char* s) {
+ return s ? strcpy(s, _PATH_TTY) : const_cast<char*>(_PATH_TTY);
+}
diff --git a/libm/Android.bp b/libm/Android.bp
index f22050e..23b9d5e 100644
--- a/libm/Android.bp
+++ b/libm/Android.bp
@@ -1,6 +1,3 @@
-// ANDROIDMK TRANSLATION ERROR: unsupported conditional
-// ifneq ($(TARGET_USE_PRIVATE_LIBM),true)
-
bionic_coverage = false
//
@@ -513,6 +510,7 @@
cflags: [
"-D__BIONIC_NO_MATH_INLINES",
+ "-D_BSD_SOURCE",
"-DFLT_EVAL_METHOD=0",
"-include freebsd-compat.h",
"-Werror",
@@ -521,14 +519,6 @@
"-Wno-sign-compare",
"-Wno-uninitialized",
"-Wno-unknown-pragmas",
- "-fvisibility=hidden",
-
- // Workaround the GCC "(long)fn -> lfn" optimization bug which will result in
- // self recursions for lrint, lrintf, and lrintl.
- // BUG: 14225968
- "-fno-builtin-rint",
- "-fno-builtin-rintf",
- "-fno-builtin-rintl",
],
conlyflags: ["-std=gnu11"],
@@ -541,6 +531,3 @@
},
stl: "none",
}
-
-// ANDROIDMK TRANSLATION ERROR: endif from unsupported contitional
-// endif
diff --git a/linker/Android.mk b/linker/Android.mk
index c37d6db..29520f9 100644
--- a/linker/Android.mk
+++ b/linker/Android.mk
@@ -19,7 +19,6 @@
LOCAL_CLANG := true
LOCAL_SRC_FILES := \
- debugger.cpp \
dlfcn.cpp \
linker.cpp \
linker_block_allocator.cpp \
@@ -76,7 +75,14 @@
LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
-LOCAL_STATIC_LIBRARIES := libc_nomalloc libziparchive libutils libbase libz liblog
+LOCAL_STATIC_LIBRARIES := \
+ libc_nomalloc \
+ libziparchive \
+ libutils \
+ libbase \
+ libz \
+ liblog \
+ libdebuggerd_client
# Important: The liblinker_malloc should be the last library in the list
# to overwrite any other malloc implementations by other static libraries.
diff --git a/linker/debugger.cpp b/linker/debugger.cpp
deleted file mode 100644
index d4c7928..0000000
--- a/linker/debugger.cpp
+++ /dev/null
@@ -1,321 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include "linker.h"
-#include "linker_gdb_support.h"
-
-#include <errno.h>
-#include <inttypes.h>
-#include <pthread.h>
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/mman.h>
-#include <sys/prctl.h>
-#include <sys/socket.h>
-#include <sys/syscall.h>
-#include <sys/un.h>
-#include <unistd.h>
-
-extern "C" int tgkill(int tgid, int tid, int sig);
-
-// Crash actions have to be sent to the proper debuggerd.
-// On 64 bit systems, the 32 bit debuggerd is named differently.
-#if defined(TARGET_IS_64_BIT) && !defined(__LP64__)
-#define DEBUGGER_SOCKET_NAME "android:debuggerd32"
-#else
-#define DEBUGGER_SOCKET_NAME "android:debuggerd"
-#endif
-
-enum debugger_action_t {
- // dump a crash
- DEBUGGER_ACTION_CRASH,
- // dump a tombstone file
- DEBUGGER_ACTION_DUMP_TOMBSTONE,
- // dump a backtrace only back to the socket
- DEBUGGER_ACTION_DUMP_BACKTRACE,
-};
-
-// Message sent over the socket.
-// NOTE: Any changes to this structure must also be reflected in
-// system/core/include/cutils/debugger.h.
-struct __attribute__((packed)) debugger_msg_t {
- int32_t action;
- pid_t tid;
- uint64_t abort_msg_address;
- int32_t original_si_code;
-};
-
-// see man(2) prctl, specifically the section about PR_GET_NAME
-#define MAX_TASK_NAME_LEN (16)
-
-static int socket_abstract_client(const char* name, int type) {
- sockaddr_un addr;
-
- // Test with length +1 for the *initial* '\0'.
- size_t namelen = strlen(name);
- if ((namelen + 1) > sizeof(addr.sun_path)) {
- errno = EINVAL;
- return -1;
- }
-
- // This is used for abstract socket namespace, we need
- // an initial '\0' at the start of the Unix socket path.
- //
- // Note: The path in this case is *not* supposed to be
- // '\0'-terminated. ("man 7 unix" for the gory details.)
- memset(&addr, 0, sizeof(addr));
- addr.sun_family = AF_LOCAL;
- addr.sun_path[0] = 0;
- memcpy(addr.sun_path + 1, name, namelen);
-
- socklen_t alen = namelen + offsetof(sockaddr_un, sun_path) + 1;
-
- int s = socket(AF_LOCAL, type, 0);
- if (s == -1) {
- return -1;
- }
-
- int rc = TEMP_FAILURE_RETRY(connect(s, reinterpret_cast<sockaddr*>(&addr), alen));
- if (rc == -1) {
- close(s);
- return -1;
- }
-
- return s;
-}
-
-/*
- * Writes a summary of the signal to the log file. We do this so that, if
- * for some reason we're not able to contact debuggerd, there is still some
- * indication of the failure in the log.
- *
- * We could be here as a result of native heap corruption, or while a
- * mutex is being held, so we don't want to use any libc functions that
- * could allocate memory or hold a lock.
- */
-static void log_signal_summary(int signum, const siginfo_t* info) {
- const char* signal_name = "???";
- bool has_address = false;
- switch (signum) {
- case SIGABRT:
- signal_name = "SIGABRT";
- break;
- case SIGBUS:
- signal_name = "SIGBUS";
- has_address = true;
- break;
- case SIGFPE:
- signal_name = "SIGFPE";
- has_address = true;
- break;
- case SIGILL:
- signal_name = "SIGILL";
- has_address = true;
- break;
- case SIGSEGV:
- signal_name = "SIGSEGV";
- has_address = true;
- break;
-#if defined(SIGSTKFLT)
- case SIGSTKFLT:
- signal_name = "SIGSTKFLT";
- break;
-#endif
- case SIGTRAP:
- signal_name = "SIGTRAP";
- break;
- }
-
- char thread_name[MAX_TASK_NAME_LEN + 1]; // one more for termination
- if (prctl(PR_GET_NAME, reinterpret_cast<unsigned long>(thread_name), 0, 0, 0) != 0) {
- strcpy(thread_name, "<name unknown>");
- } else {
- // short names are null terminated by prctl, but the man page
- // implies that 16 byte names are not.
- thread_name[MAX_TASK_NAME_LEN] = 0;
- }
-
- // "info" will be null if the siginfo_t information was not available.
- // Many signals don't have an address or a code.
- char code_desc[32]; // ", code -6"
- char addr_desc[32]; // ", fault addr 0x1234"
- addr_desc[0] = code_desc[0] = 0;
- if (info != nullptr) {
- // For a rethrown signal, this si_code will be right and the one debuggerd shows will
- // always be SI_TKILL.
- __libc_format_buffer(code_desc, sizeof(code_desc), ", code %d", info->si_code);
- if (has_address) {
- __libc_format_buffer(addr_desc, sizeof(addr_desc), ", fault addr %p", info->si_addr);
- }
- }
- __libc_format_log(ANDROID_LOG_FATAL, "libc",
- "Fatal signal %d (%s)%s%s in tid %d (%s)",
- signum, signal_name, code_desc, addr_desc, gettid(), thread_name);
-}
-
-/*
- * Returns true if the handler for signal "signum" has SA_SIGINFO set.
- */
-static bool have_siginfo(int signum) {
- struct sigaction old_action, new_action;
-
- memset(&new_action, 0, sizeof(new_action));
- new_action.sa_handler = SIG_DFL;
- new_action.sa_flags = SA_RESTART;
- sigemptyset(&new_action.sa_mask);
-
- if (sigaction(signum, &new_action, &old_action) < 0) {
- __libc_format_log(ANDROID_LOG_WARN, "libc", "Failed testing for SA_SIGINFO: %s",
- strerror(errno));
- return false;
- }
- bool result = (old_action.sa_flags & SA_SIGINFO) != 0;
-
- if (sigaction(signum, &old_action, nullptr) == -1) {
- __libc_format_log(ANDROID_LOG_WARN, "libc", "Restore failed in test for SA_SIGINFO: %s",
- strerror(errno));
- }
- return result;
-}
-
-static void send_debuggerd_packet(siginfo_t* info) {
- // Mutex to prevent multiple crashing threads from trying to talk
- // to debuggerd at the same time.
- static pthread_mutex_t crash_mutex = PTHREAD_MUTEX_INITIALIZER;
- int ret = pthread_mutex_trylock(&crash_mutex);
- if (ret != 0) {
- if (ret == EBUSY) {
- __libc_format_log(ANDROID_LOG_INFO, "libc",
- "Another thread contacted debuggerd first; not contacting debuggerd.");
- // This will never complete since the lock is never released.
- pthread_mutex_lock(&crash_mutex);
- } else {
- __libc_format_log(ANDROID_LOG_INFO, "libc",
- "pthread_mutex_trylock failed: %s", strerror(ret));
- }
- return;
- }
-
- int s = socket_abstract_client(DEBUGGER_SOCKET_NAME, SOCK_STREAM | SOCK_CLOEXEC);
- if (s == -1) {
- __libc_format_log(ANDROID_LOG_FATAL, "libc", "Unable to open connection to debuggerd: %s",
- strerror(errno));
- return;
- }
-
- // debuggerd knows our pid from the credentials on the
- // local socket but we need to tell it the tid of the crashing thread.
- // debuggerd will be paranoid and verify that we sent a tid
- // that's actually in our process.
- debugger_msg_t msg;
- msg.action = DEBUGGER_ACTION_CRASH;
- msg.tid = gettid();
- msg.abort_msg_address = reinterpret_cast<uintptr_t>(g_abort_message);
- msg.original_si_code = (info != nullptr) ? info->si_code : 0;
- ret = TEMP_FAILURE_RETRY(write(s, &msg, sizeof(msg)));
- if (ret == sizeof(msg)) {
- char debuggerd_ack;
- ret = TEMP_FAILURE_RETRY(read(s, &debuggerd_ack, 1));
- int saved_errno = errno;
- notify_gdb_of_libraries();
- errno = saved_errno;
- } else {
- // read or write failed -- broken connection?
- __libc_format_log(ANDROID_LOG_FATAL, "libc", "Failed while talking to debuggerd: %s",
- strerror(errno));
- }
-
- close(s);
-}
-
-/*
- * Catches fatal signals so we can ask debuggerd to ptrace us before
- * we crash.
- */
-static void debuggerd_signal_handler(int signal_number, siginfo_t* info, void*) {
- // It's possible somebody cleared the SA_SIGINFO flag, which would mean
- // our "info" arg holds an undefined value.
- if (!have_siginfo(signal_number)) {
- info = nullptr;
- }
-
- log_signal_summary(signal_number, info);
-
- send_debuggerd_packet(info);
-
- // We need to return from the signal handler so that debuggerd can dump the
- // thread that crashed, but returning here does not guarantee that the signal
- // will be thrown again, even for SIGSEGV and friends, since the signal could
- // have been sent manually. Resend the signal with rt_tgsigqueueinfo(2) to
- // preserve the SA_SIGINFO contents.
- signal(signal_number, SIG_DFL);
-
- struct siginfo si;
- if (!info) {
- memset(&si, 0, sizeof(si));
- si.si_code = SI_USER;
- si.si_pid = getpid();
- si.si_uid = getuid();
- info = &si;
- } else if (info->si_code >= 0 || info->si_code == SI_TKILL) {
- // rt_tgsigqueueinfo(2)'s documentation appears to be incorrect on kernels
- // that contain commit 66dd34a (3.9+). The manpage claims to only allow
- // negative si_code values that are not SI_TKILL, but 66dd34a changed the
- // check to allow all si_code values in calls coming from inside the house.
- }
-
- int rc = syscall(SYS_rt_tgsigqueueinfo, getpid(), gettid(), signal_number, info);
- if (rc != 0) {
- __libc_format_log(ANDROID_LOG_FATAL, "libc", "failed to resend signal during crash: %s",
- strerror(errno));
- _exit(0);
- }
-}
-
-__LIBC_HIDDEN__ void debuggerd_init() {
- struct sigaction action;
- memset(&action, 0, sizeof(action));
- sigemptyset(&action.sa_mask);
- action.sa_sigaction = debuggerd_signal_handler;
- action.sa_flags = SA_RESTART | SA_SIGINFO;
-
- // Use the alternate signal stack if available so we can catch stack overflows.
- action.sa_flags |= SA_ONSTACK;
-
- sigaction(SIGABRT, &action, nullptr);
- sigaction(SIGBUS, &action, nullptr);
- sigaction(SIGFPE, &action, nullptr);
- sigaction(SIGILL, &action, nullptr);
- sigaction(SIGSEGV, &action, nullptr);
-#if defined(SIGSTKFLT)
- sigaction(SIGSTKFLT, &action, nullptr);
-#endif
- sigaction(SIGTRAP, &action, nullptr);
-}
diff --git a/linker/linker.cpp b/linker/linker.cpp
index 9eb3a65..0fe0c38 100644
--- a/linker/linker.cpp
+++ b/linker/linker.cpp
@@ -61,6 +61,7 @@
#include "linker_utils.h"
#include "android-base/strings.h"
+#include "debuggerd/client.h"
#include "ziparchive/zip_archive.h"
extern void __libc_init_globals(KernelArgumentBlock&);
@@ -2403,8 +2404,8 @@
find_loaded_library_by_soname(&g_default_namespace, soname.c_str(), &candidate);
if (candidate == nullptr) {
- DL_ERR("error initializing public namespace: \"%s\" was not found"
- " in the default namespace", soname.c_str());
+ DL_ERR("error initializing public namespace: a library with soname \"%s\""
+ " was not found in the default namespace", soname.c_str());
return false;
}
@@ -4060,7 +4061,14 @@
// Initialize system properties
__system_properties_init(); // may use 'environ'
- debuggerd_init();
+ // Register the debuggerd signal handler.
+ debuggerd_callbacks_t callbacks = {
+ .get_abort_message = []() {
+ return g_abort_message;
+ },
+ .post_dump = ¬ify_gdb_of_libraries,
+ };
+ debuggerd_init(&callbacks);
// Get a few environment variables.
const char* LD_DEBUG = getenv("LD_DEBUG");
diff --git a/linker/linker.h b/linker/linker.h
index 6eab00c..fbd236f 100644
--- a/linker/linker.h
+++ b/linker/linker.h
@@ -461,9 +461,6 @@
int do_dladdr(const void* addr, Dl_info* info);
-void debuggerd_init();
-extern "C" abort_msg_t* g_abort_message;
-
char* linker_get_error_buffer();
size_t linker_get_error_buffer_size();
diff --git a/tests/stdio_test.cpp b/tests/stdio_test.cpp
index 7e82612..4db1f72 100644
--- a/tests/stdio_test.cpp
+++ b/tests/stdio_test.cpp
@@ -1297,3 +1297,11 @@
fclose(fp);
}
+
+TEST(STDIO_TEST, ctermid) {
+ ASSERT_STREQ("/dev/tty", ctermid(nullptr));
+
+ char buf[L_ctermid] = {};
+ ASSERT_EQ(buf, ctermid(buf));
+ ASSERT_STREQ("/dev/tty", buf);
+}
diff --git a/tests/string_posix_strerror_r_test.cpp b/tests/string_posix_strerror_r_test.cpp
index ae3b41a..596684b 100644
--- a/tests/string_posix_strerror_r_test.cpp
+++ b/tests/string_posix_strerror_r_test.cpp
@@ -20,7 +20,7 @@
#if defined(__GLIBC__)
// At the time of writing, libcxx -- which is dragged in by gtest -- assumes
-// declarations from glibc of things that aren't available without __USE_GNU.
+// declarations from glibc of things that aren't available without _GNU_SOURCE.
// This means we can't even build this test (which is a problem because that
// means it doesn't get included in CTS).
// For glibc 2.15, the symbols in question are:
diff --git a/tests/sys_time_test.cpp b/tests/sys_time_test.cpp
index 18fbe10..e041ba0 100644
--- a/tests/sys_time_test.cpp
+++ b/tests/sys_time_test.cpp
@@ -22,30 +22,113 @@
#include "TemporaryFile.h"
-TEST(sys_time, utimes) {
- timeval tv[2];
- memset(&tv, 0, sizeof(tv));
+// http://b/11383777
+TEST(sys_time, utimes_nullptr) {
+ TemporaryFile tf;
+ ASSERT_EQ(0, utimes(tf.filename, nullptr));
+}
+
+TEST(sys_time, utimes_EINVAL) {
+ TemporaryFile tf;
+
+ timeval tv[2] = {};
tv[0].tv_usec = -123;
- ASSERT_EQ(-1, utimes("/", tv));
+ ASSERT_EQ(-1, utimes(tf.filename, tv));
ASSERT_EQ(EINVAL, errno);
tv[0].tv_usec = 1234567;
- ASSERT_EQ(-1, utimes("/", tv));
+ ASSERT_EQ(-1, utimes(tf.filename, tv));
ASSERT_EQ(EINVAL, errno);
+
tv[0].tv_usec = 0;
tv[1].tv_usec = -123;
- ASSERT_EQ(-1, utimes("/", tv));
+ ASSERT_EQ(-1, utimes(tf.filename, tv));
ASSERT_EQ(EINVAL, errno);
tv[1].tv_usec = 1234567;
- ASSERT_EQ(-1, utimes("/", tv));
+ ASSERT_EQ(-1, utimes(tf.filename, tv));
ASSERT_EQ(EINVAL, errno);
}
-// http://b/11383777
-TEST(sys_time, utimes_NULL) {
+TEST(sys_time, futimes_nullptr) {
TemporaryFile tf;
- ASSERT_EQ(0, utimes(tf.filename, NULL));
+ ASSERT_EQ(0, futimes(tf.fd, nullptr));
+}
+
+TEST(sys_time, futimes_EINVAL) {
+ TemporaryFile tf;
+
+ timeval tv[2] = {};
+
+ tv[0].tv_usec = -123;
+ ASSERT_EQ(-1, futimes(tf.fd, tv));
+ ASSERT_EQ(EINVAL, errno);
+ tv[0].tv_usec = 1234567;
+ ASSERT_EQ(-1, futimes(tf.fd, tv));
+ ASSERT_EQ(EINVAL, errno);
+
+ tv[0].tv_usec = 0;
+
+ tv[1].tv_usec = -123;
+ ASSERT_EQ(-1, futimes(tf.fd, tv));
+ ASSERT_EQ(EINVAL, errno);
+ tv[1].tv_usec = 1234567;
+ ASSERT_EQ(-1, futimes(tf.fd, tv));
+ ASSERT_EQ(EINVAL, errno);
+}
+
+TEST(sys_time, futimesat_nullptr) {
+ TemporaryFile tf;
+ ASSERT_EQ(0, futimesat(AT_FDCWD, tf.filename, nullptr));
+}
+
+TEST(sys_time, futimesat_EINVAL) {
+ TemporaryFile tf;
+
+ timeval tv[2] = {};
+
+ tv[0].tv_usec = -123;
+ ASSERT_EQ(-1, futimesat(AT_FDCWD, tf.filename, tv));
+ ASSERT_EQ(EINVAL, errno);
+ tv[0].tv_usec = 1234567;
+ ASSERT_EQ(-1, futimesat(AT_FDCWD, tf.filename, tv));
+ ASSERT_EQ(EINVAL, errno);
+
+ tv[0].tv_usec = 0;
+
+ tv[1].tv_usec = -123;
+ ASSERT_EQ(-1, futimesat(AT_FDCWD, tf.filename, tv));
+ ASSERT_EQ(EINVAL, errno);
+ tv[1].tv_usec = 1234567;
+ ASSERT_EQ(-1, futimesat(AT_FDCWD, tf.filename, tv));
+ ASSERT_EQ(EINVAL, errno);
+}
+
+TEST(sys_time, lutimes_nullptr) {
+ TemporaryFile tf;
+ ASSERT_EQ(0, lutimes(tf.filename, nullptr));
+}
+
+TEST(sys_time, lutimes_EINVAL) {
+ TemporaryFile tf;
+
+ timeval tv[2] = {};
+
+ tv[0].tv_usec = -123;
+ ASSERT_EQ(-1, lutimes(tf.filename, tv));
+ ASSERT_EQ(EINVAL, errno);
+ tv[0].tv_usec = 1234567;
+ ASSERT_EQ(-1, lutimes(tf.filename, tv));
+ ASSERT_EQ(EINVAL, errno);
+
+ tv[0].tv_usec = 0;
+
+ tv[1].tv_usec = -123;
+ ASSERT_EQ(-1, lutimes(tf.filename, tv));
+ ASSERT_EQ(EINVAL, errno);
+ tv[1].tv_usec = 1234567;
+ ASSERT_EQ(-1, lutimes(tf.filename, tv));
+ ASSERT_EQ(EINVAL, errno);
}
TEST(sys_time, gettimeofday) {