blob: 77addf98bae7b3a9c1759ad569c50fa3113903b6 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "clog.h"
#define TIMESTRLEN 20
int lprintf(const char *format, ...)
{
va_list ap;
va_start(ap, format);
int n = vlprintf(format, ap);
va_end(ap);
return n;
}
int vlprintf(const char *format, va_list ap)
{
time_t timer = time(NULL);
struct tm *tm_info = localtime(&timer);
char buf[TIMESTRLEN];
strftime(buf, TIMESTRLEN, "%Y/%m/%d %H:%M:%S", tm_info);
free(tm_info);
int n = printf("%s ", buf);
size_t fmtlen = strlen(format) + 2;
char fmt[fmtlen];
memset(fmt, '\0', fmtlen);
strcpy(fmt, format);
strcat(fmt, "\n");
n += vprintf(format, ap);
return n;
}
|