Skip to content

Commit 33ab177

Browse files
committed
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.
1 parent fea2ffa commit 33ab177

File tree

11 files changed

+200
-44
lines changed

11 files changed

+200
-44
lines changed

configure

Lines changed: 147 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10379,6 +10379,67 @@ _ACEOF
1037910379
fi
1038010380

1038110381

10382+
echo "$as_me:$LINENO: checking for struct option" >&5
10383+
echo $ECHO_N "checking for struct option... $ECHO_C" >&6
10384+
if test "${ac_cv_type_struct_option+set}" = set; then
10385+
echo $ECHO_N "(cached) $ECHO_C" >&6
10386+
else
10387+
cat >conftest.$ac_ext <<_ACEOF
10388+
#line $LINENO "configure"
10389+
#include "confdefs.h"
10390+
#ifdef HAVE_GETOPT_H
10391+
include <getopt.h>
10392+
#endif
10393+
10394+
#ifdef F77_DUMMY_MAIN
10395+
# ifdef __cplusplus
10396+
extern "C"
10397+
# endif
10398+
int F77_DUMMY_MAIN() { return 1; }
10399+
#endif
10400+
int
10401+
main ()
10402+
{
10403+
if ((struct option *) 0)
10404+
return 0;
10405+
if (sizeof (struct option))
10406+
return 0;
10407+
;
10408+
return 0;
10409+
}
10410+
_ACEOF
10411+
rm -f conftest.$ac_objext
10412+
if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
10413+
(eval $ac_compile) 2>&5
10414+
ac_status=$?
10415+
echo "$as_me:$LINENO: \$? = $ac_status" >&5
10416+
(exit $ac_status); } &&
10417+
{ ac_try='test -s conftest.$ac_objext'
10418+
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
10419+
(eval $ac_try) 2>&5
10420+
ac_status=$?
10421+
echo "$as_me:$LINENO: \$? = $ac_status" >&5
10422+
(exit $ac_status); }; }; then
10423+
ac_cv_type_struct_option=yes
10424+
else
10425+
echo "$as_me: failed program was:" >&5
10426+
cat conftest.$ac_ext >&5
10427+
ac_cv_type_struct_option=no
10428+
fi
10429+
rm -f conftest.$ac_objext conftest.$ac_ext
10430+
fi
10431+
echo "$as_me:$LINENO: result: $ac_cv_type_struct_option" >&5
10432+
echo "${ECHO_T}$ac_cv_type_struct_option" >&6
10433+
if test $ac_cv_type_struct_option = yes; then
10434+
10435+
cat >>confdefs.h <<_ACEOF
10436+
#define HAVE_STRUCT_OPTION 1
10437+
_ACEOF
10438+
10439+
10440+
fi
10441+
10442+
1038210443
if test "$with_zlib" = yes; then
1038310444
# Check that <zlib.h> defines z_streamp (versions before about 1.0.4
1038410445
# did not). While we could work around the lack of z_streamp, it
@@ -11760,8 +11821,7 @@ fi
1176011821

1176111822

1176211823

11763-
11764-
for ac_func in crypt fseeko getopt getopt_long getrusage inet_aton random rint srandom strcasecmp strdup strerror strtol strtoul
11824+
for ac_func in crypt fseeko getopt getrusage inet_aton random rint srandom strcasecmp strdup strerror strtol strtoul
1176511825
do
1176611826
as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh`
1176711827
echo "$as_me:$LINENO: checking for $ac_func" >&5
@@ -11926,6 +11986,91 @@ else
1192611986
LIBOBJS="$LIBOBJS getaddrinfo.$ac_objext"
1192711987
fi
1192811988

11989+
# similarly, use system's getopt_long() only if system provides struct option.
11990+
if test x"$ac_cv_type_struct_option" = xyes ; then
11991+
11992+
for ac_func in getopt_long
11993+
do
11994+
as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh`
11995+
echo "$as_me:$LINENO: checking for $ac_func" >&5
11996+
echo $ECHO_N "checking for $ac_func... $ECHO_C" >&6
11997+
if eval "test \"\${$as_ac_var+set}\" = set"; then
11998+
echo $ECHO_N "(cached) $ECHO_C" >&6
11999+
else
12000+
cat >conftest.$ac_ext <<_ACEOF
12001+
#line $LINENO "configure"
12002+
#include "confdefs.h"
12003+
/* System header to define __stub macros and hopefully few prototypes,
12004+
which can conflict with char $ac_func (); below. */
12005+
#include <assert.h>
12006+
/* Override any gcc2 internal prototype to avoid an error. */
12007+
#ifdef __cplusplus
12008+
extern "C"
12009+
#endif
12010+
/* We use char because int might match the return type of a gcc2
12011+
builtin and then its argument prototype would still apply. */
12012+
char $ac_func ();
12013+
char (*f) ();
12014+
12015+
#ifdef F77_DUMMY_MAIN
12016+
# ifdef __cplusplus
12017+
extern "C"
12018+
# endif
12019+
int F77_DUMMY_MAIN() { return 1; }
12020+
#endif
12021+
int
12022+
main ()
12023+
{
12024+
/* The GNU C library defines this for functions which it implements
12025+
to always fail with ENOSYS. Some functions are actually named
12026+
something starting with __ and the normal name is an alias. */
12027+
#if defined (__stub_$ac_func) || defined (__stub___$ac_func)
12028+
choke me
12029+
#else
12030+
f = $ac_func;
12031+
#endif
12032+
12033+
;
12034+
return 0;
12035+
}
12036+
_ACEOF
12037+
rm -f conftest.$ac_objext conftest$ac_exeext
12038+
if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
12039+
(eval $ac_link) 2>&5
12040+
ac_status=$?
12041+
echo "$as_me:$LINENO: \$? = $ac_status" >&5
12042+
(exit $ac_status); } &&
12043+
{ ac_try='test -s conftest$ac_exeext'
12044+
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
12045+
(eval $ac_try) 2>&5
12046+
ac_status=$?
12047+
echo "$as_me:$LINENO: \$? = $ac_status" >&5
12048+
(exit $ac_status); }; }; then
12049+
eval "$as_ac_var=yes"
12050+
else
12051+
echo "$as_me: failed program was:" >&5
12052+
cat conftest.$ac_ext >&5
12053+
eval "$as_ac_var=no"
12054+
fi
12055+
rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext
12056+
fi
12057+
echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_var'}'`" >&5
12058+
echo "${ECHO_T}`eval echo '${'$as_ac_var'}'`" >&6
12059+
if test `eval echo '${'$as_ac_var'}'` = yes; then
12060+
cat >>confdefs.h <<_ACEOF
12061+
#define `echo "HAVE_$ac_func" | $as_tr_cpp` 1
12062+
_ACEOF
12063+
12064+
else
12065+
LIBOBJS="$LIBOBJS $ac_func.$ac_objext"
12066+
fi
12067+
done
12068+
12069+
12070+
else
12071+
LIBOBJS="$LIBOBJS getopt_long.$ac_objext"
12072+
fi
12073+
1192912074
# BSD/OS & NetBSD use a custom fseeko/ftello built on fsetpos/fgetpos
1193012075
# We override the previous test that said fseeko/ftello didn't exist
1193112076
# OS tests are also done in include/c.h and port/fseeko.c

configure.in

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
dnl Process this file with autoconf to produce a configure script.
2-
dnl $Header: /cvsroot/pgsql/configure.in,v 1.277 2003/08/04 22:30:30 pgsql Exp $
2+
dnl $Header: /cvsroot/pgsql/configure.in,v 1.278 2003/08/07 21:11:57 tgl Exp $
33
dnl
44
dnl Developers, please strive to achieve this order:
55
dnl
@@ -780,6 +780,11 @@ AC_CHECK_TYPES([struct cmsgcred, struct fcred, struct sockcred], [], [],
780780
#include <sys/socket.h>
781781
#include <sys/ucred.h>])
782782

783+
AC_CHECK_TYPES([struct option], [], [],
784+
[#ifdef HAVE_GETOPT_H
785+
include <getopt.h>
786+
#endif])
787+
783788
if test "$with_zlib" = yes; then
784789
# Check that <zlib.h> defines z_streamp (versions before about 1.0.4
785790
# did not). While we could work around the lack of z_streamp, it
@@ -875,7 +880,7 @@ else
875880
AC_CHECK_FUNCS([fpclass fp_class fp_class_d class], [break])
876881
fi
877882

878-
AC_REPLACE_FUNCS([crypt fseeko getopt getopt_long getrusage inet_aton random rint srandom strcasecmp strdup strerror strtol strtoul])
883+
AC_REPLACE_FUNCS([crypt fseeko getopt getrusage inet_aton random rint srandom strcasecmp strdup strerror strtol strtoul])
879884

880885
# system's version of getaddrinfo(), if any, may be used only if we found
881886
# a definition for struct addrinfo; see notes in src/include/getaddrinfo.h
@@ -885,6 +890,13 @@ else
885890
AC_LIBOBJ(getaddrinfo)
886891
fi
887892

893+
# similarly, use system's getopt_long() only if system provides struct option.
894+
if test x"$ac_cv_type_struct_option" = xyes ; then
895+
AC_REPLACE_FUNCS([getopt_long])
896+
else
897+
AC_LIBOBJ(getopt_long)
898+
fi
899+
888900
# BSD/OS & NetBSD use a custom fseeko/ftello built on fsetpos/fgetpos
889901
# We override the previous test that said fseeko/ftello didn't exist
890902
# OS tests are also done in include/c.h and port/fseeko.c

contrib/pg_autovacuum/pg_autovacuum.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include "postgres_fe.h"
77

88
#include <unistd.h>
9-
#ifdef __GLIBC__
9+
#ifdef HAVE_GETOPT_H
1010
#include <getopt.h>
1111
#endif
1212
#include <time.h>

contrib/pg_dumplo/main.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* -------------------------------------------------------------------------
22
* pg_dumplo
33
*
4-
* $Header: /cvsroot/pgsql/contrib/pg_dumplo/Attic/main.c,v 1.17 2003/08/04 00:43:11 momjian Exp $
4+
* $Header: /cvsroot/pgsql/contrib/pg_dumplo/Attic/main.c,v 1.18 2003/08/07 21:11:57 tgl Exp $
55
*
66
* Karel Zak 1999-2000
77
* -------------------------------------------------------------------------
@@ -11,9 +11,6 @@
1111

1212
#include <errno.h>
1313
#include <unistd.h>
14-
#ifdef HAVE_GETOPT_H
15-
#include <getopt.h>
16-
#endif
1714

1815
#include "libpq-fe.h"
1916
#include "libpq/libpq-fs.h"
@@ -24,8 +21,9 @@
2421
#include "strdup.h"
2522
#endif
2623

27-
#ifndef HAVE_GETOPT_LONG
2824
#include "getopt_long.h"
25+
26+
#ifndef HAVE_OPTRESET
2927
int optreset;
3028
#endif
3129

src/bin/pg_dump/pg_dump.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* by PostgreSQL
1313
*
1414
* IDENTIFICATION
15-
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.342 2003/08/04 02:40:09 momjian Exp $
15+
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.343 2003/08/07 21:11:58 tgl Exp $
1616
*
1717
*-------------------------------------------------------------------------
1818
*/
@@ -29,9 +29,6 @@
2929
#ifdef ENABLE_NLS
3030
#include <locale.h>
3131
#endif
32-
#ifdef HAVE_GETOPT_H
33-
#include <getopt.h>
34-
#endif
3532
#ifdef HAVE_TERMIOS_H
3633
#include <termios.h>
3734
#endif
@@ -40,8 +37,9 @@
4037
#include "strdup.h"
4138
#endif
4239

43-
#ifndef HAVE_GETOPT_LONG
4440
#include "getopt_long.h"
41+
42+
#ifndef HAVE_OPTRESET
4543
int optreset;
4644
#endif
4745

src/bin/pg_dump/pg_dumpall.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1994, Regents of the University of California
77
*
88
*
9-
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dumpall.c,v 1.26 2003/08/04 02:40:09 momjian Exp $
9+
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dumpall.c,v 1.27 2003/08/07 21:11:58 tgl Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -17,16 +17,14 @@
1717
#ifdef ENABLE_NLS
1818
#include <locale.h>
1919
#endif
20-
#ifdef HAVE_GETOPT_H
21-
#include <getopt.h>
22-
#endif
2320
#ifndef HAVE_STRDUP
2421
#include "strdup.h"
2522
#endif
2623
#include <errno.h>
2724

28-
#ifndef HAVE_GETOPT_LONG
2925
#include "getopt_long.h"
26+
27+
#ifndef HAVE_OPTRESET
3028
int optreset;
3129
#endif
3230

src/bin/pg_dump/pg_restore.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
*
3535
*
3636
* IDENTIFICATION
37-
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_restore.c,v 1.49 2003/08/04 00:43:28 momjian Exp $
37+
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_restore.c,v 1.50 2003/08/07 21:11:58 tgl Exp $
3838
*
3939
*-------------------------------------------------------------------------
4040
*/
@@ -55,12 +55,9 @@
5555

5656
#include <unistd.h>
5757

58-
#ifdef HAVE_GETOPT_H
59-
#include <getopt.h>
60-
#endif
61-
62-
#ifndef HAVE_GETOPT_LONG
6358
#include "getopt_long.h"
59+
60+
#ifndef HAVE_OPTRESET
6461
int optreset;
6562
#endif
6663

src/bin/psql/startup.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright (c) 2000-2003, PostgreSQL Global Development Group
55
*
6-
* $Header: /cvsroot/pgsql/src/bin/psql/startup.c,v 1.78 2003/08/04 23:59:40 tgl Exp $
6+
* $Header: /cvsroot/pgsql/src/bin/psql/startup.c,v 1.79 2003/08/07 21:11:58 tgl Exp $
77
*/
88
#include "postgres_fe.h"
99

@@ -17,12 +17,9 @@
1717
#include <win32.h>
1818
#endif /* WIN32 */
1919

20-
#ifdef HAVE_GETOPT_H
21-
#include <getopt.h>
22-
#endif
23-
24-
#ifndef HAVE_GETOPT_LONG
2520
#include "getopt_long.h"
21+
22+
#ifndef HAVE_OPTRESET
2623
int optreset;
2724
#endif
2825

src/bin/scripts/common.h

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,8 @@
11
#include "postgres_fe.h"
22

3-
#ifdef HAVE_GETOPT_H
4-
#include <getopt.h>
5-
#endif
6-
7-
#ifndef HAVE_GETOPT_LONG
8-
#include "getopt_long.h"
9-
#endif
10-
113
#include "libpq-fe.h"
124
#include "pqexpbuffer.h"
5+
#include "getopt_long.h"
136

147
#ifndef HAVE_OPTRESET
158
int optreset;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy