From d19294499c255dd6bd883f4fbf5a5a0450dc4e0c Mon Sep 17 00:00:00 2001 From: Jeff Hill Date: Fri, 10 Aug 2001 00:45:53 +0000 Subject: [PATCH] fixed strftime formating --- src/libCom/osi/epicsTime.cpp | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/src/libCom/osi/epicsTime.cpp b/src/libCom/osi/epicsTime.cpp index bb1d352fa..fdb5f40ba 100644 --- a/src/libCom/osi/epicsTime.cpp +++ b/src/libCom/osi/epicsTime.cpp @@ -378,13 +378,24 @@ static char *fracFormat (const char *pFormat, unsigned long *width) // point at char past format string const char *ptr = pFormat + strlen (pFormat); + // allow trailing ws + while (isspace (*(--ptr))); + // if (last) char not 'f', no match - if (*(--ptr) != 'f') return NULL; + if (*ptr != 'f') return NULL; + + // look for %f + if ( *(ptr-1) == '%' ) { + *width = 9; + return (char *) (ptr-1); + } // skip digits, extracting (must start with 0) while (isdigit (*(--ptr))); // NB, empty loop body + if (*ptr != '%') { + return NULL; + } ++ptr; // points to first digit, if any - if (*ptr != '0') return NULL; if (sscanf (ptr, "%lu", width) != 1) return NULL; // if (prev) char not '%', no match @@ -397,8 +408,19 @@ static char *fracFormat (const char *pFormat, unsigned long *width) // // size_t epicsTime::strftime (char *pBuff, size_t bufLength, const char *pFormat) // -size_t epicsTime::strftime (char *pBuff, size_t bufLength, const char *pFormat) const +size_t epicsTime::strftime ( char *pBuff, size_t bufLength, const char *pFormat ) const { + if ( bufLength == 0u ) { + return 0u; + } + + // dont report EPOCH date if its an uninitialized time stamp + if ( this->secPastEpoch == 0 && this->nSec == 0u ) { + strncpy ( pBuff, "", bufLength ); + pBuff[bufLength-1] = '\0'; + return strlen ( pBuff ); + } + // copy format (needs to be writable) char format[256]; strcpy (format, pFormat);