diff --git a/libraries/AP_HAL/utility/getopt_cpp.cpp b/libraries/AP_HAL/utility/getopt_cpp.cpp index 02e3bd26c9..9a7f3a4099 100644 --- a/libraries/AP_HAL/utility/getopt_cpp.cpp +++ b/libraries/AP_HAL/utility/getopt_cpp.cpp @@ -36,12 +36,19 @@ */ #include -#if HAL_OS_POSIX_IO && CONFIG_HAL_BOARD != HAL_BOARD_QURT +#if HAL_OS_POSIX_IO #include "getopt_cpp.h" #include #include +#if CONFIG_HAL_BOARD == HAL_BOARD_QURT +#define GETOPT_ERROR(...) HAP_printf(__FILE__, __LINE__, __VA_ARGS__) +#else +#define GETOPT_ERROR(...) fprintf(stderr, __VA_ARGS__) +#endif + + /* constructor */ @@ -117,10 +124,10 @@ int GetOptLong::getoption(void) { if (optstring[0] == ':') return BADARG; - if (opterr) - fprintf(stderr, - "%s: option requires an argument -- %s\n", - argv[0], place); + if (opterr) { + GETOPT_ERROR("%s: option requires an argument -- %s\n", + argv[0], place); + } place = ""; optind++; return BADCH; @@ -151,9 +158,9 @@ int GetOptLong::getoption(void) } } - if (opterr && optstring[0] != ':') - fprintf(stderr, - "%s: illegal option -- %s\n", argv[0], place); + if (opterr && optstring[0] != ':') { + GETOPT_ERROR("%s: illegal option -- %s\n", argv[0], place); + } place = ""; optind++; return BADCH; @@ -168,9 +175,9 @@ int GetOptLong::getoption(void) { if (!*place) ++optind; - if (opterr && *optstring != ':') - fprintf(stderr, - "%s: illegal option -- %c\n", argv[0], optopt); + if (opterr && *optstring != ':') { + GETOPT_ERROR("%s: illegal option -- %c\n", argv[0], optopt); + } return BADCH; } @@ -189,10 +196,10 @@ int GetOptLong::getoption(void) place = ""; if (*optstring == ':') return BADARG; - if (opterr) - fprintf(stderr, - "%s: option requires an argument -- %c\n", - argv[0], optopt); + if (opterr) { + GETOPT_ERROR("%s: option requires an argument -- %c\n", + argv[0], optopt); + } return BADCH; } else