2014-10-30 116 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 
} 
相關問題