Andrew Boyson
/
iot
Backing up an unused program in case of future need
Diff: log.cpp
- Revision:
- 4:e076884ef8bd
- Parent:
- 2:06fa34661f19
- Child:
- 6:be97d38e0b01
--- a/log.cpp Sat Apr 23 20:00:04 2016 +0000 +++ b/log.cpp Tue May 03 09:23:26 2016 +0000 @@ -70,20 +70,17 @@ void LogF(char *fmt, ...) { //Set up variable arguments - uint32_t now = TimeGet(); va_list argptr; va_start(argptr, fmt); //Find the size required - int sizeTime = snprintf(NULL, 0, DATE_FORMAT, now); - int sizeLog = vsnprintf(NULL, 0, fmt, argptr); + int size = vsnprintf(NULL, 0, fmt, argptr); //Allocate enough memory for the size required with an extra byte for the terminating null - char snd[sizeTime + sizeLog + 1]; + char snd[size + 1]; //Fill the new buffer - sprintf(snd, DATE_FORMAT, now); - vsprintf(snd + sizeTime, fmt, argptr); + vsprintf(snd, fmt, argptr); //Finish with variable arguments va_end(argptr); @@ -92,6 +89,14 @@ for (char* ptr = snd; *ptr; ptr++) LogPush(*ptr); } +void LogTime() +{ + uint32_t now = TimeGet(); + int size = snprintf(NULL, 0, DATE_FORMAT, now); + char snd[size + 1]; + sprintf(snd, DATE_FORMAT, now); + for (char* ptr = snd; *ptr; ptr++) LogPush(*ptr); +} void LogCrLf (char * text) { LogF("%s\r\n", text);