将输出定向到stdout和共享内存

时间:2014-10-30 13:06:03

标签: c vxworks

我正在使用C语言在Vxworks中的嵌入式项目中记录功能。

这里我们共享内存,我们写日志并由另一台设备读取。

这里我希望所有输出都指向共享内存和stdout,即串行控制台。如何在Vxworks中使用任何第三方库并使用C语言来实现这一目标。

感谢您的时间和投入。

1 个答案:

答案 0 :(得分:3)

将所有printf替换为myprintf(以下实施)。

myprintf函数的作用与printf完全相同,但会对该行进行一些进一步处理。

void myprintf(const char *format, ...)
{
    char buffer[500];   // lines are restricted to maximum of 500 chars
    va_list args;
    va_start (args, format);
    vsnprintf (buffer, 500, format, args);
    va_end (args);

    // here buffer contains the string resulting from the invocation of myprintf
    // now here you can do whatever you want with the content of buffer

    puts(buffer);  // write to stdout

    ... code that writes the content of buffer to shared memory or whatever
}
相关问题