diff options
author | default <nobody@localhost> | 2022-09-19 21:24:55 +0200 |
---|---|---|
committer | default <nobody@localhost> | 2022-09-19 21:24:55 +0200 |
commit | 91adc4817866dcde11bc0547b2ee9ab672dbc2d8 (patch) | |
tree | 2f382ec278e9edefd5cbfd911cc96a5aa9c35069 /snac.c | |
parent | 0d86568346d116f96abfe81e5b0ae05ba17b17c2 (diff) |
Added time functions.
Diffstat (limited to 'snac.c')
-rw-r--r-- | snac.c | 20 |
1 files changed, 19 insertions, 1 deletions
@@ -21,10 +21,28 @@ d_char *srv_baseurl = NULL; int dbglevel = 0; +d_char *xs_time(char *fmt, int local) +/* returns a d_char with a formated time */ +{ + time_t t = time(NULL); + struct tm tm; + char tmp[64]; + + if (local) + localtime_r(&t, &tm); + else + gmtime_r(&t, &tm); + + strftime(tmp, sizeof(tmp), fmt, &tm); + + return xs_str_new(tmp); +} + + void srv_log(d_char *str) /* logs a message */ { - char tm[16] = "00:00:00"; + xs *tm = xs_local_time("%H:%M:%S"); xs *msg = str; fprintf(stderr, "%s %s\n", tm, msg); |