2 * Copyright 2016-present 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>
24 // OSX is a pain. The XCode 8 SDK always declares clock_gettime
25 // even if the target OS version doesn't support it, so you get
26 // an error at runtime because it can't resolve the symbol. We
27 // solve that by pretending we have it here in the header and
28 // then enable our implementation on the source side so that
29 // gets linked in instead.
31 (MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_12 || \
32 __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_10_0)
34 #ifdef FOLLY_HAVE_CLOCK_GETTIME
35 #undef FOLLY_HAVE_CLOCK_GETTIME
38 #define FOLLY_HAVE_CLOCK_GETTIME 1
39 #define FOLLY_FORCE_CLOCK_GETTIME_DEFINITION 1
43 // These aren't generic implementations, so we can only declare them on
44 // platforms we support.
45 #if !FOLLY_HAVE_CLOCK_GETTIME && (defined(__MACH__) || defined(_WIN32))
46 #define CLOCK_REALTIME 0
47 #define CLOCK_MONOTONIC 1
48 #define CLOCK_PROCESS_CPUTIME_ID 2
49 #define CLOCK_THREAD_CPUTIME_ID 3
51 typedef uint8_t clockid_t;
52 extern "C" int clock_gettime(clockid_t clk_id, struct timespec* ts);
53 extern "C" int clock_getres(clockid_t clk_id, struct timespec* ts);
57 #define TM_YEAR_BASE (1900)
60 char* asctime_r(const tm* tm, char* buf);
61 char* ctime_r(const time_t* t, char* buf);
62 tm* gmtime_r(const time_t* t, tm* res);
63 tm* localtime_r(const time_t* t, tm* o);
64 int nanosleep(const struct timespec* request, struct timespec* remain);
66 const char* __restrict buf,
67 const char* __restrict fmt,
68 struct tm* __restrict tm);