]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
rtcwake: fix time_t=long assumptions
authorKarel Zak <kzak@redhat.com>
Thu, 6 May 2021 08:13:27 +0000 (10:13 +0200)
committerKarel Zak <kzak@redhat.com>
Thu, 6 May 2021 09:07:22 +0000 (11:07 +0200)
References: http://github.com/karelzak/util-linux/commit/ce3355cc54d97711bc240783324f7ab51fd6e371
Signed-off-by: Karel Zak <kzak@redhat.com>
sys-utils/rtcwake.c

index ec90c9cb7d96cf7715fd6b621dca34a3ae52430e..65f916b8149f8cc1c251f2de6d479e0607520cf9 100644 (file)
@@ -196,15 +196,15 @@ static int get_basetimes(struct rtcwake_control *ctl, int fd)
                 * reflects a seconds offset from UTC.  The value can
                 * help sort out problems like bugs in your C library. */
                char s[64];
-               printf("\tdelta   = %ld\n", ctl->sys_time - ctl->rtc_time);
+               printf("\tdelta   = %"PRId64"\n", (int64_t) ctl->sys_time - ctl->rtc_time);
                printf("\ttzone   = %ld\n", timezone);
                printf("\ttzname  = %s\n", tzname[daylight]);
                gmtime_r(&ctl->sys_time, &tm);
-               printf("\tsystime = %ld, (UTC) %s",
-                               (long) ctl->sys_time, asctime_r(&tm, s));
+               printf("\tsystime = %"PRId64", (UTC) %s",
+                               (int64_t) ctl->sys_time, asctime_r(&tm, s));
                gmtime_r(&ctl->rtc_time, &tm);
-               printf("\trtctime = %ld, (UTC) %s",
-                               (long) ctl->rtc_time, asctime_r(&tm, s));
+               printf("\trtctime = %"PRId64", (UTC) %s",
+                               (int64_t) ctl->rtc_time, asctime_r(&tm, s));
        }
        return 0;
 }
@@ -428,12 +428,11 @@ int main(int argc, char **argv)
                .clock_mode = CM_AUTO
        };
        char *devname = DEFAULT_RTC_DEVICE;
-       unsigned seconds = 0;
        int suspend = SYSFS_MODE;
        int rc = EXIT_SUCCESS;
        int t;
        int fd;
-       time_t alarm = 0;
+       time_t alarm = 0, seconds = 0;
        enum {
                OPT_DATE = CHAR_MAX + 1,
                OPT_LIST
@@ -499,11 +498,11 @@ int main(int argc, char **argv)
                        break;
                case 's':
                        /* alarm time, seconds-to-sleep (relative) */
-                       seconds = strtou32_or_err(optarg, _("invalid seconds argument"));
+                       seconds = strtotime_or_err(optarg, _("invalid seconds argument"));
                        break;
                case 't':
                        /* alarm time, time_t (absolute, seconds since epoch) */
-                       alarm = strtou32_or_err(optarg, _("invalid time argument"));
+                       alarm = strtotime_or_err(optarg, _("invalid time argument"));
                        break;
                case OPT_DATE:
                {       /* alarm time, see timestamp format from manual */
@@ -552,8 +551,11 @@ int main(int argc, char **argv)
                exit(EXIT_FAILURE);
 
        if (ctl.verbose)
-               printf(_("alarm %ld, sys_time %ld, rtc_time %ld, seconds %u\n"),
-                               alarm, ctl.sys_time, ctl.rtc_time, seconds);
+               printf(_("alarm %"PRId64", sys_time %"PRId64", "
+                        "rtc_time %"PRId64", seconds %"PRIu64"\n"),
+                               (int64_t) alarm, (int64_t) ctl.sys_time,
+                               (int64_t) ctl.rtc_time,
+                               (int64_t) seconds);
 
        if (suspend != DISABLE_MODE && suspend != SHOW_MODE) {
                /* perform alarm setup when the show or disable modes are not set */