Merge "Add C11 timespec_get."
This commit is contained in:
commit
76221401ed
11 changed files with 54 additions and 0 deletions
|
@ -1389,6 +1389,7 @@ cc_library_static {
|
||||||
"bionic/tdestroy.cpp",
|
"bionic/tdestroy.cpp",
|
||||||
"bionic/termios.cpp",
|
"bionic/termios.cpp",
|
||||||
"bionic/thread_private.cpp",
|
"bionic/thread_private.cpp",
|
||||||
|
"bionic/timespec_get.cpp",
|
||||||
"bionic/tmpfile.cpp",
|
"bionic/tmpfile.cpp",
|
||||||
"bionic/umount.cpp",
|
"bionic/umount.cpp",
|
||||||
"bionic/unlink.cpp",
|
"bionic/unlink.cpp",
|
||||||
|
|
33
libc/bionic/timespec_get.cpp
Normal file
33
libc/bionic/timespec_get.cpp
Normal 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;
|
||||||
|
}
|
|
@ -108,6 +108,9 @@ int timer_getoverrun(timer_t __timer);
|
||||||
time_t timelocal(struct tm* __tm) __INTRODUCED_IN(12);
|
time_t timelocal(struct tm* __tm) __INTRODUCED_IN(12);
|
||||||
time_t timegm(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
|
__END_DECLS
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1423,6 +1423,7 @@ LIBC_P { # introduced=P
|
||||||
LIBC_Q { # introduced=Q
|
LIBC_Q { # introduced=Q
|
||||||
global:
|
global:
|
||||||
__res_randomid;
|
__res_randomid;
|
||||||
|
timespec_get;
|
||||||
} LIBC_P;
|
} LIBC_P;
|
||||||
|
|
||||||
LIBC_PRIVATE {
|
LIBC_PRIVATE {
|
||||||
|
|
|
@ -1344,6 +1344,7 @@ LIBC_P { # introduced=P
|
||||||
LIBC_Q { # introduced=Q
|
LIBC_Q { # introduced=Q
|
||||||
global:
|
global:
|
||||||
__res_randomid;
|
__res_randomid;
|
||||||
|
timespec_get;
|
||||||
} LIBC_P;
|
} LIBC_P;
|
||||||
|
|
||||||
LIBC_PRIVATE {
|
LIBC_PRIVATE {
|
||||||
|
|
|
@ -1448,6 +1448,7 @@ LIBC_P { # introduced=P
|
||||||
LIBC_Q { # introduced=Q
|
LIBC_Q { # introduced=Q
|
||||||
global:
|
global:
|
||||||
__res_randomid;
|
__res_randomid;
|
||||||
|
timespec_get;
|
||||||
} LIBC_P;
|
} LIBC_P;
|
||||||
|
|
||||||
LIBC_PRIVATE {
|
LIBC_PRIVATE {
|
||||||
|
|
|
@ -1407,6 +1407,7 @@ LIBC_P { # introduced=P
|
||||||
LIBC_Q { # introduced=Q
|
LIBC_Q { # introduced=Q
|
||||||
global:
|
global:
|
||||||
__res_randomid;
|
__res_randomid;
|
||||||
|
timespec_get;
|
||||||
} LIBC_P;
|
} LIBC_P;
|
||||||
|
|
||||||
LIBC_PRIVATE {
|
LIBC_PRIVATE {
|
||||||
|
|
|
@ -1344,6 +1344,7 @@ LIBC_P { # introduced=P
|
||||||
LIBC_Q { # introduced=Q
|
LIBC_Q { # introduced=Q
|
||||||
global:
|
global:
|
||||||
__res_randomid;
|
__res_randomid;
|
||||||
|
timespec_get;
|
||||||
} LIBC_P;
|
} LIBC_P;
|
||||||
|
|
||||||
LIBC_PRIVATE {
|
LIBC_PRIVATE {
|
||||||
|
|
|
@ -1405,6 +1405,7 @@ LIBC_P { # introduced=P
|
||||||
LIBC_Q { # introduced=Q
|
LIBC_Q { # introduced=Q
|
||||||
global:
|
global:
|
||||||
__res_randomid;
|
__res_randomid;
|
||||||
|
timespec_get;
|
||||||
} LIBC_P;
|
} LIBC_P;
|
||||||
|
|
||||||
LIBC_PRIVATE {
|
LIBC_PRIVATE {
|
||||||
|
|
|
@ -1344,6 +1344,7 @@ LIBC_P { # introduced=P
|
||||||
LIBC_Q { # introduced=Q
|
LIBC_Q { # introduced=Q
|
||||||
global:
|
global:
|
||||||
__res_randomid;
|
__res_randomid;
|
||||||
|
timespec_get;
|
||||||
} LIBC_P;
|
} LIBC_P;
|
||||||
|
|
||||||
LIBC_PRIVATE {
|
LIBC_PRIVATE {
|
||||||
|
|
|
@ -922,3 +922,13 @@ TEST(time, strptime_s_nothing) {
|
||||||
struct tm tm;
|
struct tm tm;
|
||||||
ASSERT_EQ(nullptr, strptime("x", "%s", &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
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue