mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-06-24 06:29:19 +00:00
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:
parent
4fa293c402
commit
92d75f0dc2
@ -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:"
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user