From fbe2b7403a5e4236f65da79e4340f7ebd373270a Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Thu, 24 Mar 2011 14:01:26 +0100 Subject: [PATCH] Make znc compile without getopt_long If getopt_long() (GNU extension) isn't available, we use the plain old getopt() instead. This means that long options won't work, but at least this compiles. Tested on Solaris 9, but should also work on Irix. Signed-off-by: Uli Schlachter --- configure.ac | 2 +- main.cpp | 21 ++++++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index 80061a7a..4ed50d1d 100644 --- a/configure.ac +++ b/configure.ac @@ -164,7 +164,7 @@ if test "$POLL" = "yes"; then fi AC_CHECK_LIB( gnugetopt, getopt_long,) -AC_CHECK_FUNCS([lstat]) +AC_CHECK_FUNCS([lstat getopt_long]) PKG_PROG_PKG_CONFIG() # ----- Check for dlopen diff --git a/main.cpp b/main.cpp index 7d131a6d..50703a19 100644 --- a/main.cpp +++ b/main.cpp @@ -7,9 +7,28 @@ */ #include "znc.h" -#include #include +#ifdef HAVE_GETOPT_LONG +#include +#else +#define no_argument 0 +#define required_argument 1 +#define optional_argument 2 + +struct option { + const char *a; + int opt; + int *flag; + int val; +}; + +static inline int getopt_long(int argc, char * const argv[], const char *optstring, const struct option *, int *) +{ + return getopt(argc, argv, optstring); +} +#endif + static const struct option g_LongOpts[] = { { "help", no_argument, 0, 'h' }, { "version", no_argument, 0, 'v' },