//使用system 进行打印
static void CONSOLE_PRINTF(const char *format, ...)
{
time_t tm_seconds = time(0);
struct tm st_nowtime;
va_list st_args;
char buf[1024] = {0};
char cmd[2048] = {0};
localtime_r(&tm_seconds, &st_nowtime);
sprintf(buf, "[%d-%d-%d %d:%d:%d]", st_nowtime.tm_year + 1900, st_nowtime.tm_mon + 1,
st_nowtime.tm_mday, st_nowtime.tm_hour, st_nowtime.tm_min, st_nowtime.tm_sec);
va_start(st_args, format);
vsprintf(buf + strlen(buf), format, st_args);
va_end(st_args);
sprintf(cmd, "echo \"%s\" > /dev/console", buf);
system(cmd);
return
}
//使用fopen进行打印
static void MONITOR_CONSOLE(const char *format, ...)
{
time_t tm_seconds = time(0);
struct tm st_nowtime;
va_list st_args;
char buf[1024] = {0};
FILE * fd_console;
fd_console = fopen("/dev/console", "w");
if (fd_console == NULL) {
return;
}
localtime_r(&tm_seconds, &st_nowtime);
sprintf(buf, "[%d-%d-%d %d:%d:%d]", st_nowtime.tm_year + 1900, st_nowtime.tm_mon + 1,
st_nowtime.tm_mday, st_nowtime.tm_hour, st_nowtime.tm_min, st_nowtime.tm_sec);
va_start(st_args, format);
vsnprintf(buf + strlen(buf), 1024 - strlen(buf) - 1, format, st_args);
va_end(st_args);
fprintf(fd_console, "%s\n", buf);
return;
}