commit | author | age
|
7f6076
|
1 |
/* vim: set ts=4 sts=4 sw=4 noet : */ |
d7639a
|
2 |
#include<stdio.h> |
SP |
3 |
#include<stdlib.h> |
|
4 |
#include "general.h" |
|
5 |
#include<stdarg.h> |
|
6 |
|
1ab449
|
7 |
#include <sys/time.h> |
SP |
8 |
#include <unistd.h> |
|
9 |
#include <time.h> |
|
10 |
|
|
11 |
|
a10dd5
|
12 |
ts_uint ts_fprintf(FILE *fd, char *fmt, ...){ |
d7639a
|
13 |
if(quiet) return TS_SUCCESS; |
1ab449
|
14 |
va_list ap; |
SP |
15 |
va_start(ap,fmt); |
|
16 |
char tmbuf[255]; |
|
17 |
struct timeval now; |
|
18 |
gettimeofday(&now, 0); |
|
19 |
strftime(tmbuf, sizeof tmbuf, "%Y-%m-%d %H:%M:%S", localtime(&now.tv_sec)); |
|
20 |
fprintf(fd, "[%s] ",tmbuf); |
a10dd5
|
21 |
vfprintf(fd, fmt, ap); /* Call vfprintf */ |
d7639a
|
22 |
va_end(ap); /* Cleanup the va_list */ |
SP |
23 |
return TS_SUCCESS; |
|
24 |
} |
|
25 |
|
|
26 |
void err(char *text){ |
|
27 |
ts_fprintf(stderr,"Err: %s\n", text); |
|
28 |
} |
|
29 |
|
|
30 |
void fatal(char *text, ts_int errcode){ |
|
31 |
ts_fprintf(stderr,"Fatal: %s. TERMINATED!\n", text); |
|
32 |
exit(errcode); |
|
33 |
} |
|
34 |
|
|
35 |
|