diff options
author | Thomas Doerfler <Thomas.Doerfler@embedded-brains.de> | 2008-10-10 15:56:32 +0000 |
---|---|---|
committer | Thomas Doerfler <Thomas.Doerfler@embedded-brains.de> | 2008-10-10 15:56:32 +0000 |
commit | 06c3530efcc3cd4230278e150a0b828359982ca0 (patch) | |
tree | 580801d390e34d1ead99dcea1c06520539002306 /cpukit | |
parent | Update for status-checks.h changes. (diff) | |
download | rtems-06c3530efcc3cd4230278e150a0b828359982ca0.tar.bz2 |
libnetworking/rtems/rtems_glue.c: Copy nothing if rtems_bsdnet_parse_driver_name() if namep is NULL.
include/rtems/status-checks.h: Added prefix "RTEMS" for all macros. Doxygen style comments. Cleanup.
Diffstat (limited to 'cpukit')
-rw-r--r-- | cpukit/ChangeLog | 8 | ||||
-rw-r--r-- | cpukit/include/rtems/status-checks.h | 322 | ||||
-rw-r--r-- | cpukit/libnetworking/rtems/rtems_glue.c | 26 |
3 files changed, 262 insertions, 94 deletions
diff --git a/cpukit/ChangeLog b/cpukit/ChangeLog index 0dd2202a95..e04becd92f 100644 --- a/cpukit/ChangeLog +++ b/cpukit/ChangeLog @@ -15,6 +15,14 @@ * libcsupport/src/newlibc_exit.c: For some odd reason, the fini symbol for the m32r in C needs an extra leading _. +2008-10-02 Sebastian Huber <sebastian.huber@embedded-brains.de> + + * libnetworking/rtems/rtems_glue.c: Copy nothing in + rtems_bsdnet_parse_driver_name() if namep is NULL. + + * include/rtems/status-checks.h: Added prefix "RTEMS" for all macros. + Doxygen style comments. Cleanup. + 2008-10-02 Joel Sherrill <joel.sherrill@oarcorp.com> * score/cpu/Makefile.am: Add new M32R port. It is just a beginning but diff --git a/cpukit/include/rtems/status-checks.h b/cpukit/include/rtems/status-checks.h index 1face9488e..bb924e8b07 100644 --- a/cpukit/include/rtems/status-checks.h +++ b/cpukit/include/rtems/status-checks.h @@ -2,6 +2,9 @@ * @file * * @brief Header file for status checks. + * + * @warning Do not include this file in other header files. Use it only in + * source files. */ /* @@ -23,169 +26,318 @@ extern "C" { #endif /* __cplusplus */ +/** + * @defgroup rtems_status_checks Status Checks + * + * @{ + */ + +/** + * @name Print Macros + * + * @{ + */ + +/** + * @brief General purpose debug print macro. + */ #ifdef DEBUG - #ifndef DEBUG_PRINT + #ifndef RTEMS_DEBUG_PRINT #ifdef RTEMS_STATUS_CHECKS_USE_PRINTK - #define DEBUG_PRINT( fmt, ...) \ + #define RTEMS_DEBUG_PRINT( fmt, ...) \ printk( "%s: " fmt, __func__, ##__VA_ARGS__) #else /* RTEMS_STATUS_CHECKS_USE_PRINTK */ - #define DEBUG_PRINT( fmt, ...) \ + #include <stdio.h> + #define RTEMS_DEBUG_PRINT( fmt, ...) \ printf( "%s: " fmt, __func__, ##__VA_ARGS__) #endif /* RTEMS_STATUS_CHECKS_USE_PRINTK */ - #endif /* DEBUG_PRINT */ + #endif /* RTEMS_DEBUG_PRINT */ #else /* DEBUG */ - #ifdef DEBUG_PRINT - #warning DEBUG_PRINT was defined, but DEBUG was undefined - #undef DEBUG_PRINT - #endif /* DEBUG_PRINT */ - #define DEBUG_PRINT( fmt, ...) + #ifdef RTEMS_DEBUG_PRINT + #warning RTEMS_DEBUG_PRINT was defined, but DEBUG was undefined + #undef RTEMS_DEBUG_PRINT + #endif /* RTEMS_DEBUG_PRINT */ + #define RTEMS_DEBUG_PRINT( fmt, ...) #endif /* DEBUG */ -#ifndef SYSLOG_PRINT +/** + * @brief Macro to print debug messages for successful operations. + */ +#define RTEMS_DEBUG_OK( msg) \ + RTEMS_DEBUG_PRINT( "Ok: %s\n", msg) + +/** + * @brief General purpose system log print macro. + */ +#ifndef RTEMS_SYSLOG_PRINT #ifdef RTEMS_STATUS_CHECKS_USE_PRINTK - #define SYSLOG_PRINT( fmt, ...) \ + #define RTEMS_SYSLOG_PRINT( fmt, ...) \ printk( fmt, ##__VA_ARGS__) #else /* RTEMS_STATUS_CHECKS_USE_PRINTK */ - #define SYSLOG_PRINT( fmt, ...) \ + #include <stdio.h> + #define RTEMS_SYSLOG_PRINT( fmt, ...) \ printf( fmt, ##__VA_ARGS__) #endif /* RTEMS_STATUS_CHECKS_USE_PRINTK */ -#endif /* SYSLOG_PRINT */ +#endif /* RTEMS_SYSLOG_PRINT */ -#define SYSLOG( fmt, ...) \ - SYSLOG_PRINT( "%s: " fmt, __func__, ##__VA_ARGS__) +/** + * @brief General purpose system log macro. + */ +#define RTEMS_SYSLOG( fmt, ...) \ + RTEMS_SYSLOG_PRINT( "%s: " fmt, __func__, ##__VA_ARGS__) -#define SYSLOG_WARNING( fmt, ...) \ - SYSLOG_PRINT( "%s: Warning: " fmt, __func__, ##__VA_ARGS__) +/** + * @brief General purpose system log macro for warnings. + */ +#define RTEMS_SYSLOG_WARNING( fmt, ...) \ + RTEMS_SYSLOG( "Warning: " fmt, ##__VA_ARGS__) -#define SYSLOG_WARNING_SC( sc, fmt, ...) \ - if ((sc) != RTEMS_SUCCESSFUL) { \ - SYSLOG_PRINT( "%s: Warning: SC = %i: " fmt "\n", \ - __func__, sc, ##__VA_ARGS__); \ +/** + * @brief Macro to generate a system log warning message if the status code @a + * sc is not equal to @ref RTEMS_SUCCESSFUL. + */ +#define RTEMS_SYSLOG_WARNING_SC( sc, msg) \ + if ((rtems_status_code) (sc) != RTEMS_SUCCESSFUL) { \ + RTEMS_SYSLOG_WARNING( "SC = %i: %s\n", (int) sc, msg); \ } -#define SYSLOG_ERROR( fmt, ...) \ - SYSLOG_PRINT( "%s: Error: " fmt, __func__, ##__VA_ARGS__) +/** + * @brief General purpose system log macro for errors. + */ +#define RTEMS_SYSLOG_ERROR( fmt, ...) \ + RTEMS_SYSLOG( "Error: " fmt, ##__VA_ARGS__) + +/** + * @brief Macro for system log error messages with status code. + */ +#define RTEMS_SYSLOG_ERROR_WITH_SC( sc, msg) \ + RTEMS_SYSLOG_ERROR( "SC = %i: %s\n", (int) sc, msg); + +/** + * @brief Macro for system log error messages with return value. + */ +#define RTEMS_SYSLOG_ERROR_WITH_RV( rv, msg) \ + RTEMS_SYSLOG_ERROR( "RV = %i: %s\n", (int) rv, msg); + +/** + * @brief Macro to generate a system log error message if the status code @a + * sc is not equal to @ref RTEMS_SUCCESSFUL. + */ +#define RTEMS_SYSLOG_ERROR_SC( sc, msg) \ + if ((rtems_status_code) (sc) != RTEMS_SUCCESSFUL) { \ + RTEMS_SYSLOG_ERROR_WITH_SC( sc, msg); \ + } -#define SYSLOG_ERROR_SC( sc, fmt, ...) \ - if ((sc) != RTEMS_SUCCESSFUL) { \ - SYSLOG_PRINT( "%s: Error: SC = %i: " fmt "\n", \ - __func__, sc, ##__VA_ARGS__); \ +/** + * @brief Macro to generate a system log error message if the return value @a + * rv is less than zero. + */ +#define RTEMS_SYSLOG_ERROR_RV( rv, msg) \ + if ((int) (rv) < 0) { \ + RTEMS_SYSLOG_ERROR_WITH_RV( rv, msg); \ } -#define CHECK_SC( sc, hint ) \ - if ((sc) != RTEMS_SUCCESSFUL) { \ - SYSLOG_ERROR( "SC = %i: %s\n", sc, hint ); \ - return sc; \ +/** @} */ + +/** + * @name Check Macros + * + * @{ + */ + +/** + * @brief Prints message @a msg and returns with status code @a sc if the status + * code @a sc is not equal to @ref RTEMS_SUCCESSFUL. + */ +#define RTEMS_CHECK_SC( sc, msg) \ + if ((rtems_status_code) (sc) != RTEMS_SUCCESSFUL) { \ + RTEMS_SYSLOG_ERROR_WITH_SC( sc, msg); \ + return (rtems_status_code) sc; \ } else { \ - DEBUG_PRINT( "Ok: %s\n", hint ); \ + RTEMS_DEBUG_OK( msg); \ } -#define CHECK_SCRV( sc, hint ) \ - if ((sc) != RTEMS_SUCCESSFUL) { \ - SYSLOG_ERROR( "SC = %i: %s\n", sc, hint ); \ +/** + * @brief Prints message @a msg and returns with a return value of negative @a sc + * if the status code @a sc is not equal to @ref RTEMS_SUCCESSFUL. + */ +#define RTEMS_CHECK_SC_RV( sc, msg) \ + if ((rtems_status_code) (sc) != RTEMS_SUCCESSFUL) { \ + RTEMS_SYSLOG_ERROR_WITH_SC( sc, msg); \ return -((int) (sc)); \ } else { \ - DEBUG_PRINT( "Ok: %s\n", hint ); \ + RTEMS_DEBUG_OK( msg); \ } -#define CHECK_SC_VOID( sc, hint ) \ - if ((sc) != RTEMS_SUCCESSFUL) { \ - SYSLOG_ERROR( "SC = %i: %s\n", sc, hint ); \ +/** + * @brief Prints message @a msg and returns if the status code @a sc is not equal + * to @ref RTEMS_SUCCESSFUL. + */ +#define RTEMS_CHECK_SC_VOID( sc, msg) \ + if ((rtems_status_code) (sc) != RTEMS_SUCCESSFUL) { \ + RTEMS_SYSLOG_ERROR_WITH_SC( sc, msg); \ return; \ } else { \ - DEBUG_PRINT( "Ok: %s\n", hint ); \ + RTEMS_DEBUG_OK( msg); \ } -#define CHECK_SC_TASK( sc, hint ) \ - if ((sc) != RTEMS_SUCCESSFUL) { \ - SYSLOG_ERROR( "SC = %i: %s\n", sc, hint ); \ - rtems_task_delete( RTEMS_SELF); \ +/** + * @brief Prints message @a msg and delete the current task if the status code + * @a sc is not equal to @ref RTEMS_SUCCESSFUL. + */ +#define RTEMS_CHECK_SC_TASK( sc, msg) \ + if ((rtems_status_code) (sc) != RTEMS_SUCCESSFUL) { \ + RTEMS_SYSLOG_ERROR_WITH_SC( sc, msg); \ + (void) rtems_task_delete( RTEMS_SELF); \ return; \ } else { \ - DEBUG_PRINT( "Ok: %s\n", hint ); \ + RTEMS_DEBUG_OK( msg); \ } -#define CHECK_RV( rv, hint ) \ - if ((rv) < 0) { \ - SYSLOG_ERROR( "RV = %i: %s\n", rv, hint ); \ - return rv; \ +/** + * @brief Prints message @a msg and returns with a return value @a rv if the + * return value @a rv is less than zero. + */ +#define RTEMS_CHECK_RV( rv, msg) \ + if ((int) (rv) < 0) { \ + RTEMS_SYSLOG_ERROR_WITH_RV( rv, msg); \ + return (int) rv; \ } else { \ - DEBUG_PRINT( "Ok: %s\n", hint ); \ + RTEMS_DEBUG_OK( msg); \ } -#define CHECK_RVSC( rv, hint ) \ - if ((rv) < 0) { \ - SYSLOG_ERROR( "RV = %i: %s\n", rv, hint ); \ +/** + * @brief Prints message @a msg and returns with status code @ref RTEMS_IO_ERROR + * if the return value @a rv is less than zero. + */ +#define RTEMS_CHECK_RV_SC( rv, msg) \ + if ((int) (rv) < 0) { \ + RTEMS_SYSLOG_ERROR_WITH_RV( rv, msg); \ return RTEMS_IO_ERROR; \ } else { \ - DEBUG_PRINT( "Ok: %s\n", hint ); \ + RTEMS_DEBUG_OK( msg); \ } -#define CHECK_RV_VOID( rv, hint ) \ - if ((rv) < 0) { \ - SYSLOG_ERROR( "RV = %i: %s\n", rv, hint ); \ +/** + * @brief Prints message @a msg and returns if the return value @a rv is less + * than zero. + */ +#define RTEMS_CHECK_RV_VOID( rv, msg) \ + if ((int) (rv) < 0) { \ + RTEMS_SYSLOG_ERROR_WITH_RV( rv, msg); \ return; \ } else { \ - DEBUG_PRINT( "Ok: %s\n", hint ); \ + RTEMS_DEBUG_OK( msg); \ } -#define CHECK_RV_TASK( rv, hint ) \ - if ((rv) < 0) { \ - SYSLOG_ERROR( "RV = %i: %s\n", rv, hint ); \ - rtems_task_delete( RTEMS_SELF); \ +/** + * @brief Prints message @a msg and delete the current task if the return value + * @a rv is less than zero. + */ +#define RTEMS_CHECK_RV_TASK( rv, msg) \ + if ((int) (rv) < 0) { \ + RTEMS_SYSLOG_ERROR_WITH_RV( rv, msg); \ + (void) rtems_task_delete( RTEMS_SELF); \ return; \ } else { \ - DEBUG_PRINT( "Ok: %s\n", hint ); \ + RTEMS_DEBUG_OK( msg); \ } -#define CLEANUP_SC( sc, label, hint ) \ - if ((sc) != RTEMS_SUCCESSFUL) { \ - SYSLOG_ERROR( "SC = %i: %s\n", sc, hint ); \ +/** @} */ + +/** + * @name Cleanup Macros + * + * @{ + */ + +/** + * @brief Prints message @a msg and jumps to @a label if the status code @a sc + * is not equal to @ref RTEMS_SUCCESSFUL. + */ +#define RTEMS_CLEANUP_SC( sc, label, msg) \ + if ((rtems_status_code) (sc) != RTEMS_SUCCESSFUL) { \ + RTEMS_SYSLOG_ERROR_WITH_SC( sc, msg); \ goto label; \ } else { \ - DEBUG_PRINT( "Ok: %s\n", hint ); \ + RTEMS_DEBUG_OK( msg); \ } -#define CLEANUP_SCRV( sc, rv, label, hint ) \ - if ((sc) != RTEMS_SUCCESSFUL) { \ - SYSLOG_ERROR( "SC = %i: %s\n", sc, hint ); \ +/** + * @brief Prints message @a msg and jumps to @a label if the status code @a sc + * is not equal to @ref RTEMS_SUCCESSFUL. The return value variable @a rv will + * be set to a negative @a sc in this case. + */ +#define RTEMS_CLEANUP_SC_RV( sc, rv, label, msg) \ + if ((rtems_status_code) (sc) != RTEMS_SUCCESSFUL) { \ + RTEMS_SYSLOG_ERROR_WITH_SC( sc, msg); \ rv = -((int) (sc)); \ goto label; \ } else { \ - DEBUG_PRINT( "Ok: %s\n", hint ); \ + RTEMS_DEBUG_OK( msg); \ } -#define CLEANUP_RV( rv, label, hint ) \ - if ((rv) < 0) { \ - SYSLOG_ERROR( "RV = %i: %s\n", rv, hint ); \ +/** + * @brief Prints message @a msg and jumps to @a label if the return value @a rv + * is less than zero. + */ +#define RTEMS_CLEANUP_RV( rv, label, msg) \ + if ((int) (rv) < 0) { \ + RTEMS_SYSLOG_ERROR_WITH_RV( rv, msg); \ goto label; \ } else { \ - DEBUG_PRINT( "Ok: %s\n", hint ); \ + RTEMS_DEBUG_OK( msg); \ } -#define CLEANUP_RVSC( rv, sc, label, hint ) \ - if ((rv) < 0) { \ - SYSLOG_ERROR( "RV = %i: %s\n", rv, hint ); \ +/** + * @brief Prints message @a msg and jumps to @a label if the return value @a rv + * is less than zero. The status code variable @a sc will be set to @ref + * RTEMS_IO_ERROR in this case. + */ +#define RTEMS_CLEANUP_RV_SC( rv, sc, label, msg) \ + if ((int) (rv) < 0) { \ + RTEMS_SYSLOG_ERROR_WITH_RV( rv, msg); \ sc = RTEMS_IO_ERROR; \ goto label; \ } else { \ - DEBUG_PRINT( "Ok: %s\n", hint ); \ + RTEMS_DEBUG_OK( msg); \ } -#define DO_CLEANUP_SC( val, sc, label, hint ) \ +/** + * @brief Prints message @a msg and jumps to @a label. + */ +#define RTEMS_DO_CLEANUP( label, msg) \ + do { \ + RTEMS_SYSLOG_ERROR( msg); \ + goto label; \ + } while (0) + +/** + * @brief Prints message @a msg, sets the status code variable @a sc to @a val + * and jumps to @a label. + */ +#define RTEMS_DO_CLEANUP_SC( val, sc, label, msg) \ do { \ - sc = val; \ - SYSLOG_ERROR( "SC = %i: %s\n", sc, hint ); \ + sc = (rtems_status_code) val; \ + RTEMS_SYSLOG_ERROR_WITH_SC( sc, msg); \ goto label; \ } while (0) -#define DO_CLEANUP_RV( val, rv, label, hint ) \ +/** + * @brief Prints message @a msg, sets the return value variable @a rv to @a val + * and jumps to @a label. + */ +#define RTEMS_DO_CLEANUP_RV( val, rv, label, msg) \ do { \ - rv = val; \ - SYSLOG_ERROR( "RV = %i: %s\n", rv, hint ); \ + rv = (int) val; \ + RTEMS_SYSLOG_ERROR_WITH_RV( rv, msg); \ goto label; \ } while (0) +/** @} */ + +/** @} */ + #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/cpukit/libnetworking/rtems/rtems_glue.c b/cpukit/libnetworking/rtems/rtems_glue.c index 07e70e5c39..d3d589c166 100644 --- a/cpukit/libnetworking/rtems/rtems_glue.c +++ b/cpukit/libnetworking/rtems/rtems_glue.c @@ -1148,8 +1148,14 @@ int rtems_bsdnet_ifconfig(const char *ifname, uint32_t cmd, void *param) return r; } -/* - * Parse a network driver name into a name and a unit number +/** + * @brief Splits a network interface name with interface configuration @a + * config into the unit name and number parts. + * + * Memory for the unit name will be allocated from the heap and copied to @a + * namep. If @a namep is NULL nothing will be allocated and copied. + * + * Returns the unit number or -1 on error. */ int rtems_bsdnet_parse_driver_name (const struct rtems_bsdnet_ifconfig *config, char **namep) @@ -1171,14 +1177,16 @@ rtems_bsdnet_parse_driver_name (const struct rtems_bsdnet_ifconfig *config, char unitNumber = (unitNumber * 10) + (c - '0'); c = *cp++; if (c == '\0') { - char *unitName = malloc (len); - if (unitName == NULL) { - printf ("No memory.\n"); - return -1; + if (namep != NULL) { + char *unitName = malloc (len); + if (unitName == NULL) { + printf ("No memory.\n"); + return -1; + } + strncpy (unitName, config->name, len - 1); + unitName[len-1] = '\0'; + *namep = unitName; } - strncpy (unitName, config->name, len - 1); - unitName[len-1] = '\0'; - *namep = unitName; return unitNumber; } if ((c < '0') || (c > '9')) |