Xinqi Bao's Git
projects
/
slstatus.git
/ commitdiff
summary
|
log
|
commit
|
diff
|
tree
raw
|
patch
|
inline
| side by side (parent:
25eb9ff
)
removed heap dependency in datetime() and simplified the function
author
Ali H. Fardan <
[email protected]
>
Sun, 28 Aug 2016 13:39:04 +0000
(16:39 +0300)
committer
Ali H. Fardan <
[email protected]
>
Sun, 28 Aug 2016 13:39:04 +0000
(16:39 +0300)
slstatus.c
patch
|
blob
|
history
diff --git
a/slstatus.c
b/slstatus.c
index
4dbe650
..
628c0f4
100644
(file)
--- a/
slstatus.c
+++ b/
slstatus.c
@@
-163,27
+163,14
@@
cpu_perc(void)
static char *
datetime(const char *timeformat)
{
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);
return smprintf(UNKNOWN_STR);
- }
- setlocale(LC_TIME, "C");
- char *ret = smprintf("%s", buf);
- free(buf);
- return ret;
+ return smprintf("%s", timestr);
}
static char *
}
static char *