correct va_list usage (#686)

This commit is contained in:
Buke Po
2016-09-26 10:00:50 -07:00
committed by Jonathan Hui
parent 96af368981
commit d20d54a394
4 changed files with 27 additions and 8 deletions
+11 -5
View File
@@ -179,6 +179,15 @@ int Uart::OutputFormat(const char *fmt, ...)
return Output(buf, static_cast<uint16_t>(strlen(buf)));
}
int Uart::OutputFormatV(const char *aFmt, va_list aAp)
{
char buf[kMaxLineLength];
vsnprintf(buf, sizeof(buf), aFmt, aAp);
return Output(buf, static_cast<uint16_t>(strlen(buf)));
}
void Uart::Send(void)
{
VerifyOrExit(mSendLength == 0, ;);
@@ -219,7 +228,7 @@ void Uart::SendDoneTask(void)
#ifdef __cplusplus
extern "C" {
#endif
void otCliLog(otLogLevel aLogLevel, otLogRegion aLogRegion, const char *aFormat, ...)
void otCliLog(otLogLevel aLogLevel, otLogRegion aLogRegion, const char *aFormat, va_list aAp)
{
if (NULL == Uart::sUartServer)
{
@@ -298,10 +307,7 @@ void otCliLog(otLogLevel aLogLevel, otLogRegion aLogRegion, const char *aFormat,
return;
}
va_list args;
va_start(args, aFormat);
Uart::sUartServer->OutputFormat(aFormat, args);
va_end(args);
Uart::sUartServer->OutputFormatV(aFormat, aAp);
}
#ifdef __cplusplus
} // extern "C"
+11
View File
@@ -78,6 +78,17 @@ public:
*/
int OutputFormat(const char *fmt, ...);
/**
* This method delivers formatted output to the client.
*
* @param[in] aFmt A pointer to the format string.
* @param[in] aAp A variable list of arguments for format.
*
* @returns The number of bytes placed in the output queue.
*
*/
int OutputFormatV(const char *aFmt, va_list aAp);
void ReceiveTask(const uint8_t *aBuf, uint16_t aBufLength);
void SendDoneTask(void);