time: Add time64_to_tm()
authorDeepa Dinamani <deepa.kernel@gmail.com>
Thu, 9 Jun 2016 05:04:59 +0000 (22:04 -0700)
committerJohn Stultz <john.stultz@linaro.org>
Mon, 20 Jun 2016 19:47:15 +0000 (12:47 -0700)
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
kernel/time/timeconv.c

index 297f09f23896d2db41cd90a0cad37746e6ed77aa..4cea09d9420803469a991cf7038864a92982b0c0 100644 (file)
@@ -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
index 86628e755f38f82bab7423a2d9f702782bc6c598..7142580ad94fa03f3011b6c444b7bc3679ca6088 100644 (file)
@@ -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);