Debian Codegraph @

crt/aws-c-common/source/posix/time.c

raw symbols SCIP
1 /**
2 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 * SPDX-License-Identifier: Apache-2.0.
4 */
5 #include <aws/common/time.h>
6
7 #if defined(__ANDROID__) && !defined(__LP64__)
8 /*
9 * This branch brought to you by the kind folks at google chromium. It's been modified a bit, but
10 * gotta give credit where it's due.... I'm not a lawyer so I'm just gonna drop their copyright
11 * notification here to avoid all of that.
12 */
13
14 /*
15 * Copyright 2014 The Chromium Authors. All rights reserved.
16 *
17 * Redistribution and use in source and binary forms, with or without
18 * modification, are permitted provided that the following conditions are
19 * met:
20 *
21 * Redistributions of source code must retain the above copyright
22 * notice, this list of conditions and the following disclaimer.
23 * Redistributions in binary form must reproduce the above
24 * copyright notice, this list of conditions and the following disclaimer
25 * in the documentation and/or other materials provided with the
26 * distribution.
27 * Neither the name of Google Inc. nor the names of its
28 * contributors may be used to endorse or promote products derived from
29 * this software without specific prior written permission.
30 *
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
36 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
37 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
38 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
39 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
40 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
41 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42
43 * From src/base/os_compat_android.cc:
44 */
45 # include <time64.h>
46
47 static const time_t s_time_max = ~(1L << ((sizeof(time_t) * __CHAR_BIT__ - 1)));
48 static const time_t s_time_min = (1L << ((sizeof(time_t)) * __CHAR_BIT__ - 1));
49
50 /* 32-bit Android has only timegm64() and not timegm(). */
51 time_t aws_timegm(struct tm *const t) {
52
53 time64_t result = timegm64(t);
54 if (result < s_time_min || result > s_time_max) {
55 return -1;
56 }
57 return (time_t)result;
58 }
59
60 #else
61
62 # ifndef __APPLE__
63 /* glibc.... you disappoint me.. */
64 extern time_t timegm(struct tm *);
65 # endif
66
67 time_t aws_timegm(struct tm *const t) {
68 return timegm(t);
69 }
70
71 #endif /* defined(__ANDROID__) && !defined(__LP64__) */
72
73 void aws_localtime(time_t time, struct tm *t) {
74 localtime_r(&time, t);
75 }
76
77 void aws_gmtime(time_t time, struct tm *t) {
78 gmtime_r(&time, t);
79 }