dm: replace string function api for acrn-dm

String function of strlen()/vsnprintf() shuould be replaced.
This patch remove the strlen(). And vsnprintf() replaced by vasprintf().

Tracked-On: #2687
Signed-off-by: Wei Liu <weix.w.liu@intel.com>
Reviewed-by: Yonghua Huang <yonghua.huang@intel.com>
Reviewed-by: Tianhua Sun <tianhuax.s.sun@intel.com>
Acked-by: Yin Fengwei <fengwei.yin@intel.com>
This commit is contained in:
Wei Liu 2019-03-06 14:37:23 +08:00 committed by wenlingz
parent 4fa293c402
commit 92d75f0dc2
2 changed files with 9 additions and 6 deletions

View File

@ -8,7 +8,6 @@
#ifndef _DM_KMSG_H_
#define _DM_KMSG_H_
#define DM_BUF 4096
#define KERN_NODE "/dev/kmsg"
#define KMSG_FMT "dm_run:"

View File

@ -6,14 +6,13 @@
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdarg.h>
#include "dm_kmsg.h"
int fd_kmsg;
char dm_buf[DM_BUF];
static int open_kmsg(void);
static int close_kmsg(void);
@ -49,21 +48,26 @@ static int close_kmsg(void)
void write_kmsg(const char *fmt, ...)
{
int write_cnt;
int write_cnt, len;
va_list args;
char *dm_buf;
va_start(args, fmt);
vsnprintf(dm_buf, DM_BUF, fmt, args);
len = vasprintf(&dm_buf, fmt, args);
va_end(args);
if (len == -1) {
return;
}
open_kmsg();
/* write the fmt to the /dev/kmsg */
write_cnt = write(fd_kmsg, dm_buf, strlen(dm_buf));
write_cnt = write(fd_kmsg, dm_buf, len);
if (write_cnt < 0) {
perror(KMSG_FMT"write_kmsg");
}
close_kmsg();
free(dm_buf);
return;
}