From 06c3530efcc3cd4230278e150a0b828359982ca0 Mon Sep 17 00:00:00 2001 From: Thomas Doerfler Date: Fri, 10 Oct 2008 15:56:32 +0000 Subject: 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. --- cpukit/libnetworking/rtems/rtems_glue.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) (limited to 'cpukit/libnetworking') 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')) -- cgit v1.2.3