From mboxrd@z Thu Jan 1 00:00:00 1970 From: AKASHI Takahiro Date: Wed, 13 Nov 2019 09:44:50 +0900 Subject: [U-Boot] [PATCH v3 04/16] lib: add mktime64() for linux compatibility In-Reply-To: <20191113004502.29986-1-takahiro.akashi@linaro.org> References: <20191113004502.29986-1-takahiro.akashi@linaro.org> Message-ID: <20191113004502.29986-5-takahiro.akashi@linaro.org> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de 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 --- include/linux/time.h | 10 ++++++++++ lib/date.c | 20 ++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/include/linux/time.h b/include/linux/time.h index b8d298eb4d68..dc9344a6d97b 100644 --- a/include/linux/time.h +++ b/include/linux/time.h @@ -1,6 +1,7 @@ #ifndef _LINUX_TIME_H #define _LINUX_TIME_H +#include #include #define _DEFUN(a,b,c) a(c) @@ -150,4 +151,13 @@ _DEFUN (ctime_r, (tim_p, result), return asctime_r (localtime_r (tim_p, &tm), result); } +/* for compatibility with linux code */ +typedef __s64 time64_t; + +#ifdef CONFIG_LIB_DATE +time64_t mktime64(const unsigned int year, const unsigned int mon, + const unsigned int day, const unsigned int hour, + const unsigned int min, const unsigned int sec); +#endif + #endif diff --git a/lib/date.c b/lib/date.c index 63af4a142612..0456de78ab14 100644 --- a/lib/date.c +++ b/lib/date.c @@ -8,6 +8,7 @@ #include #include #include +#include #if defined(CONFIG_LIB_DATE) || defined(CONFIG_TIMESTAMP) @@ -97,3 +98,22 @@ unsigned long rtc_mktime(const struct rtc_time *tm) } #endif /* CONFIG_LIB_DATE || CONFIG_TIMESTAMP */ + +#ifdef CONFIG_LIB_DATE +/* for compatibility with linux code */ +time64_t mktime64(const unsigned int year, const unsigned int mon, + const unsigned int day, const unsigned int hour, + const unsigned int min, const unsigned int sec) +{ + struct rtc_time time; + + time.tm_year = year; + time.tm_mon = mon; + time.tm_mday = day; + time.tm_hour = hour; + time.tm_min = min; + time.tm_sec = sec; + + return (time64_t)rtc_mktime((const struct rtc_time *)&time); +} +#endif -- 2.21.0