From 67a3697a4d90233cad53d2770b2204e8f39e1668 Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Wed, 27 Jan 2016 23:49:13 +0100 Subject: [PATCH] Disable the getopt argument permutation on BSD systems. On BSD based operating systems (which includes Mac OS X), the getopt() function is posix compliant and thus the option processing stops when the first non-option is found. But the getopt_long() function permutes the argument vector, just like the GNU implementation. Using a leading '+' character in the option string disables the permutation again. --- configure.ac | 1 + examples/dctool.c | 11 +++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index cb9c7a3..b5aa34b 100644 --- a/configure.ac +++ b/configure.ac @@ -106,6 +106,7 @@ AM_CONDITIONAL([IRDA], [test "$irda_win32" = "yes" || test "$irda_linux" = "yes" AC_CHECK_HEADERS([linux/serial.h]) AC_CHECK_HEADERS([IOKit/serial/ioss.h]) AC_CHECK_HEADERS([getopt.h]) +AC_CHECK_HEADERS([sys/param.h]) # Checks for global variable declarations. AC_CHECK_DECLS([optreset]) diff --git a/examples/dctool.c b/examples/dctool.c index c3ac6c0..a317980 100644 --- a/examples/dctool.c +++ b/examples/dctool.c @@ -31,6 +31,9 @@ #ifdef HAVE_GETOPT_H #include #endif +#ifdef HAVE_SYS_PARAM_H +#include +#endif #include #include @@ -40,13 +43,17 @@ #include "utils.h" #if defined(__GLIBC__) || defined(__MINGW32__) -#define NOPERMUTATION "+" #define RESET 0 #else -#define NOPERMUTATION "" #define RESET 1 #endif +#if defined(__GLIBC__) || defined(__MINGW32__) || defined(BSD) +#define NOPERMUTATION "+" +#else +#define NOPERMUTATION "" +#endif + static const dctool_command_t *g_commands[] = { &dctool_help, &dctool_version,