Don't assume that struct option is available just because we can find a

getopt_long().  This is more or less the same problem as we saw earlier
with getaddrinfo() and struct addrinfo, and for the same reason: random
user-added libraries might contain the subroutine, but there's no
guarantee we will find the matching header files.
This commit is contained in:
Tom Lane 2003-08-07 21:11:58 +00:00
parent fea2ffa7d8
commit 33ab177a56
11 changed files with 200 additions and 44 deletions

149
configure vendored
View File

@ -10379,6 +10379,67 @@ _ACEOF
fi
echo "$as_me:$LINENO: checking for struct option" >&5
echo $ECHO_N "checking for struct option... $ECHO_C" >&6
if test "${ac_cv_type_struct_option+set}" = set; then
echo $ECHO_N "(cached) $ECHO_C" >&6
else
cat >conftest.$ac_ext <<_ACEOF
#line $LINENO "configure"
#include "confdefs.h"
#ifdef HAVE_GETOPT_H
include <getopt.h>
#endif
#ifdef F77_DUMMY_MAIN
# ifdef __cplusplus
extern "C"
# endif
int F77_DUMMY_MAIN() { return 1; }
#endif
int
main ()
{
if ((struct option *) 0)
return 0;
if (sizeof (struct option))
return 0;
;
return 0;
}
_ACEOF
rm -f conftest.$ac_objext
if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
(eval $ac_compile) 2>&5
ac_status=$?
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); } &&
{ ac_try='test -s conftest.$ac_objext'
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
(eval $ac_try) 2>&5
ac_status=$?
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); }; }; then
ac_cv_type_struct_option=yes
else
echo "$as_me: failed program was:" >&5
cat conftest.$ac_ext >&5
ac_cv_type_struct_option=no
fi
rm -f conftest.$ac_objext conftest.$ac_ext
fi
echo "$as_me:$LINENO: result: $ac_cv_type_struct_option" >&5
echo "${ECHO_T}$ac_cv_type_struct_option" >&6
if test $ac_cv_type_struct_option = yes; then
cat >>confdefs.h <<_ACEOF
#define HAVE_STRUCT_OPTION 1
_ACEOF
fi
if test "$with_zlib" = yes; then
# Check that <zlib.h> defines z_streamp (versions before about 1.0.4
# did not). While we could work around the lack of z_streamp, it
@ -11760,8 +11821,7 @@ fi
for ac_func in crypt fseeko getopt getopt_long getrusage inet_aton random rint srandom strcasecmp strdup strerror strtol strtoul
for ac_func in crypt fseeko getopt getrusage inet_aton random rint srandom strcasecmp strdup strerror strtol strtoul
do
as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh`
echo "$as_me:$LINENO: checking for $ac_func" >&5
@ -11926,6 +11986,91 @@ else
LIBOBJS="$LIBOBJS getaddrinfo.$ac_objext"
fi
# similarly, use system's getopt_long() only if system provides struct option.
if test x"$ac_cv_type_struct_option" = xyes ; then
for ac_func in getopt_long
do
as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh`
echo "$as_me:$LINENO: checking for $ac_func" >&5
echo $ECHO_N "checking for $ac_func... $ECHO_C" >&6
if eval "test \"\${$as_ac_var+set}\" = set"; then
echo $ECHO_N "(cached) $ECHO_C" >&6
else
cat >conftest.$ac_ext <<_ACEOF
#line $LINENO "configure"
#include "confdefs.h"
/* System header to define __stub macros and hopefully few prototypes,
which can conflict with char $ac_func (); below. */
#include <assert.h>
/* Override any gcc2 internal prototype to avoid an error. */
#ifdef __cplusplus
extern "C"
#endif
/* We use char because int might match the return type of a gcc2
builtin and then its argument prototype would still apply. */
char $ac_func ();
char (*f) ();
#ifdef F77_DUMMY_MAIN
# ifdef __cplusplus
extern "C"
# endif
int F77_DUMMY_MAIN() { return 1; }
#endif
int
main ()
{
/* The GNU C library defines this for functions which it implements
to always fail with ENOSYS. Some functions are actually named
something starting with __ and the normal name is an alias. */
#if defined (__stub_$ac_func) || defined (__stub___$ac_func)
choke me
#else
f = $ac_func;
#endif
;
return 0;
}
_ACEOF
rm -f conftest.$ac_objext conftest$ac_exeext
if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
(eval $ac_link) 2>&5
ac_status=$?
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); } &&
{ ac_try='test -s conftest$ac_exeext'
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
(eval $ac_try) 2>&5
ac_status=$?
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); }; }; then
eval "$as_ac_var=yes"
else
echo "$as_me: failed program was:" >&5
cat conftest.$ac_ext >&5
eval "$as_ac_var=no"
fi
rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext
fi
echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_var'}'`" >&5
echo "${ECHO_T}`eval echo '${'$as_ac_var'}'`" >&6
if test `eval echo '${'$as_ac_var'}'` = yes; then
cat >>confdefs.h <<_ACEOF
#define `echo "HAVE_$ac_func" | $as_tr_cpp` 1
_ACEOF
else
LIBOBJS="$LIBOBJS $ac_func.$ac_objext"
fi
done
else
LIBOBJS="$LIBOBJS getopt_long.$ac_objext"
fi
# BSD/OS & NetBSD use a custom fseeko/ftello built on fsetpos/fgetpos
# We override the previous test that said fseeko/ftello didn't exist
# OS tests are also done in include/c.h and port/fseeko.c

View File

@ -1,5 +1,5 @@
dnl Process this file with autoconf to produce a configure script.
dnl $Header: /cvsroot/pgsql/configure.in,v 1.277 2003/08/04 22:30:30 pgsql Exp $
dnl $Header: /cvsroot/pgsql/configure.in,v 1.278 2003/08/07 21:11:57 tgl Exp $
dnl
dnl Developers, please strive to achieve this order:
dnl
@ -780,6 +780,11 @@ AC_CHECK_TYPES([struct cmsgcred, struct fcred, struct sockcred], [], [],
#include <sys/socket.h>
#include <sys/ucred.h>])
AC_CHECK_TYPES([struct option], [], [],
[#ifdef HAVE_GETOPT_H
include <getopt.h>
#endif])
if test "$with_zlib" = yes; then
# Check that <zlib.h> defines z_streamp (versions before about 1.0.4
# did not). While we could work around the lack of z_streamp, it
@ -875,7 +880,7 @@ else
AC_CHECK_FUNCS([fpclass fp_class fp_class_d class], [break])
fi
AC_REPLACE_FUNCS([crypt fseeko getopt getopt_long getrusage inet_aton random rint srandom strcasecmp strdup strerror strtol strtoul])
AC_REPLACE_FUNCS([crypt fseeko getopt getrusage inet_aton random rint srandom strcasecmp strdup strerror strtol strtoul])
# system's version of getaddrinfo(), if any, may be used only if we found
# a definition for struct addrinfo; see notes in src/include/getaddrinfo.h
@ -885,6 +890,13 @@ else
AC_LIBOBJ(getaddrinfo)
fi
# similarly, use system's getopt_long() only if system provides struct option.
if test x"$ac_cv_type_struct_option" = xyes ; then
AC_REPLACE_FUNCS([getopt_long])
else
AC_LIBOBJ(getopt_long)
fi
# BSD/OS & NetBSD use a custom fseeko/ftello built on fsetpos/fgetpos
# We override the previous test that said fseeko/ftello didn't exist
# OS tests are also done in include/c.h and port/fseeko.c

View File

@ -6,7 +6,7 @@
#include "postgres_fe.h"
#include <unistd.h>
#ifdef __GLIBC__
#ifdef HAVE_GETOPT_H
#include <getopt.h>
#endif
#include <time.h>

View File

@ -1,7 +1,7 @@
/* -------------------------------------------------------------------------
* pg_dumplo
*
* $Header: /cvsroot/pgsql/contrib/pg_dumplo/Attic/main.c,v 1.17 2003/08/04 00:43:11 momjian Exp $
* $Header: /cvsroot/pgsql/contrib/pg_dumplo/Attic/main.c,v 1.18 2003/08/07 21:11:57 tgl Exp $
*
* Karel Zak 1999-2000
* -------------------------------------------------------------------------
@ -11,9 +11,6 @@
#include <errno.h>
#include <unistd.h>
#ifdef HAVE_GETOPT_H
#include <getopt.h>
#endif
#include "libpq-fe.h"
#include "libpq/libpq-fs.h"
@ -24,8 +21,9 @@
#include "strdup.h"
#endif
#ifndef HAVE_GETOPT_LONG
#include "getopt_long.h"
#ifndef HAVE_OPTRESET
int optreset;
#endif

View File

@ -12,7 +12,7 @@
* by PostgreSQL
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.342 2003/08/04 02:40:09 momjian Exp $
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.343 2003/08/07 21:11:58 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -29,9 +29,6 @@
#ifdef ENABLE_NLS
#include <locale.h>
#endif
#ifdef HAVE_GETOPT_H
#include <getopt.h>
#endif
#ifdef HAVE_TERMIOS_H
#include <termios.h>
#endif
@ -40,8 +37,9 @@
#include "strdup.h"
#endif
#ifndef HAVE_GETOPT_LONG
#include "getopt_long.h"
#ifndef HAVE_OPTRESET
int optreset;
#endif

View File

@ -6,7 +6,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
*
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dumpall.c,v 1.26 2003/08/04 02:40:09 momjian Exp $
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dumpall.c,v 1.27 2003/08/07 21:11:58 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -17,16 +17,14 @@
#ifdef ENABLE_NLS
#include <locale.h>
#endif
#ifdef HAVE_GETOPT_H
#include <getopt.h>
#endif
#ifndef HAVE_STRDUP
#include "strdup.h"
#endif
#include <errno.h>
#ifndef HAVE_GETOPT_LONG
#include "getopt_long.h"
#ifndef HAVE_OPTRESET
int optreset;
#endif

View File

@ -34,7 +34,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_restore.c,v 1.49 2003/08/04 00:43:28 momjian Exp $
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_restore.c,v 1.50 2003/08/07 21:11:58 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -55,12 +55,9 @@
#include <unistd.h>
#ifdef HAVE_GETOPT_H
#include <getopt.h>
#endif
#ifndef HAVE_GETOPT_LONG
#include "getopt_long.h"
#ifndef HAVE_OPTRESET
int optreset;
#endif

View File

@ -3,7 +3,7 @@
*
* Copyright (c) 2000-2003, PostgreSQL Global Development Group
*
* $Header: /cvsroot/pgsql/src/bin/psql/startup.c,v 1.78 2003/08/04 23:59:40 tgl Exp $
* $Header: /cvsroot/pgsql/src/bin/psql/startup.c,v 1.79 2003/08/07 21:11:58 tgl Exp $
*/
#include "postgres_fe.h"
@ -17,12 +17,9 @@
#include <win32.h>
#endif /* WIN32 */
#ifdef HAVE_GETOPT_H
#include <getopt.h>
#endif
#ifndef HAVE_GETOPT_LONG
#include "getopt_long.h"
#ifndef HAVE_OPTRESET
int optreset;
#endif

View File

@ -1,15 +1,8 @@
#include "postgres_fe.h"
#ifdef HAVE_GETOPT_H
#include <getopt.h>
#endif
#ifndef HAVE_GETOPT_LONG
#include "getopt_long.h"
#endif
#include "libpq-fe.h"
#include "pqexpbuffer.h"
#include "getopt_long.h"
#ifndef HAVE_OPTRESET
int optreset;

View File

@ -2,11 +2,16 @@
* Portions Copyright (c) 1987, 1993, 1994
* The Regents of the University of California. All rights reserved.
*
* Portions Copyright (c) 2003
* PostgreSQL Global Development Group
* Portions Copyright (c) 2003, PostgreSQL Global Development Group
*
* $Header: /cvsroot/pgsql/src/include/getopt_long.h,v 1.2 2003/08/04 00:43:29 momjian Exp $
* $Header: /cvsroot/pgsql/src/include/getopt_long.h,v 1.3 2003/08/07 21:11:58 tgl Exp $
*/
#ifndef GETOPT_LONG_H
#define GETOPT_LONG_H
#ifdef HAVE_GETOPT_H
#include <getopt.h>
#endif
/* These are picked up from the system's getopt() facility. */
extern int opterr;
@ -17,6 +22,8 @@ extern char *optarg;
/* Some systems have this, otherwise you need to define it somewhere. */
extern int optreset;
#ifndef HAVE_STRUCT_OPTION
struct option
{
const char *name;
@ -28,6 +35,14 @@ struct option
#define no_argument 0
#define required_argument 1
int getopt_long(int argc, char *const argv[],
#endif
#ifndef HAVE_GETOPT_LONG
extern int getopt_long(int argc, char *const argv[],
const char *optstring,
const struct option * longopts, int *longindex);
#endif
#endif /* GETOPT_LONG_H */

View File

@ -417,6 +417,9 @@
/* Define to 1 if the system has the type `struct fcred'. */
#undef HAVE_STRUCT_FCRED
/* Define to 1 if the system has the type `struct option'. */
#undef HAVE_STRUCT_OPTION
/* Define to 1 if `sa_len' is member of `struct sockaddr'. */
#undef HAVE_STRUCT_SOCKADDR_SA_LEN