diff --git a/wireless/wapi/src/util.h b/wireless/wapi/src/util.h index 50de0b6eb..e7c304f7f 100644 --- a/wireless/wapi/src/util.h +++ b/wireless/wapi/src/util.h @@ -47,29 +47,74 @@ * Pre-processor Definitions ****************************************************************************/ -#define WAPI_IOCTL_STRERROR(cmd) \ - fprintf( \ - stderr, "%s:%d:%s():ioctl(%s): %s\n", \ - __FILE__, __LINE__, __func__, \ - wapi_ioctl_command_name(cmd), strerror(errno)) +#ifdef DEBUG_WIRELESS_ERROR +# ifdef CONFIG_LIBC_STRERROR +# define WAPI_IOCTL_STRERROR(cmd) \ + fprintf( \ + stderr, "%s:%d:%s():ioctl(%s): %s\n", \ + __FILE__, __LINE__, __func__, \ + wapi_ioctl_command_name(cmd), strerror(errno)) -#define WAPI_STRERROR(fmt, ...) \ - fprintf( \ - stderr, "%s:%d:%s():" fmt ": %s\n", \ - __FILE__, __LINE__, __func__, \ - ## __VA_ARGS__, strerror(errno)) +# define WAPI_STRERROR(fmt, ...) \ + fprintf( \ + stderr, "%s:%d:%s():" fmt ": %s\n", \ + __FILE__, __LINE__, __func__, \ + ## __VA_ARGS__, strerror(errno)) +# else +# define WAPI_IOCTL_STRERROR(cmd) \ + fprintf( \ + stderr, "%s:%d:%s():ioctl(%s): %d\n", \ + __FILE__, __LINE__, __func__, \ + wapi_ioctl_command_name(cmd), errno) -#define WAPI_ERROR(fmt, ...) \ - fprintf( \ - stderr, "%s:%d:%s(): " fmt , \ - __FILE__, __LINE__, __func__, ## __VA_ARGS__) +# define WAPI_STRERROR(fmt, ...) \ + fprintf( \ + stderr, "%s:%d:%s():" fmt ": %d\n", \ + __FILE__, __LINE__, __func__, \ + ## __VA_ARGS__, errno) +# endif + +# define WAPI_ERROR(fmt, ...) \ + fprintf( \ + stderr, "%s:%d:%s(): " fmt , \ + __FILE__, __LINE__, __func__, ## __VA_ARGS__) + +#else +# ifdef CONFIG_LIBC_STRERROR +# define WAPI_IOCTL_STRERROR(cmd) \ + fprintf( \ + stderr, "ioctl(%s): %s\n", \ + wapi_ioctl_command_name(cmd), strerror(errno)) + +# define WAPI_STRERROR(fmt, ...) \ + fprintf( \ + stderr, fmt ": %s\n", \ + ## __VA_ARGS__, strerror(errno)) +# else +# define WAPI_IOCTL_STRERROR(cmd) \ + fprintf( \ + stderr, "ioctl(%s): %d\n", \ + wapi_ioctl_command_name(cmd), errno) + +# define WAPI_STRERROR(fmt, ...) \ + fprintf( \ + stderr, fmt ": %d\n", \ + ## __VA_ARGS__, errno) +# endif + +# define WAPI_ERROR(fmt, ...) \ + fprintf( \ + stderr, fmt , \ + ## __VA_ARGS__) + +#endif #define WAPI_VALIDATE_PTR(ptr) \ - if (!ptr) \ - { \ - WAPI_ERROR("Null pointer: %s.\n", #ptr); \ - return -1; \ - } + if (ptr == NULL) \ + { \ + WAPI_ERROR("Null pointer: %p\n", ptr); \ + return -EINVAL; \ + } /**************************************************************************** * Public Function Prototypes diff --git a/wireless/wapi/src/wapi.c b/wireless/wapi/src/wapi.c index 60f00a3b9..a5f53c2d2 100644 --- a/wireless/wapi/src/wapi.c +++ b/wireless/wapi/src/wapi.c @@ -76,6 +76,8 @@ typedef void (*cmd3_t)(int sock, FAR const char *arg1, static int wapi_str2int(FAR const char *str); static double wapi_str2double(FAR const char *str); +static unsigned int wapi_str2ndx(FAR const char *name, FAR const char **list, + unsigned int listlen); static void wapi_show_cmd(int sock, FAR const char *ifname); static void wapi_ip_cmd(int sock, FAR const char *ifname, @@ -196,7 +198,13 @@ static unsigned int wapi_str2ndx(FAR const char *name, FAR const char **list, } } - WAPI_ERROR("ERROR: Invalid string: %s\n", name); + WAPI_ERROR("ERROR: Invalid option string: %s\n", name); + WAPI_ERROR(" Valid options include:\n"); + for (ndx = 0; ndx < listlen; ndx++) + { + WAPI_ERROR(" - %s\n", list[ndx]); + } + exit(EXIT_FAILURE); }