2 * Copyright 2017 Facebook, Inc.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
22 #include <folly/portability/Config.h>
23 #include <folly/Portability.h>
25 // OSX is a pain. The XCode 8 SDK always declares clock_gettime
26 // even if the target OS version doesn't support it, so you get
27 // an error at runtime because it can't resolve the symbol. We
28 // solve that by pretending we have it here in the header and
29 // then enable our implementation on the source side so that
30 // gets linked in instead.
31 #if __MACH__ && FOLLY_HAVE_CLOCK_GETTIME && \
32 (MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_12 || \
33 __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_10_0)
35 #define FOLLY_FORCE_CLOCK_GETTIME_DEFINITION 1
39 // These aren't generic implementations, so we can only declare them on
40 // platforms we support.
41 #if !FOLLY_HAVE_CLOCK_GETTIME && (defined(__MACH__) || defined(_WIN32))
42 #define CLOCK_REALTIME 0
43 #define CLOCK_MONOTONIC 1
44 #define CLOCK_PROCESS_CPUTIME_ID 2
45 #define CLOCK_THREAD_CPUTIME_ID 3
48 #if (!FOLLY_HAVE_CLOCK_GETTIME || FOLLY_FORCE_CLOCK_GETTIME_DEFINITION) && (defined(__MACH__) || defined(_WIN32))
50 namespace portability {
52 typedef uint8_t clockid_t;
53 int clock_gettime(clockid_t clk_id, struct timespec* ts);
54 int clock_getres(clockid_t clk_id, struct timespec* ts);
60 #if __CLANG_PREREQ(3, 0)
61 FOLLY_GCC_DISABLE_WARNING("-Wheader-hygiene")
63 /* using override */ using namespace folly::portability::time;
68 #define TM_YEAR_BASE (1900)
71 char* asctime_r(const tm* tm, char* buf);
72 char* ctime_r(const time_t* t, char* buf);
73 tm* gmtime_r(const time_t* t, tm* res);
74 tm* localtime_r(const time_t* t, tm* o);
75 int nanosleep(const struct timespec* request, struct timespec* remain);
77 const char* __restrict buf,
78 const char* __restrict fmt,
79 struct tm* __restrict tm);