Changeset 06c3530 in rtems


Ignore:
Timestamp:
Oct 10, 2008, 3:56:32 PM (11 years ago)
Author:
Thomas Doerfler <Thomas.Doerfler@…>
Branches:
4.10, 4.11, master
Children:
0846740
Parents:
f049983
Message:

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.

Location:
cpukit
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • cpukit/ChangeLog

    rf049983 r06c3530  
    1515        * libcsupport/src/newlibc_exit.c: For some odd reason, the fini
    1616        symbol for the m32r in C needs an extra leading _.
     17
     182008-10-02      Sebastian Huber <sebastian.huber@embedded-brains.de>
     19
     20        * libnetworking/rtems/rtems_glue.c: Copy nothing in
     21        rtems_bsdnet_parse_driver_name() if namep is NULL.
     22
     23        * include/rtems/status-checks.h: Added prefix "RTEMS" for all macros.
     24        Doxygen style comments.  Cleanup.
    1725
    18262008-10-02      Joel Sherrill <joel.sherrill@oarcorp.com>
  • cpukit/include/rtems/status-checks.h

    rf049983 r06c3530  
    33 *
    44 * @brief Header file for status checks.
     5 *
     6 * @warning Do not include this file in other header files.  Use it only in
     7 * source files.
    58 */
    69
     
    2427#endif /* __cplusplus */
    2528
     29/**
     30 * @defgroup rtems_status_checks Status Checks
     31 *
     32 * @{
     33 */
     34
     35/**
     36 * @name Print Macros
     37 *
     38 * @{
     39 */
     40
     41/**
     42 * @brief General purpose debug print macro.
     43 */
    2644#ifdef DEBUG
    27   #ifndef DEBUG_PRINT
     45  #ifndef RTEMS_DEBUG_PRINT
    2846    #ifdef RTEMS_STATUS_CHECKS_USE_PRINTK
    29       #define DEBUG_PRINT( fmt, ...) \
     47      #define RTEMS_DEBUG_PRINT( fmt, ...) \
    3048        printk( "%s: " fmt, __func__, ##__VA_ARGS__)
    3149    #else /* RTEMS_STATUS_CHECKS_USE_PRINTK */
    32       #define DEBUG_PRINT( fmt, ...) \
     50      #include <stdio.h>
     51      #define RTEMS_DEBUG_PRINT( fmt, ...) \
    3352        printf( "%s: " fmt, __func__, ##__VA_ARGS__)
    3453    #endif /* RTEMS_STATUS_CHECKS_USE_PRINTK */
    35   #endif /* DEBUG_PRINT */
     54  #endif /* RTEMS_DEBUG_PRINT */
    3655#else /* DEBUG */
    37   #ifdef DEBUG_PRINT
    38     #warning DEBUG_PRINT was defined, but DEBUG was undefined
    39     #undef DEBUG_PRINT
    40   #endif /* DEBUG_PRINT */
    41   #define DEBUG_PRINT( fmt, ...)
     56  #ifdef RTEMS_DEBUG_PRINT
     57    #warning RTEMS_DEBUG_PRINT was defined, but DEBUG was undefined
     58    #undef RTEMS_DEBUG_PRINT
     59  #endif /* RTEMS_DEBUG_PRINT */
     60  #define RTEMS_DEBUG_PRINT( fmt, ...)
    4261#endif /* DEBUG */
    4362
    44 #ifndef SYSLOG_PRINT
     63/**
     64 * @brief Macro to print debug messages for successful operations.
     65 */
     66#define RTEMS_DEBUG_OK( msg) \
     67  RTEMS_DEBUG_PRINT( "Ok: %s\n", msg)
     68
     69/**
     70 * @brief General purpose system log print macro.
     71 */
     72#ifndef RTEMS_SYSLOG_PRINT
    4573  #ifdef RTEMS_STATUS_CHECKS_USE_PRINTK
    46     #define SYSLOG_PRINT( fmt, ...) \
     74    #define RTEMS_SYSLOG_PRINT( fmt, ...) \
    4775      printk( fmt, ##__VA_ARGS__)
    4876  #else /* RTEMS_STATUS_CHECKS_USE_PRINTK */
    49     #define SYSLOG_PRINT( fmt, ...) \
     77    #include <stdio.h>
     78    #define RTEMS_SYSLOG_PRINT( fmt, ...) \
    5079      printf( fmt, ##__VA_ARGS__)
    5180  #endif /* RTEMS_STATUS_CHECKS_USE_PRINTK */
    52 #endif /* SYSLOG_PRINT */
    53 
    54 #define SYSLOG( fmt, ...) \
    55   SYSLOG_PRINT( "%s: " fmt, __func__, ##__VA_ARGS__)
    56 
    57 #define SYSLOG_WARNING( fmt, ...) \
    58   SYSLOG_PRINT( "%s: Warning: " fmt, __func__, ##__VA_ARGS__)
    59 
    60 #define SYSLOG_WARNING_SC( sc, fmt, ...) \
    61   if ((sc) != RTEMS_SUCCESSFUL) { \
    62     SYSLOG_PRINT( "%s: Warning: SC = %i: " fmt "\n", \
    63       __func__, sc, ##__VA_ARGS__); \
    64   }
    65 
    66 #define SYSLOG_ERROR( fmt, ...) \
    67   SYSLOG_PRINT( "%s: Error: " fmt, __func__, ##__VA_ARGS__)
    68 
    69 #define SYSLOG_ERROR_SC( sc, fmt, ...) \
    70   if ((sc) != RTEMS_SUCCESSFUL) { \
    71     SYSLOG_PRINT( "%s: Error: SC = %i: " fmt "\n", \
    72       __func__, sc, ##__VA_ARGS__); \
    73   }
    74 
    75 #define CHECK_SC( sc, hint ) \
    76   if ((sc) != RTEMS_SUCCESSFUL) { \
    77     SYSLOG_ERROR( "SC = %i: %s\n", sc, hint ); \
    78     return sc; \
    79   } else { \
    80     DEBUG_PRINT( "Ok: %s\n", hint ); \
    81   }
    82 
    83 #define CHECK_SCRV( sc, hint ) \
    84   if ((sc) != RTEMS_SUCCESSFUL) { \
    85     SYSLOG_ERROR( "SC = %i: %s\n", sc, hint ); \
     81#endif /* RTEMS_SYSLOG_PRINT */
     82
     83/**
     84 * @brief General purpose system log macro.
     85 */
     86#define RTEMS_SYSLOG( fmt, ...) \
     87  RTEMS_SYSLOG_PRINT( "%s: " fmt, __func__, ##__VA_ARGS__)
     88
     89/**
     90 * @brief General purpose system log macro for warnings.
     91 */
     92#define RTEMS_SYSLOG_WARNING( fmt, ...) \
     93  RTEMS_SYSLOG( "Warning: " fmt, ##__VA_ARGS__)
     94
     95/**
     96 * @brief Macro to generate a system log warning message if the status code @a
     97 * sc is not equal to @ref RTEMS_SUCCESSFUL.
     98 */
     99#define RTEMS_SYSLOG_WARNING_SC( sc, msg) \
     100  if ((rtems_status_code) (sc) != RTEMS_SUCCESSFUL) { \
     101    RTEMS_SYSLOG_WARNING( "SC = %i: %s\n", (int) sc, msg); \
     102  }
     103
     104/**
     105 * @brief General purpose system log macro for errors.
     106 */
     107#define RTEMS_SYSLOG_ERROR( fmt, ...) \
     108  RTEMS_SYSLOG( "Error: " fmt, ##__VA_ARGS__)
     109
     110/**
     111 * @brief Macro for system log error messages with status code.
     112 */
     113#define RTEMS_SYSLOG_ERROR_WITH_SC( sc, msg) \
     114  RTEMS_SYSLOG_ERROR( "SC = %i: %s\n", (int) sc, msg);
     115
     116/**
     117 * @brief Macro for system log error messages with return value.
     118 */
     119#define RTEMS_SYSLOG_ERROR_WITH_RV( rv, msg) \
     120  RTEMS_SYSLOG_ERROR( "RV = %i: %s\n", (int) rv, msg);
     121
     122/**
     123 * @brief Macro to generate a system log error message if the status code @a
     124 * sc is not equal to @ref RTEMS_SUCCESSFUL.
     125 */
     126#define RTEMS_SYSLOG_ERROR_SC( sc, msg) \
     127  if ((rtems_status_code) (sc) != RTEMS_SUCCESSFUL) { \
     128    RTEMS_SYSLOG_ERROR_WITH_SC( sc, msg); \
     129  }
     130
     131/**
     132 * @brief Macro to generate a system log error message if the return value @a
     133 * rv is less than zero.
     134 */
     135#define RTEMS_SYSLOG_ERROR_RV( rv, msg) \
     136  if ((int) (rv) < 0) { \
     137    RTEMS_SYSLOG_ERROR_WITH_RV( rv, msg); \
     138  }
     139
     140/** @} */
     141
     142/**
     143 * @name Check Macros
     144 *
     145 * @{
     146 */
     147
     148/**
     149 * @brief Prints message @a msg and returns with status code @a sc if the status
     150 * code @a sc is not equal to @ref RTEMS_SUCCESSFUL.
     151 */
     152#define RTEMS_CHECK_SC( sc, msg) \
     153  if ((rtems_status_code) (sc) != RTEMS_SUCCESSFUL) { \
     154    RTEMS_SYSLOG_ERROR_WITH_SC( sc, msg); \
     155    return (rtems_status_code) sc; \
     156  } else { \
     157    RTEMS_DEBUG_OK( msg); \
     158  }
     159
     160/**
     161 * @brief Prints message @a msg and returns with a return value of negative @a sc
     162 * if the status code @a sc is not equal to @ref RTEMS_SUCCESSFUL.
     163 */
     164#define RTEMS_CHECK_SC_RV( sc, msg) \
     165  if ((rtems_status_code) (sc) != RTEMS_SUCCESSFUL) { \
     166    RTEMS_SYSLOG_ERROR_WITH_SC( sc, msg); \
    86167    return -((int) (sc)); \
    87168  } else { \
    88     DEBUG_PRINT( "Ok: %s\n", hint ); \
    89   }
    90 
    91 #define CHECK_SC_VOID( sc, hint ) \
    92   if ((sc) != RTEMS_SUCCESSFUL) { \
    93     SYSLOG_ERROR( "SC = %i: %s\n", sc, hint ); \
     169    RTEMS_DEBUG_OK( msg); \
     170  }
     171
     172/**
     173 * @brief Prints message @a msg and returns if the status code @a sc is not equal
     174 * to @ref RTEMS_SUCCESSFUL.
     175 */
     176#define RTEMS_CHECK_SC_VOID( sc, msg) \
     177  if ((rtems_status_code) (sc) != RTEMS_SUCCESSFUL) { \
     178    RTEMS_SYSLOG_ERROR_WITH_SC( sc, msg); \
    94179    return; \
    95180  } else { \
    96     DEBUG_PRINT( "Ok: %s\n", hint ); \
    97   }
    98 
    99 #define CHECK_SC_TASK( sc, hint ) \
    100   if ((sc) != RTEMS_SUCCESSFUL) { \
    101     SYSLOG_ERROR( "SC = %i: %s\n", sc, hint ); \
    102     rtems_task_delete( RTEMS_SELF); \
     181    RTEMS_DEBUG_OK( msg); \
     182  }
     183
     184/**
     185 * @brief Prints message @a msg and delete the current task if the status code
     186 * @a sc is not equal to @ref RTEMS_SUCCESSFUL.
     187 */
     188#define RTEMS_CHECK_SC_TASK( sc, msg) \
     189  if ((rtems_status_code) (sc) != RTEMS_SUCCESSFUL) { \
     190    RTEMS_SYSLOG_ERROR_WITH_SC( sc, msg); \
     191    (void) rtems_task_delete( RTEMS_SELF); \
    103192    return; \
    104193  } else { \
    105     DEBUG_PRINT( "Ok: %s\n", hint ); \
    106   }
    107 
    108 #define CHECK_RV( rv, hint ) \
    109   if ((rv) < 0) { \
    110     SYSLOG_ERROR( "RV = %i: %s\n", rv, hint ); \
    111     return rv; \
    112   } else { \
    113     DEBUG_PRINT( "Ok: %s\n", hint ); \
    114   }
    115 
    116 #define CHECK_RVSC( rv, hint ) \
    117   if ((rv) < 0) { \
    118     SYSLOG_ERROR( "RV = %i: %s\n", rv, hint ); \
     194    RTEMS_DEBUG_OK( msg); \
     195  }
     196
     197/**
     198 * @brief Prints message @a msg and returns with a return value @a rv if the
     199 * return value @a rv is less than zero.
     200 */
     201#define RTEMS_CHECK_RV( rv, msg) \
     202  if ((int) (rv) < 0) { \
     203    RTEMS_SYSLOG_ERROR_WITH_RV( rv, msg); \
     204    return (int) rv; \
     205  } else { \
     206    RTEMS_DEBUG_OK( msg); \
     207  }
     208
     209/**
     210 * @brief Prints message @a msg and returns with status code @ref RTEMS_IO_ERROR
     211 * if the return value @a rv is less than zero.
     212 */
     213#define RTEMS_CHECK_RV_SC( rv, msg) \
     214  if ((int) (rv) < 0) { \
     215    RTEMS_SYSLOG_ERROR_WITH_RV( rv, msg); \
    119216    return RTEMS_IO_ERROR; \
    120217  } else { \
    121     DEBUG_PRINT( "Ok: %s\n", hint ); \
    122   }
    123 
    124 #define CHECK_RV_VOID( rv, hint ) \
    125   if ((rv) < 0) { \
    126     SYSLOG_ERROR( "RV = %i: %s\n", rv, hint ); \
     218    RTEMS_DEBUG_OK( msg); \
     219  }
     220
     221/**
     222 * @brief Prints message @a msg and returns if the return value @a rv is less
     223 * than zero.
     224 */
     225#define RTEMS_CHECK_RV_VOID( rv, msg) \
     226  if ((int) (rv) < 0) { \
     227    RTEMS_SYSLOG_ERROR_WITH_RV( rv, msg); \
    127228    return; \
    128229  } else { \
    129     DEBUG_PRINT( "Ok: %s\n", hint ); \
    130   }
    131 
    132 #define CHECK_RV_TASK( rv, hint ) \
    133   if ((rv) < 0) { \
    134     SYSLOG_ERROR( "RV = %i: %s\n", rv, hint ); \
    135     rtems_task_delete( RTEMS_SELF); \
     230    RTEMS_DEBUG_OK( msg); \
     231  }
     232
     233/**
     234 * @brief Prints message @a msg and delete the current task if the return value
     235 * @a rv is less than zero.
     236 */
     237#define RTEMS_CHECK_RV_TASK( rv, msg) \
     238  if ((int) (rv) < 0) { \
     239    RTEMS_SYSLOG_ERROR_WITH_RV( rv, msg); \
     240    (void) rtems_task_delete( RTEMS_SELF); \
    136241    return; \
    137242  } else { \
    138     DEBUG_PRINT( "Ok: %s\n", hint ); \
    139   }
    140 
    141 #define CLEANUP_SC( sc, label, hint ) \
    142   if ((sc) != RTEMS_SUCCESSFUL) { \
    143     SYSLOG_ERROR( "SC = %i: %s\n", sc, hint ); \
    144     goto label; \
    145   } else { \
    146     DEBUG_PRINT( "Ok: %s\n", hint ); \
    147   }
    148 
    149 #define CLEANUP_SCRV( sc, rv, label, hint ) \
    150   if ((sc) != RTEMS_SUCCESSFUL) { \
    151     SYSLOG_ERROR( "SC = %i: %s\n", sc, hint ); \
     243    RTEMS_DEBUG_OK( msg); \
     244  }
     245
     246/** @} */
     247
     248/**
     249 * @name Cleanup Macros
     250 *
     251 * @{
     252 */
     253
     254/**
     255 * @brief Prints message @a msg and jumps to @a label if the status code @a sc
     256 * is not equal to @ref RTEMS_SUCCESSFUL.
     257 */
     258#define RTEMS_CLEANUP_SC( sc, label, msg) \
     259  if ((rtems_status_code) (sc) != RTEMS_SUCCESSFUL) { \
     260    RTEMS_SYSLOG_ERROR_WITH_SC( sc, msg); \
     261    goto label; \
     262  } else { \
     263    RTEMS_DEBUG_OK( msg); \
     264  }
     265
     266/**
     267 * @brief Prints message @a msg and jumps to @a label if the status code @a sc
     268 * is not equal to @ref RTEMS_SUCCESSFUL.  The return value variable @a rv will
     269 * be set to a negative @a sc in this case.
     270 */
     271#define RTEMS_CLEANUP_SC_RV( sc, rv, label, msg) \
     272  if ((rtems_status_code) (sc) != RTEMS_SUCCESSFUL) { \
     273    RTEMS_SYSLOG_ERROR_WITH_SC( sc, msg); \
    152274    rv = -((int) (sc)); \
    153275    goto label; \
    154276  } else { \
    155     DEBUG_PRINT( "Ok: %s\n", hint ); \
    156   }
    157 
    158 #define CLEANUP_RV( rv, label, hint ) \
    159   if ((rv) < 0) { \
    160     SYSLOG_ERROR( "RV = %i: %s\n", rv, hint ); \
    161     goto label; \
    162   } else { \
    163     DEBUG_PRINT( "Ok: %s\n", hint ); \
    164   }
    165 
    166 #define CLEANUP_RVSC( rv, sc, label, hint ) \
    167   if ((rv) < 0) { \
    168     SYSLOG_ERROR( "RV = %i: %s\n", rv, hint ); \
     277    RTEMS_DEBUG_OK( msg); \
     278  }
     279
     280/**
     281 * @brief Prints message @a msg and jumps to @a label if the return value @a rv
     282 * is less than zero.
     283 */
     284#define RTEMS_CLEANUP_RV( rv, label, msg) \
     285  if ((int) (rv) < 0) { \
     286    RTEMS_SYSLOG_ERROR_WITH_RV( rv, msg); \
     287    goto label; \
     288  } else { \
     289    RTEMS_DEBUG_OK( msg); \
     290  }
     291
     292/**
     293 * @brief Prints message @a msg and jumps to @a label if the return value @a rv
     294 * is less than zero.  The status code variable @a sc will be set to @ref
     295 * RTEMS_IO_ERROR in this case.
     296 */
     297#define RTEMS_CLEANUP_RV_SC( rv, sc, label, msg) \
     298  if ((int) (rv) < 0) { \
     299    RTEMS_SYSLOG_ERROR_WITH_RV( rv, msg); \
    169300    sc = RTEMS_IO_ERROR; \
    170301    goto label; \
    171302  } else { \
    172     DEBUG_PRINT( "Ok: %s\n", hint ); \
    173   }
    174 
    175 #define DO_CLEANUP_SC( val, sc, label, hint ) \
     303    RTEMS_DEBUG_OK( msg); \
     304  }
     305
     306/**
     307 * @brief Prints message @a msg and jumps to @a label.
     308 */
     309#define RTEMS_DO_CLEANUP( label, msg) \
    176310  do { \
    177     sc = val; \
    178     SYSLOG_ERROR( "SC = %i: %s\n", sc, hint ); \
     311    RTEMS_SYSLOG_ERROR( msg); \
    179312    goto label; \
    180313  } while (0)
    181314
    182 #define DO_CLEANUP_RV( val, rv, label, hint ) \
     315/**
     316 * @brief Prints message @a msg, sets the status code variable @a sc to @a val
     317 * and jumps to @a label.
     318 */
     319#define RTEMS_DO_CLEANUP_SC( val, sc, label, msg) \
    183320  do { \
    184     rv = val; \
    185     SYSLOG_ERROR( "RV = %i: %s\n", rv, hint ); \
     321    sc = (rtems_status_code) val; \
     322    RTEMS_SYSLOG_ERROR_WITH_SC( sc, msg); \
    186323    goto label; \
    187324  } while (0)
     325
     326/**
     327 * @brief Prints message @a msg, sets the return value variable @a rv to @a val
     328 * and jumps to @a label.
     329 */
     330#define RTEMS_DO_CLEANUP_RV( val, rv, label, msg) \
     331  do { \
     332    rv = (int) val; \
     333    RTEMS_SYSLOG_ERROR_WITH_RV( rv, msg); \
     334    goto label; \
     335  } while (0)
     336
     337/** @} */
     338
     339/** @} */
    188340
    189341#ifdef __cplusplus
  • cpukit/libnetworking/rtems/rtems_glue.c

    rf049983 r06c3530  
    11491149}
    11501150
    1151 /*
    1152  * Parse a network driver name into a name and a unit number
     1151/**
     1152 * @brief Splits a network interface name with interface configuration @a
     1153 * config into the unit name and number parts.
     1154 *
     1155 * Memory for the unit name will be allocated from the heap and copied to @a
     1156 * namep.  If @a namep is NULL nothing will be allocated and copied.
     1157 *
     1158 * Returns the unit number or -1 on error.
    11531159 */
    11541160int
     
    11721178                                c = *cp++;
    11731179                                if (c == '\0') {
    1174                                         char *unitName = malloc (len);
    1175                                         if (unitName == NULL) {
    1176                                                 printf ("No memory.\n");
    1177                                                 return -1;
     1180                                        if (namep != NULL) {
     1181                                                char *unitName = malloc (len);
     1182                                                if (unitName == NULL) {
     1183                                                        printf ("No memory.\n");
     1184                                                        return -1;
     1185                                                }
     1186                                                strncpy (unitName, config->name, len - 1);
     1187                                                unitName[len-1] = '\0';
     1188                                                *namep = unitName;
    11781189                                        }
    1179                                         strncpy (unitName, config->name, len - 1);
    1180                                         unitName[len-1] = '\0';
    1181                                         *namep = unitName;
    11821190                                        return unitNumber;
    11831191                                }
Note: See TracChangeset for help on using the changeset viewer.