[hackers] [sbase] date: Just set TZ to handle -u flag || Michael Forney

From: <git_AT_suckless.org>
Date: Sun, 3 Sep 2017 22:11:20 +0200 (CEST)

commit 1b41610a820215cdc569129e1cada5c6267fcecb
Author: Michael Forney <mforney_AT_mforney.org>
AuthorDate: Sun Sep 3 11:39:12 2017 -0700
Commit: Michael Forney <mforney_AT_mforney.org>
CommitDate: Sun Sep 3 11:39:12 2017 -0700

    date: Just set TZ to handle -u flag
    
    This simplifies things a tiny bit, and is also necessary for setting the
    date since mktime operates based on the value of TZ.

diff --git a/date.c b/date.c
index 1671e1f..7201227 100644
--- a/date.c
+++ b/date.c
_AT_@ -15,9 +15,8 @@ int
 main(int argc, char *argv[])
 {
         struct tm *now;
- struct tm *(*tztime)(const time_t *) = localtime;
         time_t t;
- char buf[BUFSIZ], *fmt = "%c", *tz = "local";
+ char buf[BUFSIZ], *fmt = "%c";
 
         t = time(NULL);
 
_AT_@ -26,8 +25,8 @@ main(int argc, char *argv[])
                 t = estrtonum(EARGF(usage()), 0, LLONG_MAX);
                 break;
         case 'u':
- tztime = gmtime;
- tz = "gm";
+ if (setenv("TZ", "UTC0", 1) < 0)
+ eprintf("setenv:");
                 break;
         default:
                 usage();
_AT_@ -39,8 +38,8 @@ main(int argc, char *argv[])
                 else
                         fmt = &argv[0][1];
         }
- if (!(now = tztime(&t)))
- eprintf("%stime failed\n", tz);
+ if (!(now = localtime(&t)))
+ eprintf("localtime:");
 
         strftime(buf, sizeof(buf), fmt, now);
         puts(buf);
Received on Sun Sep 03 2017 - 22:11:20 CEST

This archive was generated by hypermail 2.3.0 : Sun Sep 03 2017 - 22:13:21 CEST