1 /*
2 * Copyright (C) 2019 The Android Open Source Project
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16
17 #include <errno.h>
18 #include <sys/time.h>
19 #include <time.h>
20
21 /* Needed by Musl internals. Normally provided by Musl's __tz.c file. */
22 const char __utc[] = "UTC";
23
24 /*
25 * strftime ends up depending on time zone data files. Stub this function rather
26 * than stubbing out data loading.
27 */
strftime_l(char * restrict s,size_t n,const char * restrict f,const struct tm * restrict tm,locale_t loc)28 size_t strftime_l(char* restrict s,
29 size_t n,
30 const char* restrict f,
31 const struct tm* restrict tm,
32 locale_t loc) {
33 if (n) {
34 s[0] = 0;
35 }
36 return 0;
37 }
38
strftime(char * restrict s,size_t n,const char * restrict f,const struct tm * restrict tm)39 size_t strftime(char* restrict s,
40 size_t n,
41 const char* restrict f,
42 const struct tm* restrict tm) {
43 return strftime_l(s, n, f, tm, 0);
44 }
45
46 /* Mock Musl function for timezone information - no databases available. */
__secs_to_zone(long long t,int local,int * isdst,long * offset,long * oppoff,const char ** zonename)47 void __secs_to_zone(long long t,
48 int local,
49 int* isdst,
50 long* offset,
51 long* oppoff,
52 const char** zonename) {
53 /* UTC+0 */
54 *isdst = 0;
55 *offset = 0;
56 if (oppoff)
57 *oppoff = 0;
58 *zonename = "UTC";
59 }
60
61 /* sys/time.h is not quite right for ALL_SOURCE, so declare the last argument as
62 * void* */
settimeofday(const struct timeval * tv,const void * tz)63 int settimeofday(const struct timeval* tv, const void* tz) {
64 return EPERM;
65 }
66