2014-10-30 113 views
0

我的日志记录功能在这里,我们已经共享内存工作在一个嵌入式项目的Vxworks在C.定向输出到标准输出和共享内存

,我们写日志和其他设备读取。

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

感谢您的时间和投入。

+0

使用'vprintf'系列的函数来创建自己的'myprintf'函数。然后用'myprintf'替换所有'printf'。在'myprintf'中,你写入标准输出和任何文件,共享内存....等。 – 2014-10-30 13:12:31

+0

@Michel Walz。我正在使用现有的项目。问题是我无法替换所有现有的printf。例如,我想了解如何使用Vxworks API重定向输出。顺便提及“使用vprintf家族函数的myprintf函数”请求,以在此处给出示例或任何适合初学者的链接。谢谢 – venkysmarty 2014-10-30 13:26:32

+0

看到我的答案'myprintf'的实现。为什么用'myprintf'替换'printf'是个问题? – 2014-10-30 13:35:01

回答

3

myprintf替换全部printf s(下面的实施例)。

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 
} 
相关问题