Skip to content

Commit 770bddc

Browse files
committed
Fix up getopt() reset management so it works on recent mingw.
The mingw people don't appear to care about compatibility with non-GNU versions of getopt, so force use of our own copy of getopt on Windows. Also, ensure that we make use of optreset when using our own copy. Per report from Andrew Dunstan. Back-patch to all versions supported on Windows.
1 parent d45f163 commit 770bddc

File tree

4 files changed

+41
-15
lines changed

4 files changed

+41
-15
lines changed

configure

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20713,6 +20713,23 @@ esac
2071320713

2071420714
fi
2071520715

20716+
# mingw has adopted a GNU-centric interpretation of optind/optreset,
20717+
# so always use our version on Windows.
20718+
if test "$PORTNAME" = "win32"; then
20719+
case " $LIBOBJS " in
20720+
*" getopt.$ac_objext "* ) ;;
20721+
*) LIBOBJS="$LIBOBJS getopt.$ac_objext"
20722+
;;
20723+
esac
20724+
20725+
case " $LIBOBJS " in
20726+
*" getopt_long.$ac_objext "* ) ;;
20727+
*) LIBOBJS="$LIBOBJS getopt_long.$ac_objext"
20728+
;;
20729+
esac
20730+
20731+
fi
20732+
2071620733
# Cygwin's erand48() is broken (always returns zero) in some releases,
2071720734
# so force use of ours.
2071820735
if test "$PORTNAME" = "cygwin"; then
@@ -20835,25 +20852,25 @@ fi
2083520852
done
2083620853

2083720854

20838-
case " $LIBOBJS " in
20855+
case " $LIBOBJS " in
2083920856
*" kill.$ac_objext "* ) ;;
2084020857
*) LIBOBJS="$LIBOBJS kill.$ac_objext"
2084120858
;;
2084220859
esac
2084320860

20844-
case " $LIBOBJS " in
20861+
case " $LIBOBJS " in
2084520862
*" open.$ac_objext "* ) ;;
2084620863
*) LIBOBJS="$LIBOBJS open.$ac_objext"
2084720864
;;
2084820865
esac
2084920866

20850-
case " $LIBOBJS " in
20867+
case " $LIBOBJS " in
2085120868
*" win32env.$ac_objext "* ) ;;
2085220869
*) LIBOBJS="$LIBOBJS win32env.$ac_objext"
2085320870
;;
2085420871
esac
2085520872

20856-
case " $LIBOBJS " in
20873+
case " $LIBOBJS " in
2085720874
*" win32error.$ac_objext "* ) ;;
2085820875
*) LIBOBJS="$LIBOBJS win32error.$ac_objext"
2085920876
;;

configure.in

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1328,6 +1328,13 @@ if test "$PORTNAME" = "solaris"; then
13281328
AC_LIBOBJ(getopt)
13291329
fi
13301330

1331+
# mingw has adopted a GNU-centric interpretation of optind/optreset,
1332+
# so always use our version on Windows.
1333+
if test "$PORTNAME" = "win32"; then
1334+
AC_LIBOBJ(getopt)
1335+
AC_LIBOBJ(getopt_long)
1336+
fi
1337+
13311338
# Cygwin's erand48() is broken (always returns zero) in some releases,
13321339
# so force use of ours.
13331340
if test "$PORTNAME" = "cygwin"; then
@@ -1336,13 +1343,13 @@ fi
13361343

13371344
# Win32 support
13381345
if test "$PORTNAME" = "win32"; then
1339-
AC_REPLACE_FUNCS(gettimeofday)
1340-
AC_LIBOBJ(kill)
1341-
AC_LIBOBJ(open)
1342-
AC_LIBOBJ(win32env)
1343-
AC_LIBOBJ(win32error)
1344-
AC_DEFINE([HAVE_SYMLINK], 1,
1345-
[Define to 1 if you have the `symlink' function.])
1346+
AC_REPLACE_FUNCS(gettimeofday)
1347+
AC_LIBOBJ(kill)
1348+
AC_LIBOBJ(open)
1349+
AC_LIBOBJ(win32env)
1350+
AC_LIBOBJ(win32error)
1351+
AC_DEFINE([HAVE_SYMLINK], 1,
1352+
[Define to 1 if you have the `symlink' function.])
13461353
fi
13471354

13481355
if test "$with_readline" = yes; then

src/backend/postmaster/postmaster.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,8 @@ extern char *optarg;
312312
extern int optind,
313313
opterr;
314314

315-
#ifdef HAVE_INT_OPTRESET
315+
/* If not HAVE_GETOPT, we are using src/port/getopt.c, which has optreset */
316+
#if defined(HAVE_INT_OPTRESET) || !defined(HAVE_GETOPT)
316317
extern int optreset; /* might not be declared by system headers */
317318
#endif
318319

@@ -750,7 +751,7 @@ PostmasterMain(int argc, char *argv[])
750751
* getopt(3) library so that it will work correctly in subprocesses.
751752
*/
752753
optind = 1;
753-
#ifdef HAVE_INT_OPTRESET
754+
#if defined(HAVE_INT_OPTRESET) || !defined(HAVE_GETOPT)
754755
optreset = 1; /* some systems need this too */
755756
#endif
756757

src/backend/tcop/postgres.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@
7777
extern char *optarg;
7878
extern int optind;
7979

80-
#ifdef HAVE_INT_OPTRESET
80+
/* If not HAVE_GETOPT, we are using src/port/getopt.c, which has optreset */
81+
#if defined(HAVE_INT_OPTRESET) || !defined(HAVE_GETOPT)
8182
extern int optreset; /* might not be declared by system headers */
8283
#endif
8384

@@ -3439,7 +3440,7 @@ process_postgres_switches(int argc, char *argv[], GucContext ctx)
34393440
* or when this function is called a second time with another array.
34403441
*/
34413442
optind = 1;
3442-
#ifdef HAVE_INT_OPTRESET
3443+
#if defined(HAVE_INT_OPTRESET) || !defined(HAVE_GETOPT)
34433444
optreset = 1; /* some systems need this too */
34443445
#endif
34453446

0 commit comments

Comments
 (0)