agora inbox for pgsql-hackers@postgresql.org  
help / color / mirror / Atom feed
[PATCH v16 3/8] Row pattern recognition patch (rewriter).
144+ messages / 2 participants
[nested] [flat]

* [PATCH v16 3/8] Row pattern recognition patch (rewriter).
@ 2024-04-12 06:49 Tatsuo Ishii <ishii@postgresql.org>
  0 siblings, 0 replies; 144+ messages in thread

From: Tatsuo Ishii @ 2024-04-12 06:49 UTC (permalink / raw)

---
 src/backend/utils/adt/ruleutils.c | 103 ++++++++++++++++++++++++++++++
 1 file changed, 103 insertions(+)

diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 24e3514b00..c204565cc1 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -426,6 +426,10 @@ static void get_rule_groupingset(GroupingSet *gset, List *targetlist,
 								 bool omit_parens, deparse_context *context);
 static void get_rule_orderby(List *orderList, List *targetList,
 							 bool force_colno, deparse_context *context);
+static void get_rule_pattern(List *patternVariable, List *patternRegexp,
+							 bool force_colno, deparse_context *context);
+static void get_rule_define(List *defineClause, List *patternVariables,
+							bool force_colno, deparse_context *context);
 static void get_rule_windowclause(Query *query, deparse_context *context);
 static void get_rule_windowspec(WindowClause *wc, List *targetList,
 								deparse_context *context);
@@ -6487,6 +6491,67 @@ get_rule_orderby(List *orderList, List *targetList,
 	}
 }
 
+/*
+ * Display a PATTERN clause.
+ */
+static void
+get_rule_pattern(List *patternVariable, List *patternRegexp,
+				 bool force_colno, deparse_context *context)
+{
+	StringInfo	buf = context->buf;
+	const char *sep;
+	ListCell   *lc_var,
+			   *lc_reg = list_head(patternRegexp);
+
+	sep = "";
+	appendStringInfoChar(buf, '(');
+	foreach(lc_var, patternVariable)
+	{
+		char	   *variable = strVal((String *) lfirst(lc_var));
+		char	   *regexp = NULL;
+
+		if (lc_reg != NULL)
+		{
+			regexp = strVal((String *) lfirst(lc_reg));
+
+			lc_reg = lnext(patternRegexp, lc_reg);
+		}
+
+		appendStringInfo(buf, "%s%s", sep, variable);
+		if (regexp !=NULL)
+			appendStringInfoString(buf, regexp);
+
+		sep = " ";
+	}
+	appendStringInfoChar(buf, ')');
+}
+
+/*
+ * Display a DEFINE clause.
+ */
+static void
+get_rule_define(List *defineClause, List *patternVariables,
+				bool force_colno, deparse_context *context)
+{
+	StringInfo	buf = context->buf;
+	const char *sep;
+	ListCell   *lc_var,
+			   *lc_def;
+
+	sep = "  ";
+	Assert(list_length(patternVariables) == list_length(defineClause));
+
+	forboth(lc_var, patternVariables, lc_def, defineClause)
+	{
+		char	   *varName = strVal(lfirst(lc_var));
+		TargetEntry *te = (TargetEntry *) lfirst(lc_def);
+
+		appendStringInfo(buf, "%s%s AS ", sep, varName);
+		get_rule_expr((Node *) te->expr, context, false);
+		sep = ",\n  ";
+	}
+}
+
 /*
  * Display a WINDOW clause.
  *
@@ -6624,6 +6689,44 @@ get_rule_windowspec(WindowClause *wc, List *targetList,
 			appendStringInfoString(buf, "EXCLUDE GROUP ");
 		else if (wc->frameOptions & FRAMEOPTION_EXCLUDE_TIES)
 			appendStringInfoString(buf, "EXCLUDE TIES ");
+		/* RPR */
+		if (wc->rpSkipTo == ST_NEXT_ROW)
+			appendStringInfoString(buf,
+								   "\n  AFTER MATCH SKIP TO NEXT ROW ");
+		else if (wc->rpSkipTo == ST_PAST_LAST_ROW)
+			appendStringInfoString(buf,
+								   "\n  AFTER MATCH SKIP PAST LAST ROW ");
+		else if (wc->rpSkipTo == ST_FIRST_VARIABLE)
+			appendStringInfo(buf,
+							 "\n  AFTER MATCH SKIP TO FIRST %s ",
+							 wc->rpSkipVariable);
+		else if (wc->rpSkipTo == ST_LAST_VARIABLE)
+			appendStringInfo(buf,
+							 "\n  AFTER MATCH SKIP TO LAST %s ",
+							 wc->rpSkipVariable);
+		else if (wc->rpSkipTo == ST_VARIABLE)
+			appendStringInfo(buf,
+							 "\n  AFTER MATCH SKIP TO %s ",
+							 wc->rpSkipVariable);
+
+		if (wc->initial)
+			appendStringInfoString(buf, "\n  INITIAL");
+
+		if (wc->patternVariable)
+		{
+			appendStringInfoString(buf, "\n  PATTERN ");
+			get_rule_pattern(wc->patternVariable, wc->patternRegexp,
+							 false, context);
+		}
+
+		if (wc->defineClause)
+		{
+			appendStringInfoString(buf, "\n  DEFINE\n");
+			get_rule_define(wc->defineClause, wc->patternVariable,
+							false, context);
+			appendStringInfoChar(buf, ' ');
+		}
+
 		/* we will now have a trailing space; remove it */
 		buf->len--;
 	}
-- 
2.25.1


----Next_Part(Fri_Apr_12_16_09_08_2024_262)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="v16-0004-Row-pattern-recognition-patch-planner.patch"



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread

* [PATCH v2 1/2] Add a binary to test getopt_long()
@ 2026-07-22 03:55 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 144+ messages in thread

From: Japin Li @ 2026-07-22 03:55 UTC (permalink / raw)

---
 src/bin/Makefile                            |  1 +
 src/bin/getopt_long_test/Makefile           | 26 +++++++++++++++++++++
 src/bin/getopt_long_test/getopt_long_test.c | 25 ++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 src/bin/getopt_long_test/Makefile
 create mode 100644 src/bin/getopt_long_test/getopt_long_test.c

diff --git a/src/bin/Makefile b/src/bin/Makefile
index 538af88a523..b25305f9db5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,6 +14,7 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
 SUBDIRS = \
+	getopt_long_test \
 	initdb \
 	pg_amcheck \
 	pg_archivecleanup \
diff --git a/src/bin/getopt_long_test/Makefile b/src/bin/getopt_long_test/Makefile
new file mode 100644
index 00000000000..f7de6ef872c
--- /dev/null
+++ b/src/bin/getopt_long_test/Makefile
@@ -0,0 +1,26 @@
+PGFILEDESC = "getopt_long_test - test PostgreSQL getopt_long() function"
+PGAPPICON = win32
+
+subdir = src/bin/getopt_long_test
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+PG_CPPFLAGS += -I$(top_srcdir)/src/port
+
+OBJS = \
+	$(WIN32RES) \
+	getopt_long.o \
+	getopt_long_test.o
+
+all: getopt_long_test
+
+getopt_long_test: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+
+getopt_long_test.o: getopt_long_test.c $(top_builddir)/src/Makefile.global
+
+getopt_long.c:
+	ln -s $(top_srcdir)/src/port/getopt_long.c .
+
+clean distclean:
+	rm -f getopt_long_test$(X) $(OBJS) getopt_long.c
diff --git a/src/bin/getopt_long_test/getopt_long_test.c b/src/bin/getopt_long_test/getopt_long_test.c
new file mode 100644
index 00000000000..4abd042bbaa
--- /dev/null
+++ b/src/bin/getopt_long_test/getopt_long_test.c
@@ -0,0 +1,25 @@
+
+#include "postgres.h"
+
+#include "getopt_long.h"
+
+int
+main(int argc, char **argv)
+{
+	int c;
+	const char		*shortopts = ":f:";
+	struct option	 longopts[] = {
+		{"log-filename", required_argument, NULL, 'f'},
+		{NULL, 0, NULL, 0},
+	};
+
+	while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
+	{
+		if (c == ':')
+			fprintf(stderr, "option '%s' requires an argument\n", argv[optind - 1]);
+		else if (c == '?')
+			fprintf(stderr, "unrecognized option '%s'\n", argv[optind - 1]);
+	}
+
+	return 0;
+}
-- 
2.53.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v2-0002-Fix-optind-handling-inconsistency-in-getopt_long-.patch



^ permalink  raw  reply  [nested|flat] 144+ messages in thread


end of thread, other threads:[~2026-07-22 03:55 UTC | newest]

Thread overview: 144+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2024-04-12 06:49 [PATCH v16 3/8] Row pattern recognition patch (rewriter). Tatsuo Ishii <ishii@postgresql.org>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>
2026-07-22 03:55 [PATCH v2 1/2] Add a binary to test getopt_long() Japin Li <japinli@hotmail.com>

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox