From 2dee87346a344103b6a471f24345cb60cab46ee8 Mon Sep 17 00:00:00 2001 From: "Steffen \"Daode\" Nurpmeso" Date: Thu, 11 Oct 2012 16:28:53 +0200 Subject: [PATCH] Tweak (Use system getopt(3) if available.., 2012-10-05).. That commit had two pitfalls. First it simply used getopt() if available, though getopt.c has been introduced to be able to provide a non-reordered argument list processing. (And that was also needed because in main() direct messing around with the argument list had been performed; this is no longer true for S-nail(1), though.) So never succeed and use libc getopt(3) when __GLIBC__ or __linux__ preprocessor variables are detected. Secondly the author introduced user.conf to express user options, and these are then (when satisfieable) defined as USE_*, rather than HAVE_*. The mentioned commit used USE_*, too, because the author planned to make usage of the builtin getopt() configurable in user.conf first. And, because makeconfig link_check() requires a #define that it can set when the check succeeds, that required usage of a pseudo variable since USE_BUILTIN_GETOPT could of course not be used. Well. Instead of turning that to USE_SYSTEM_GETOPT (which would thus have been wrong due to multiple reasons) turn this non-user-configurable thing to HAVE_GETOPT. --- extern.h | 2 +- getopt.c | 4 ++-- makeconfig | 15 +++++++++------ 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/extern.h b/extern.h index f9fdc3f7..ece5baca 100644 --- a/extern.h +++ b/extern.h @@ -271,7 +271,7 @@ char *getname(int uid); int getuserid(char *name); /* getopt.c */ -#ifdef USE_BUILTIN_GETOPT +#ifndef HAVE_GETOPT int getopt(int argc, char *const argv[], const char *optstring); #endif diff --git a/getopt.c b/getopt.c index f605117d..9a2dcb47 100644 --- a/getopt.c +++ b/getopt.c @@ -6,7 +6,7 @@ #include "config.h" -#ifndef USE_BUILTIN_GETOPT +#ifdef HAVE_GETOPT typedef int avoid_empty_file_compiler_warning; #else @@ -159,4 +159,4 @@ getopt$UNIX2003(int argc, char *const argv[], const char *optstring) return getopt(argc, argv, optstring); } # endif /* __APPLE__ */ -#endif /* USE_BUILTIN_GETOPT */ +#endif /* HAVE_GETOPT */ diff --git a/makeconfig b/makeconfig index 8ae9570b..901c1da0 100644 --- a/makeconfig +++ b/makeconfig @@ -337,13 +337,16 @@ int main(void) } ! -link_check getopt 'for getopt()' '#define __WE_WILL_USE_SYS_GETOPT' << \! || \ - echo '#define USE_BUILTIN_GETOPT' >> $out +link_check getopt 'for getopt()' '#define HAVE_GETOPT' << \! #include int main(int argc, char **argv) { +#if defined __GLIBC__ || defined __linux__ + Argument and option reordering is not a desired feature. +#else getopt(argc, argv, "oPt"); - return ((long)optarg + optind) & 0x7F; +#endif + return (((long)optarg + optind) & 0x7F); } ! @@ -713,9 +716,9 @@ cat > $tmp2.c << \! : chdir() instead. This is not a problem unless the current working : directory of mailx is moved while the IMAP cache is used. #endif -#ifndef __WE_WILL_USE_SYS_GETOPT -: * A (usable) getopt() functionality could not be found. A simple builtin -: version is used instead. +#ifndef HAVE_GETOPT +: * A (usable) getopt() functionality could not be found. +: A builtin version is used instead. #endif #ifdef HAVE_ASSERTS : * WANT_ASSERTS is enabled, the program binary will contain code assertions. -- 2.11.4.GIT