From 2bb02e732aa0131f5661a06c9babe00e3466d79d Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Tue, 28 Feb 2017 20:06:42 -0600 Subject: [PATCH] libCom: add errSymMsg() error message lookup Like errSymLookup() but always returns a static string. --- src/libCom/error/errMdef.h | 1 + src/libCom/error/errSymLib.c | 38 ++++++++++++++++++++++++------------ 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/src/libCom/error/errMdef.h b/src/libCom/error/errMdef.h index e511d912b..163b063f2 100644 --- a/src/libCom/error/errMdef.h +++ b/src/libCom/error/errMdef.h @@ -53,6 +53,7 @@ extern "C" { #define M_time (529 <<16) /*epicsTime*/ epicsShareFunc void epicsShareAPI errSymLookup(long status, char *pBuf, unsigned bufLength); +epicsShareFunc const char* errSymMsg(long status); epicsShareFunc void epicsShareAPI errSymTest(unsigned short modnum, unsigned short begErrNum, unsigned short endErrNum); epicsShareFunc void epicsShareAPI errSymTestPrint(long errNum); epicsShareFunc int epicsShareAPI errSymBld(void); diff --git a/src/libCom/error/errSymLib.c b/src/libCom/error/errSymLib.c index f75577b23..74d766810 100644 --- a/src/libCom/error/errSymLib.c +++ b/src/libCom/error/errSymLib.c @@ -192,11 +192,9 @@ static void errRawCopy ( long statusToDecode, char *pBuf, unsigned bufLength ) assert ( nChar < bufLength ); } } - -/**************************************************************** - * errSymLookup - ***************************************************************/ -void epicsShareAPI errSymLookup (long status, char * pBuf, unsigned bufLength) + +static +const char* errSymLookupInternal(long status) { unsigned modNum; unsigned hashInd; @@ -211,9 +209,7 @@ void epicsShareAPI errSymLookup (long status, char * pBuf, unsigned bufLength) if ( modNum <= 500 ) { const char * pStr = strerror ((int) status); if ( pStr ) { - strncpy(pBuf, pStr,bufLength); - pBuf[bufLength-1] = '\0'; - return; + return pStr; } } else { @@ -222,17 +218,35 @@ void epicsShareAPI errSymLookup (long status, char * pBuf, unsigned bufLength) pNextNode = *phashnode; while(pNextNode) { if(pNextNode->errNum==status){ - strncpy(pBuf, pNextNode->message, bufLength); - pBuf[bufLength-1] = '\0'; - return; + return pNextNode->message; } phashnode = &pNextNode->hashnode; pNextNode = *phashnode; } } + return NULL; +} + +const char* errSymMsg(long status) +{ + const char* msg = errSymLookupInternal(status); + return msg ? msg : ""; +} + +/**************************************************************** + * errSymLookup + ***************************************************************/ +void epicsShareAPI errSymLookup (long status, char * pBuf, unsigned bufLength) +{ + const char* msg = errSymLookupInternal(status); + if(msg) { + strncpy(pBuf, msg, bufLength); + pBuf[bufLength-1] = '\0'; + return; + } errRawCopy(status, pBuf, bufLength); } - + /**************************************************************** * errSymDump ***************************************************************/