slstatus

My fork of https://tools.suckless.org/slstatus/
git clone https://git.inz.fi/slstatus
Log | Files | Refs | README | LICENSE

commit 1d257999ed6049dce4d1305c4dc3304ea9910ca7
parent 25eb9ff35e76312b09ff5613c9a3cc1275938680
Author: Ali H. Fardan <raiz@firemail.cc>
Date:   Sun, 28 Aug 2016 16:39:04 +0300

removed heap dependency in datetime() and simplified the function

Diffstat:
Mslstatus.c | 23+++++------------------
1 file changed, 5 insertions(+), 18 deletions(-)

diff --git a/slstatus.c b/slstatus.c @@ -163,27 +163,14 @@ cpu_perc(void) static char * datetime(const char *timeformat) { - time_t tm; - size_t bufsize = 64; - char *buf = malloc(bufsize); - if (buf == NULL) { - fprintf(stderr, "Failed to get date/time.\n"); - return smprintf(UNKNOWN_STR); - } + time_t t; + char timestr[80]; - time(&tm); - setlocale(LC_TIME, ""); - if (!strftime(buf, bufsize, timeformat, localtime(&tm))) { - setlocale(LC_TIME, "C"); - free(buf); - fprintf(stderr, "Strftime failed.\n"); + t = time(NULL); + if (strftime(timestr, sizeof(timestr), timeformat, localtime(&t)) == 0) return smprintf(UNKNOWN_STR); - } - setlocale(LC_TIME, "C"); - char *ret = smprintf("%s", buf); - free(buf); - return ret; + return smprintf("%s", timestr); } static char *