Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1426972

[PATCH 4/6] time: Add time64_to_tm()

Path csiph.com!news.mixmin.net!news.unit0.net!news.panservice.it!bofh.it!news.nic.it!robomod
From John Stultz <john.stultz@linaro.org>
Newsgroups linux.kernel
Subject [PATCH 4/6] time: Add time64_to_tm()
Date Mon, 20 Jun 2016 22:00:01 +0200
Message-ID <rMdwt-44L-19@gated-at.bofh.it> (permalink)
References <rMdwt-44L-11@gated-at.bofh.it>
Dkim-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=vSq/FZyV2ARfKOKZ7M30N/kcOnABUNjRl1NrOf/E1EM=; b=ht2rldQ9GPVPkNX/fyPXO3W0yEnAkeMh4CZ2emgoBjlmrnN3Mhop+TSb63rXQH/tj9 irE1OPX42ar2iVe6RFWpWXEUIYLbllpJafOOTvXmLu1cNBjOvM3j31VbbaZANjNIk+KR s4O0oLgmmuHt6E19SFr3tL+kx8LlpSgzflY+s=
X-Google-Dkim-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=vSq/FZyV2ARfKOKZ7M30N/kcOnABUNjRl1NrOf/E1EM=; b=jekVVKzFBecxyA975TjcphyLnOiT6zWK6UHHGUldkGPU4QE/zMiJzGUQX+jyYuDL0n icULyKWwVf81+/r63VKrmT1FOkZmjrm34l/HAapDUUFW2D5ARTZVxrn3msVvDF/hgXta IM6PN2KWkQgiOw0IHl+FDOky0MGACxcZlnrHdo2RI7Yy95LD+X5JHQZ6Usp5hGMgQMD6 F3Bpl/S/52fPokSJJn4xuBsZzH86JMbabd3U2Ed3NUmuYF5eZ+A6Zd+aVXYW97qZleqp lz4yPjMa0oKEz8mn7TM3u3rAM5CVlrBW68Ma8jjudNQHJxZrYualL62+14XFN7qiCR7z mbKg==
X-Gm-Message-State ALyK8tIzt9pZsw8p5+OgHZwUid7yPwL0tPdR9n6VpiG6vRAlnhzmr9x/hTU4UYoUZpS8WECY
X-Received by 10.66.178.49 with SMTP id cv17mr23749357pac.157.1466452599681; Mon, 20 Jun 2016 12:56:39 -0700 (PDT)
X-Mailer git-send-email 1.9.1
Sender robomod@news.nic.it
List-ID <linux-kernel.vger.kernel.org>
X-Mailing-List linux-kernel@vger.kernel.org
Approved robomod@news.nic.it
Lines 84
Organization linux.* mail to news gateway
X-Original-Cc Deepa Dinamani <deepa.kernel@gmail.com>, Prarit Bhargava <prarit@redhat.com>, Richard Cochran <richardcochran@gmail.com>, Thomas Gleixner <tglx@linutronix.de>, Ingo Molnar <mingo@kernel.org>, John Stultz <john.stultz@linaro.org>
X-Original-Date Mon, 20 Jun 2016 12:56:23 -0700
X-Original-Message-ID <1466452585-29379-5-git-send-email-john.stultz@linaro.org>
X-Original-References <1466452585-29379-1-git-send-email-john.stultz@linaro.org>
X-Original-Sender linux-kernel-owner@vger.kernel.org
Xref csiph.com linux.kernel:1426972

Show key headers only | View raw


From: Deepa Dinamani <deepa.kernel@gmail.com>

time_to_tm() takes time_t as an argument.
time_t is not y2038 safe.
Add time64_to_tm() that takes time64_t as an argument
which is y2038 safe.
The plan is to eventually replace all calls to time_to_tm()
by time64_to_tm().

Cc: Prarit Bhargava <prarit@redhat.com>
Cc: Richard Cochran <richardcochran@gmail.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@kernel.org>
Signed-off-by: Deepa Dinamani <deepa.kernel@gmail.com>
Signed-off-by: John Stultz <john.stultz@linaro.org>
---
 include/linux/time.h   | 15 ++++++++++++++-
 kernel/time/timeconv.c | 11 ++++++-----
 2 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/include/linux/time.h b/include/linux/time.h
index 297f09f..4cea09d 100644
--- a/include/linux/time.h
+++ b/include/linux/time.h
@@ -205,7 +205,20 @@ struct tm {
 	int tm_yday;
 };
 
-void time_to_tm(time_t totalsecs, int offset, struct tm *result);
+void time64_to_tm(time64_t totalsecs, int offset, struct tm *result);
+
+/**
+ * time_to_tm - converts the calendar time to local broken-down time
+ *
+ * @totalsecs	the number of seconds elapsed since 00:00:00 on January 1, 1970,
+ *		Coordinated Universal Time (UTC).
+ * @offset	offset seconds adding to totalsecs.
+ * @result	pointer to struct tm variable to receive broken-down time
+ */
+static inline void time_to_tm(time_t totalsecs, int offset, struct tm *result)
+{
+	time64_to_tm(totalsecs, offset, result);
+}
 
 /**
  * timespec_to_ns - Convert timespec to nanoseconds
diff --git a/kernel/time/timeconv.c b/kernel/time/timeconv.c
index 86628e7..7142580 100644
--- a/kernel/time/timeconv.c
+++ b/kernel/time/timeconv.c
@@ -67,20 +67,21 @@ static const unsigned short __mon_yday[2][13] = {
 #define SECS_PER_DAY	(SECS_PER_HOUR * 24)
 
 /**
- * time_to_tm - converts the calendar time to local broken-down time
+ * time64_to_tm - converts the calendar time to local broken-down time
  *
  * @totalsecs	the number of seconds elapsed since 00:00:00 on January 1, 1970,
  *		Coordinated Universal Time (UTC).
  * @offset	offset seconds adding to totalsecs.
  * @result	pointer to struct tm variable to receive broken-down time
  */
-void time_to_tm(time_t totalsecs, int offset, struct tm *result)
+void time64_to_tm(time64_t totalsecs, int offset, struct tm *result)
 {
 	long days, rem, y;
+	int remainder;
 	const unsigned short *ip;
 
-	days = totalsecs / SECS_PER_DAY;
-	rem = totalsecs % SECS_PER_DAY;
+	days = div_s64_rem(totalsecs, SECS_PER_DAY, &remainder);
+	rem = remainder;
 	rem += offset;
 	while (rem < 0) {
 		rem += SECS_PER_DAY;
@@ -124,4 +125,4 @@ void time_to_tm(time_t totalsecs, int offset, struct tm *result)
 	result->tm_mon = y;
 	result->tm_mday = days + 1;
 }
-EXPORT_SYMBOL(time_to_tm);
+EXPORT_SYMBOL(time64_to_tm);
-- 
1.9.1

Back to linux.kernel | Previous | Next | Find similar | Unroll thread


Thread

[PATCH 4/6] time: Add time64_to_tm() John Stultz <john.stultz@linaro.org> - 2016-06-20 22:00 +0200

csiph-web