Commit 18723117271370e480f8ca9495f8850522fabb74
Committed by
Tom Rini
1 parent
05429b6cf5
Exists in
smarc_8mq_lf_v2020.04
and in
9 other branches
lib: add mktime64() for linux compatibility
This function will be used in lib/crypto/x509_cert_parser.c, which will also be imported from linux code in a later commit. Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Showing 2 changed files with 30 additions and 0 deletions Side-by-side Diff
include/linux/time.h
1 | 1 | #ifndef _LINUX_TIME_H |
2 | 2 | #define _LINUX_TIME_H |
3 | 3 | |
4 | +#include <rtc.h> | |
4 | 5 | #include <linux/types.h> |
5 | 6 | |
6 | 7 | #define _DEFUN(a,b,c) a(c) |
... | ... | @@ -149,6 +150,15 @@ |
149 | 150 | struct tm tm; |
150 | 151 | return asctime_r (localtime_r (tim_p, &tm), result); |
151 | 152 | } |
153 | + | |
154 | +/* for compatibility with linux code */ | |
155 | +typedef __s64 time64_t; | |
156 | + | |
157 | +#ifdef CONFIG_LIB_DATE | |
158 | +time64_t mktime64(const unsigned int year, const unsigned int mon, | |
159 | + const unsigned int day, const unsigned int hour, | |
160 | + const unsigned int min, const unsigned int sec); | |
161 | +#endif | |
152 | 162 | |
153 | 163 | #endif |
lib/date.c
... | ... | @@ -8,6 +8,7 @@ |
8 | 8 | #include <command.h> |
9 | 9 | #include <errno.h> |
10 | 10 | #include <rtc.h> |
11 | +#include <linux/time.h> | |
11 | 12 | |
12 | 13 | #if defined(CONFIG_LIB_DATE) || defined(CONFIG_TIMESTAMP) |
13 | 14 | |
... | ... | @@ -97,4 +98,23 @@ |
97 | 98 | } |
98 | 99 | |
99 | 100 | #endif /* CONFIG_LIB_DATE || CONFIG_TIMESTAMP */ |
101 | + | |
102 | +#ifdef CONFIG_LIB_DATE | |
103 | +/* for compatibility with linux code */ | |
104 | +time64_t mktime64(const unsigned int year, const unsigned int mon, | |
105 | + const unsigned int day, const unsigned int hour, | |
106 | + const unsigned int min, const unsigned int sec) | |
107 | +{ | |
108 | + struct rtc_time time; | |
109 | + | |
110 | + time.tm_year = year; | |
111 | + time.tm_mon = mon; | |
112 | + time.tm_mday = day; | |
113 | + time.tm_hour = hour; | |
114 | + time.tm_min = min; | |
115 | + time.tm_sec = sec; | |
116 | + | |
117 | + return (time64_t)rtc_mktime((const struct rtc_time *)&time); | |
118 | +} | |
119 | +#endif |