Merge "Add C11 timespec_get."

This commit is contained in:
Treehugger Robot 2018-07-18 23:16:24 +00:00 committed by Gerrit Code Review
commit 76221401ed
11 changed files with 54 additions and 0 deletions

View file

@ -1389,6 +1389,7 @@ cc_library_static {
"bionic/tdestroy.cpp",
"bionic/termios.cpp",
"bionic/thread_private.cpp",
"bionic/timespec_get.cpp",
"bionic/tmpfile.cpp",
"bionic/umount.cpp",
"bionic/unlink.cpp",

View file

@ -0,0 +1,33 @@
/*
* Copyright (C) 2018 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 <time.h>
int timespec_get(timespec* ts, int base) {
return (base == TIME_UTC && clock_gettime(CLOCK_REALTIME, ts) != -1) ? base : 0;
}

View file

@ -108,6 +108,9 @@ int timer_getoverrun(timer_t __timer);
time_t timelocal(struct tm* __tm) __INTRODUCED_IN(12);
time_t timegm(struct tm* __tm) __INTRODUCED_IN(12);
#define TIME_UTC 1
int timespec_get(struct timespec* __ts, int __base) __INTRODUCED_IN_FUTURE;
__END_DECLS
#endif

View file

@ -1423,6 +1423,7 @@ LIBC_P { # introduced=P
LIBC_Q { # introduced=Q
global:
__res_randomid;
timespec_get;
} LIBC_P;
LIBC_PRIVATE {

View file

@ -1344,6 +1344,7 @@ LIBC_P { # introduced=P
LIBC_Q { # introduced=Q
global:
__res_randomid;
timespec_get;
} LIBC_P;
LIBC_PRIVATE {

View file

@ -1448,6 +1448,7 @@ LIBC_P { # introduced=P
LIBC_Q { # introduced=Q
global:
__res_randomid;
timespec_get;
} LIBC_P;
LIBC_PRIVATE {

View file

@ -1407,6 +1407,7 @@ LIBC_P { # introduced=P
LIBC_Q { # introduced=Q
global:
__res_randomid;
timespec_get;
} LIBC_P;
LIBC_PRIVATE {

View file

@ -1344,6 +1344,7 @@ LIBC_P { # introduced=P
LIBC_Q { # introduced=Q
global:
__res_randomid;
timespec_get;
} LIBC_P;
LIBC_PRIVATE {

View file

@ -1405,6 +1405,7 @@ LIBC_P { # introduced=P
LIBC_Q { # introduced=Q
global:
__res_randomid;
timespec_get;
} LIBC_P;
LIBC_PRIVATE {

View file

@ -1344,6 +1344,7 @@ LIBC_P { # introduced=P
LIBC_Q { # introduced=Q
global:
__res_randomid;
timespec_get;
} LIBC_P;
LIBC_PRIVATE {

View file

@ -922,3 +922,13 @@ TEST(time, strptime_s_nothing) {
struct tm tm;
ASSERT_EQ(nullptr, strptime("x", "%s", &tm));
}
TEST(time, timespec_get) {
#if __BIONIC__
timespec ts = {};
ASSERT_EQ(0, timespec_get(&ts, 123));
ASSERT_EQ(TIME_UTC, timespec_get(&ts, TIME_UTC));
#else
GTEST_LOG_(INFO) << "glibc doesn't have timespec_get until 2.21\n";
#endif
}