blob: b4d0dd46404853106495f1c59d4b7c74534d6df1 (
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
|
#include <stdarg.h>
#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);
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);
va_end(ap);
return n;
}
|