diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2012-07-22 17:41:19 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2012-07-22 17:41:19 +0000 |
commit | 60375dcc5d9c24b5919f66f63ac70879e653c350 (patch) | |
tree | 5d5734278407c48ed17c0a8e0e951d45ee24ec1e /apps/modbus/nuttx/portother.c | |
parent | 107fe46fc6359ec1b5169c960fa8bd4fc619b23b (diff) | |
download | px4-nuttx-60375dcc5d9c24b5919f66f63ac70879e653c350.tar.gz px4-nuttx-60375dcc5d9c24b5919f66f63ac70879e653c350.tar.bz2 px4-nuttx-60375dcc5d9c24b5919f66f63ac70879e653c350.zip |
Don't use strerror in apps/modbus; Add CONFIG_MB_TERMIOS to enable/suppress use of termios.h interfaces
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@4968 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'apps/modbus/nuttx/portother.c')
-rw-r--r-- | apps/modbus/nuttx/portother.c | 62 |
1 files changed, 32 insertions, 30 deletions
diff --git a/apps/modbus/nuttx/portother.c b/apps/modbus/nuttx/portother.c index 12f79defe..fef826760 100644 --- a/apps/modbus/nuttx/portother.c +++ b/apps/modbus/nuttx/portother.c @@ -22,6 +22,7 @@ */ /* ----------------------- Standard includes --------------------------------*/ + #include <nuttx/config.h> #include <stdio.h> #include <stdlib.h> @@ -33,72 +34,73 @@ #include "port.h" /* ----------------------- Modbus includes ----------------------------------*/ + #include <apps/modbus/mb.h> #include <apps/modbus/mbport.h> /* ----------------------- Defines ------------------------------------------*/ -#define NELEMS( x ) ( sizeof( ( x ) )/sizeof( ( x )[0] ) ) + +#define NELEMS(x) (sizeof((x))/sizeof((x)[0])) /* ----------------------- Static variables ---------------------------------*/ + static FILE *fLogFile = NULL; static eMBPortLogLevel eLevelMax = MB_LOG_DEBUG; static pthread_mutex_t xLock = PTHREAD_MUTEX_INITIALIZER; /* ----------------------- Start implementation -----------------------------*/ -void -vMBPortLogLevel( eMBPortLogLevel eNewLevelMax ) + +void vMBPortLogLevel(eMBPortLogLevel eNewLevelMax) { - eLevelMax = eNewLevelMax; + eLevelMax = eNewLevelMax; } -void -vMBPortLogFile( FILE * fNewLogFile ) +void vMBPortLogFile(FILE * fNewLogFile) { - fLogFile = fNewLogFile; + fLogFile = fNewLogFile; } -void -vMBPortLog( eMBPortLogLevel eLevel, const char * szModule, const char * szFmt, ... ) +void vMBPortLog(eMBPortLogLevel eLevel, const char * szModule, const char * szFmt, ...) { - char szBuf[512]; - int i; - va_list args; - FILE *fOutput = fLogFile == NULL ? stderr : fLogFile; + char szBuf[512]; + int i; + va_list args; + FILE *fOutput = fLogFile == NULL ? stderr : fLogFile; - static const char *arszLevel2Str[] = { "ERROR", "WARN", "INFO", "DEBUG" }; + static const char *arszLevel2Str[] = { "ERROR", "WARN", "INFO", "DEBUG" }; - i = snprintf( szBuf, NELEMS( szBuf ), "%s: %s: ", arszLevel2Str[eLevel], szModule ); + i = snprintf(szBuf, NELEMS(szBuf), "%s: %s: ", arszLevel2Str[eLevel], szModule); - if( i != 0 ) + if (i != 0) { - va_start( args, szFmt ); - i += vsnprintf( &szBuf[i], NELEMS( szBuf ) - i, szFmt, args ); - va_end( args ); + va_start(args, szFmt); + i += vsnprintf(&szBuf[i], NELEMS(szBuf) - i, szFmt, args); + va_end(args); } - if( i != 0 ) + if (i != 0) { - if( eLevel <= eLevelMax ) + if (eLevel <= eLevelMax) { - fputs( szBuf, fOutput ); + fputs(szBuf, fOutput); } } } -void -vMBPortEnterCritical( void ) +void vMBPortEnterCritical(void) { - if( pthread_mutex_lock( &xLock ) != 0 ) + int ret = pthread_mutex_lock(&xLock); + if (ret != 0) { - vMBPortLog( MB_LOG_ERROR, "OTHER", "Locking primitive failed: %s\n", strerror( errno ) ); + vMBPortLog(MB_LOG_ERROR, "OTHER", "Locking primitive failed: %d\n", ret); } } -void -vMBPortExitCritical( void ) +void vMBPortExitCritical(void) { - if( pthread_mutex_unlock( &xLock ) != 0 ) + int ret = pthread_mutex_unlock(&xLock); + if (ret != 0) { - vMBPortLog( MB_LOG_ERROR, "OTHER", "Locking primitive failed: %s\n", strerror( errno ) ); + vMBPortLog(MB_LOG_ERROR, "OTHER", "Locking primitive failed: %d\n", ret); } } |