mirror of
https://codeberg.org/grunfink/snac2.git
synced 2024-11-29 07:53:37 +00:00
Added time functions.
This commit is contained in:
parent
0d86568346
commit
91adc48178
2 changed files with 23 additions and 1 deletions
20
snac.c
20
snac.c
|
@ -21,10 +21,28 @@ d_char *srv_baseurl = NULL;
|
||||||
int dbglevel = 0;
|
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)
|
void srv_log(d_char *str)
|
||||||
/* logs a message */
|
/* logs a message */
|
||||||
{
|
{
|
||||||
char tm[16] = "00:00:00";
|
xs *tm = xs_local_time("%H:%M:%S");
|
||||||
xs *msg = str;
|
xs *msg = str;
|
||||||
|
|
||||||
fprintf(stderr, "%s %s\n", tm, msg);
|
fprintf(stderr, "%s %s\n", tm, msg);
|
||||||
|
|
4
snac.h
4
snac.h
|
@ -7,6 +7,10 @@ extern d_char *srv_baseurl;
|
||||||
|
|
||||||
extern int dbglevel;
|
extern int dbglevel;
|
||||||
|
|
||||||
|
d_char *xs_time(char *fmt, int local);
|
||||||
|
#define xs_local_time(fmt) xs_time(fmt, 1)
|
||||||
|
#define xs_utc_time(fmt) xs_time(fmt, 0)
|
||||||
|
|
||||||
void srv_log(d_char *str);
|
void srv_log(d_char *str);
|
||||||
int srv_open(char *basedir);
|
int srv_open(char *basedir);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue