am 50a9630c: Merge "Start hiding "private/bionic_time.h"."
* commit '50a9630cc26cbc1e38e3ddc589f04fa5cd91697b': Start hiding "private/bionic_time.h".
This commit is contained in:
commit
4b4ee2fc1b
@ -19,26 +19,6 @@
|
|||||||
#include <sys/syscall.h>
|
#include <sys/syscall.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
#if defined(__BIONIC__)
|
|
||||||
|
|
||||||
// Used by the horrible android.text.format.Time class, which is used by Calendar. http://b/8270865.
|
|
||||||
extern "C" void localtime_tz(const time_t* const timep, struct tm* tmp, const char* tz);
|
|
||||||
|
|
||||||
static void BM_time_localtime_tz(int iters) {
|
|
||||||
StartBenchmarkTiming();
|
|
||||||
|
|
||||||
time_t now(time(NULL));
|
|
||||||
tm broken_down_time;
|
|
||||||
for (int i = 0; i < iters; ++i) {
|
|
||||||
localtime_tz(&now, &broken_down_time, "Europe/Berlin");
|
|
||||||
}
|
|
||||||
|
|
||||||
StopBenchmarkTiming();
|
|
||||||
}
|
|
||||||
BENCHMARK(BM_time_localtime_tz);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static void BM_time_clock_gettime(int iters) {
|
static void BM_time_clock_gettime(int iters) {
|
||||||
StartBenchmarkTiming();
|
StartBenchmarkTiming();
|
||||||
|
|
||||||
|
@ -68,7 +68,7 @@
|
|||||||
#ifdef __LP64__
|
#ifdef __LP64__
|
||||||
#define __LIBC64_HIDDEN__ __LIBC_HIDDEN__
|
#define __LIBC64_HIDDEN__ __LIBC_HIDDEN__
|
||||||
#else
|
#else
|
||||||
#define __LIBC64_HIDDEN__
|
#define __LIBC64_HIDDEN__ __LIBC_ABI_PUBLIC__
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Used to tag non-static symbols that are public and exposed by the shared library. */
|
/* Used to tag non-static symbols that are public and exposed by the shared library. */
|
||||||
|
@ -33,32 +33,8 @@
|
|||||||
|
|
||||||
__BEGIN_DECLS
|
__BEGIN_DECLS
|
||||||
|
|
||||||
#ifndef _BIONIC_STRFTIME_TZ_DECLARED
|
// We can't remove this (and this file) until we fix MtpUtils.cpp.
|
||||||
#define _BIONIC_STRFTIME_TZ_DECLARED
|
time_t mktime_tz(struct tm* const, char const*);
|
||||||
|
|
||||||
struct strftime_locale {
|
|
||||||
const char * mon[12];
|
|
||||||
const char * month[12];
|
|
||||||
const char * standalone_month[12];
|
|
||||||
const char * wday[7];
|
|
||||||
const char * weekday[7];
|
|
||||||
const char * X_fmt;
|
|
||||||
const char * x_fmt;
|
|
||||||
const char * c_fmt;
|
|
||||||
const char * am;
|
|
||||||
const char * pm;
|
|
||||||
const char * date_fmt;
|
|
||||||
};
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Note: you should consider these extensions deprecated and use managed code or icu4c instead.
|
|
||||||
* We'd like to hide them but they're currently still used in frameworks code.
|
|
||||||
*/
|
|
||||||
extern size_t strftime_tz(char*, size_t, const char*, const struct tm*, const struct strftime_locale*);
|
|
||||||
extern time_t mktime_tz(struct tm* const, char const*);
|
|
||||||
extern void localtime_tz(const time_t* const, struct tm*, const char*);
|
|
||||||
|
|
||||||
#endif /* _BIONIC_STRFTIME_TZ_DECLARED */
|
|
||||||
|
|
||||||
__END_DECLS
|
__END_DECLS
|
||||||
|
|
||||||
|
@ -2293,7 +2293,8 @@ static int __bionic_tzload_cached(const char* name, struct state* const sp, cons
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Non-standard API: mktime(3) but with an explicit timezone parameter.
|
// Non-standard API: mktime(3) but with an explicit timezone parameter.
|
||||||
time_t __attribute__((visibility("default"))) mktime_tz(struct tm* const tmp, const char* tz) {
|
// This can't actually be hidden/removed until we fix MtpUtils.cpp
|
||||||
|
__attribute__((visibility("default"))) time_t mktime_tz(struct tm* const tmp, const char* tz) {
|
||||||
struct state* st = malloc(sizeof(*st));
|
struct state* st = malloc(sizeof(*st));
|
||||||
time_t return_value;
|
time_t return_value;
|
||||||
|
|
||||||
@ -2310,7 +2311,8 @@ time_t __attribute__((visibility("default"))) mktime_tz(struct tm* const tmp, co
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Non-standard API: localtime(3) but with an explicit timezone parameter.
|
// Non-standard API: localtime(3) but with an explicit timezone parameter.
|
||||||
void __attribute__((visibility("default"))) localtime_tz(const time_t* const timep, struct tm* tmp, const char* tz) {
|
#if !defined(__LP64__)
|
||||||
|
__attribute__((visibility("default"))) void localtime_tz(const time_t* const timep, struct tm* tmp, const char* tz) {
|
||||||
struct state* st = malloc(sizeof(*st));
|
struct state* st = malloc(sizeof(*st));
|
||||||
|
|
||||||
if (st == NULL)
|
if (st == NULL)
|
||||||
@ -2322,5 +2324,6 @@ void __attribute__((visibility("default"))) localtime_tz(const time_t* const tim
|
|||||||
localsub(timep, 0L, tmp, st);
|
localsub(timep, 0L, tmp, st);
|
||||||
free(st);
|
free(st);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// END android-added
|
// END android-added
|
||||||
|
@ -29,16 +29,38 @@
|
|||||||
#include "locale.h"
|
#include "locale.h"
|
||||||
|
|
||||||
#if __ANDROID__
|
#if __ANDROID__
|
||||||
/* Android: struct lc_time_T is defined as strftime_locale in "bionic_time.h" */
|
|
||||||
#include "private/bionic_time.h" /* for strftime_tz */
|
/*
|
||||||
#define lc_time_T strftime_locale
|
* This has an extra standalone_month array field compared to upstream.
|
||||||
|
* We only need to keep that if we leave the strftime_tz symbol exposed.
|
||||||
|
* Even then, this structure was never in an NDK header file.
|
||||||
|
*/
|
||||||
|
struct lc_time_T {
|
||||||
|
const char * mon[12];
|
||||||
|
const char * month[12];
|
||||||
|
const char * standalone_month[12];
|
||||||
|
const char * wday[7];
|
||||||
|
const char * weekday[7];
|
||||||
|
const char * X_fmt;
|
||||||
|
const char * x_fmt;
|
||||||
|
const char * c_fmt;
|
||||||
|
const char * am;
|
||||||
|
const char * pm;
|
||||||
|
const char * date_fmt;
|
||||||
|
};
|
||||||
|
|
||||||
|
/* LP32 had a 32-bit time_t, so we need to work around that here. */
|
||||||
#if defined(__LP64__)
|
#if defined(__LP64__)
|
||||||
#define time64_t time_t
|
#define time64_t time_t
|
||||||
#define mktime64 mktime
|
#define mktime64 mktime
|
||||||
#else
|
#else
|
||||||
#include <time64.h>
|
#include <time64.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
|
||||||
|
size_t strftime_tz(char*, size_t, const char*, const struct tm*, const struct lc_time_T*);
|
||||||
|
|
||||||
#else // not __ANDROID__
|
#else // not __ANDROID__
|
||||||
struct lc_time_T {
|
struct lc_time_T {
|
||||||
const char * mon[MONSPERYEAR];
|
const char * mon[MONSPERYEAR];
|
||||||
@ -116,7 +138,7 @@ static const struct lc_time_T C_time_locale = {
|
|||||||
static char * _add(const char *, char *, const char *, int);
|
static char * _add(const char *, char *, const char *, int);
|
||||||
static char * _conv(int, const char *, char *, const char *);
|
static char * _conv(int, const char *, char *, const char *);
|
||||||
static char * _fmt(const char *, const struct tm *, char *, const char *,
|
static char * _fmt(const char *, const struct tm *, char *, const char *,
|
||||||
int *, const struct strftime_locale*);
|
int *, const struct lc_time_T*);
|
||||||
static char * _yconv(int, int, int, int, char *, const char *, int);
|
static char * _yconv(int, int, int, int, char *, const char *, int);
|
||||||
static char * getformat(int, char *, char *, char *, char *);
|
static char * getformat(int, char *, char *, char *, char *);
|
||||||
|
|
||||||
@ -143,13 +165,12 @@ const struct tm * const t;
|
|||||||
return strftime_tz(s, maxsize, format, t, Locale);
|
return strftime_tz(s, maxsize, format, t, Locale);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t
|
__LIBC64_HIDDEN__ size_t strftime_tz(s, maxsize, format, t, locale)
|
||||||
__attribute__((visibility("default"))) strftime_tz(s, maxsize, format, t, locale)
|
|
||||||
char * const s;
|
char * const s;
|
||||||
const size_t maxsize;
|
const size_t maxsize;
|
||||||
const char * const format;
|
const char * const format;
|
||||||
const struct tm * const t;
|
const struct tm * const t;
|
||||||
const struct strftime_locale *locale;
|
const struct lc_time_T *locale;
|
||||||
{
|
{
|
||||||
char * p;
|
char * p;
|
||||||
int warn;
|
int warn;
|
||||||
@ -202,7 +223,7 @@ const struct tm * const t;
|
|||||||
char * pt;
|
char * pt;
|
||||||
const char * const ptlim;
|
const char * const ptlim;
|
||||||
int * warnp;
|
int * warnp;
|
||||||
const struct strftime_locale* locale;
|
const struct lc_time_T* locale;
|
||||||
{
|
{
|
||||||
for ( ; *format; ++format) {
|
for ( ; *format; ++format) {
|
||||||
if (*format == '%') {
|
if (*format == '%') {
|
||||||
|
@ -27,34 +27,6 @@
|
|||||||
|
|
||||||
#include "ScopedSignalHandler.h"
|
#include "ScopedSignalHandler.h"
|
||||||
|
|
||||||
#if defined(__BIONIC__) // mktime_tz is a bionic extension.
|
|
||||||
#include <libc/private/bionic_time.h>
|
|
||||||
#endif // __BIONIC__
|
|
||||||
|
|
||||||
TEST(time, mktime_tz) {
|
|
||||||
#if defined(__BIONIC__)
|
|
||||||
struct tm epoch;
|
|
||||||
memset(&epoch, 0, sizeof(tm));
|
|
||||||
epoch.tm_year = 1970 - 1900;
|
|
||||||
epoch.tm_mon = 1;
|
|
||||||
epoch.tm_mday = 1;
|
|
||||||
|
|
||||||
// Alphabetically first. Coincidentally equivalent to UTC.
|
|
||||||
ASSERT_EQ(2678400, mktime_tz(&epoch, "Africa/Abidjan"));
|
|
||||||
|
|
||||||
// Alphabetically last. Coincidentally equivalent to UTC.
|
|
||||||
ASSERT_EQ(2678400, mktime_tz(&epoch, "Zulu"));
|
|
||||||
|
|
||||||
// Somewhere in the middle, not UTC.
|
|
||||||
ASSERT_EQ(2707200, mktime_tz(&epoch, "America/Los_Angeles"));
|
|
||||||
|
|
||||||
// Missing. Falls back to UTC.
|
|
||||||
ASSERT_EQ(2678400, mktime_tz(&epoch, "PST"));
|
|
||||||
#else // __BIONIC__
|
|
||||||
GTEST_LOG_(INFO) << "This test does nothing.\n";
|
|
||||||
#endif // __BIONIC__
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(time, gmtime) {
|
TEST(time, gmtime) {
|
||||||
time_t t = 0;
|
time_t t = 0;
|
||||||
tm* broken_down = gmtime(&t);
|
tm* broken_down = gmtime(&t);
|
||||||
@ -108,9 +80,6 @@ TEST(time, mktime_10310929) {
|
|||||||
#if !defined(__LP64__)
|
#if !defined(__LP64__)
|
||||||
// 32-bit bionic stupidly had a signed 32-bit time_t.
|
// 32-bit bionic stupidly had a signed 32-bit time_t.
|
||||||
ASSERT_EQ(-1, mktime(&t));
|
ASSERT_EQ(-1, mktime(&t));
|
||||||
#if defined(__BIONIC__)
|
|
||||||
ASSERT_EQ(-1, mktime_tz(&t, "UTC"));
|
|
||||||
#endif
|
|
||||||
#else
|
#else
|
||||||
// Everyone else should be using a signed 64-bit time_t.
|
// Everyone else should be using a signed 64-bit time_t.
|
||||||
ASSERT_GE(sizeof(time_t) * 8, 64U);
|
ASSERT_GE(sizeof(time_t) * 8, 64U);
|
||||||
@ -118,16 +87,10 @@ TEST(time, mktime_10310929) {
|
|||||||
setenv("TZ", "America/Los_Angeles", 1);
|
setenv("TZ", "America/Los_Angeles", 1);
|
||||||
tzset();
|
tzset();
|
||||||
ASSERT_EQ(static_cast<time_t>(4108348800U), mktime(&t));
|
ASSERT_EQ(static_cast<time_t>(4108348800U), mktime(&t));
|
||||||
#if defined(__BIONIC__)
|
|
||||||
ASSERT_EQ(static_cast<time_t>(4108320000U), mktime_tz(&t, "UTC"));
|
|
||||||
#endif
|
|
||||||
|
|
||||||
setenv("TZ", "UTC", 1);
|
setenv("TZ", "UTC", 1);
|
||||||
tzset();
|
tzset();
|
||||||
ASSERT_EQ(static_cast<time_t>(4108320000U), mktime(&t));
|
ASSERT_EQ(static_cast<time_t>(4108320000U), mktime(&t));
|
||||||
#if defined(__BIONIC__)
|
|
||||||
ASSERT_EQ(static_cast<time_t>(4108348800U), mktime_tz(&t, "America/Los_Angeles"));
|
|
||||||
#endif
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user