Match-id-df4725b6c80f635a41309e55ed1b71e075c67f50

This commit is contained in:
BianTanggui
2021-07-07 15:13:37 +08:00
parent 2a8df8f50e
commit 3ddbe2299d
5 changed files with 128 additions and 106 deletions

View File

@@ -15,23 +15,27 @@
#include "securec.h"
#include "logger.h"
char *FormatLogMessage(char *format, int* iLength, ...){
char *FormatLogMessage(char *format, int* iLength, ...)
{
va_list list;
// 获取格式化后字符串的长度
va_start(list, format);
va_start(list, iLength);
char buff[1024] = {0};
int size = vsnprintf_s(buff, sizeof(buff), sizeof(buff), format, list);
va_end(list);
if(size <= 0){
if (size <= 0) {
return NULL;
}
size++;
// 复位va_list, 将格式化字符串写入到buf
va_start(list, format);
va_start(list, iLength);
char *buf = (char *)malloc(size);
*iLength = size;
vsnprintf_s(buf, size, size, format, list);
int ret = vsnprintf_s(buf, size, size, format, list);
va_end(list);
if (ret <= 0) {
return NULL;
}
return buf;
}