diff --git a/ChangeLog b/ChangeLog index 8a9c473b..a0f6a8ae 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2009-07-14 Tatsuhiro Tsujikawa + + Handle the situation where struct option.name is char *. + * configure.ac + * src/OptionParser.cc + 2009-07-14 Tatsuhiro Tsujikawa Code cleanup diff --git a/config.h.in b/config.h.in index 91186628..932efbc4 100644 --- a/config.h.in +++ b/config.h.in @@ -284,6 +284,9 @@ /* Define to 1 if you have old openssl. */ #undef HAVE_OLD_LIBSSL +/* Define 1 if struct option.name is const char* */ +#undef HAVE_OPTION_CONST_NAME + /* Define to 1 if you have the `posix_fallocate' function. */ #undef HAVE_POSIX_FALLOCATE diff --git a/configure b/configure index 95ff3d09..4adfa25a 100755 --- a/configure +++ b/configure @@ -23141,6 +23141,70 @@ _ACEOF fi +# Check struct option.name is assignable from const char*. struct +# option.name in opensolaris is of type char*. In Linux, it is const +# char* +{ $as_echo "$as_me:$LINENO: checking whether struct option.name is assignable from const char*" >&5 +$as_echo_n "checking whether struct option.name is assignable from const char*... " >&6; } +cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +#include +#include + +int +main () +{ + +const char* s = "const char"; +option op; +op.name = s; + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" +$as_echo "$ac_try_echo") >&5 + (eval "$ac_compile") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { + test -z "$ac_cxx_werror_flag" || + test ! -s conftest.err + } && test -s conftest.$ac_objext; then + have_option_const_name=yes +else + $as_echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + have_option_const_name=no +fi + +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +{ $as_echo "$as_me:$LINENO: result: $have_option_const_name" >&5 +$as_echo "$have_option_const_name" >&6; } +if test "x$have_option_const_name" = "xyes"; then + +cat >>confdefs.h <<\_ACEOF +#define HAVE_OPTION_CONST_NAME 1 +_ACEOF + +fi + ac_config_files="$ac_config_files Makefile src/Makefile test/Makefile po/Makefile.in m4/Makefile intl/Makefile lib/Makefile doc/Makefile" cat >confcache <<\_ACEOF diff --git a/configure.ac b/configure.ac index ab6ece95..b3d0ab75 100644 --- a/configure.ac +++ b/configure.ac @@ -349,6 +349,25 @@ AC_CHECK_MEMBER([struct sockaddr_in.sin_len], [], [[#include ]]) +# Check struct option.name is assignable from const char*. struct +# option.name in opensolaris is of type char*. In Linux, it is const +# char* +AC_MSG_CHECKING([whether struct option.name is assignable from const char*]) +AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ +#include +#include +]], +[[ +const char* s = "const char"; +option op; +op.name = s; +]])], +[have_option_const_name=yes], [have_option_const_name=no]) +AC_MSG_RESULT([$have_option_const_name]) +if test "x$have_option_const_name" = "xyes"; then + AC_DEFINE([HAVE_OPTION_CONST_NAME], [1], [Define 1 if struct option.name is const char*]) +fi + AC_CONFIG_FILES([Makefile src/Makefile test/Makefile diff --git a/src/OptionParser.cc b/src/OptionParser.cc index 75bb9f46..04129bb7 100644 --- a/src/OptionParser.cc +++ b/src/OptionParser.cc @@ -71,7 +71,11 @@ static void putOptions(struct option* longOpts, int* plopt, { for(; first != last; ++first) { if(!(*first)->isHidden()) { +#ifdef HAVE_OPTION_CONST_NAME (*longOpts).name = (*first)->getName().c_str(); +#else // !HAVE_OPTION_CONST_NAME + (*longOpts).name = strdup((*first)->getName().c_str()); +#endif // !HAVE_OPTION_CONST_NAME switch((*first)->getArgType()) { case OptionHandler::REQ_ARG: (*longOpts).has_arg = required_argument;