标签:sizeof message end lse va_list api %s ftime void
#include <WinBase.h>
#include <stdio.h>
#include <stdarg.h>
#include <time.h>
#include <stdio.h>
#include <wchar.h>
static void dbg(const char *fmt, ...)
{
//获取时间并减去 8 小时时差
struct timespec ts;
timespec_get(&ts, TIME_UTC);
ts.tv_sec += 28800;
//格式化时间
char time_buf[32];
size_t rc = strftime(time_buf, sizeof time_buf, "[%Y-%m-%d %T", gmtime(&ts.tv_sec));
int time_lenght = snprintf(time_buf + rc, sizeof time_buf - rc, ".%06ld UTC+8]", ts.tv_nsec / 1000);
//获取参数列表
va_list args;
va_start(args, fmt);
//打印参数列表
char message[9216] = { 0 };
vsnprintf_s(message, 9216, 9216 - 1, fmt, args);
//组合格式化的时间和参数列表字符串
char debug[10240] = { 0 };
sprintf_s(debug, 10240, "%s [debug] %s", time_buf, message);
#ifdef WINBASEAPI
OutputDebugStringA(debug);
#else
printf("%s\n", debug);
#endif
}
标签:sizeof message end lse va_list api %s ftime void
原文地址:https://www.cnblogs.com/cheungxiongwei/p/9092699.html