From caad817d1c250017b3f456417ecf14fa7ad083e6 Mon Sep 17 00:00:00 2001
From: Bruce Momjian <bruce@momjian.us>
Date: Fri, 11 Mar 2005 19:13:43 +0000
Subject: [PATCH] Add fprintf() custom version to libpgport.

Document use of macros for pg_printf functions.

Bump major versions of all interfaces to handle movement of get_progname
from libpq to libpgport in 8.0, and probably other libpgport changes in 8.1.
---
 src/backend/bootstrap/bootscanner.l     |  3 ++-
 src/backend/parser/scan.l               |  3 ++-
 src/backend/utils/misc/guc-file.l       |  3 ++-
 src/include/port.h                      | 14 +++++++++--
 src/interfaces/ecpg/compatlib/Makefile  |  6 ++---
 src/interfaces/ecpg/ecpglib/Makefile    |  6 ++---
 src/interfaces/ecpg/pgtypeslib/Makefile |  6 ++---
 src/interfaces/ecpg/preproc/Makefile    |  6 ++---
 src/interfaces/libpq/Makefile           |  6 ++---
 src/pl/plpgsql/src/scan.l               |  3 ++-
 src/port/snprintf.c                     | 31 +++++++++++++++++++++----
 src/tools/RELEASE_CHANGES               |  3 ++-
 12 files changed, 64 insertions(+), 26 deletions(-)

diff --git a/src/backend/bootstrap/bootscanner.l b/src/backend/bootstrap/bootscanner.l
index f2e80fa212a..2cec26078af 100644
--- a/src/backend/bootstrap/bootscanner.l
+++ b/src/backend/bootstrap/bootscanner.l
@@ -9,7 +9,7 @@
  *
  *
  * IDENTIFICATION
- *	  $PostgreSQL: pgsql/src/backend/bootstrap/bootscanner.l,v 1.38 2004/12/31 21:59:34 pgsql Exp $
+ *	  $PostgreSQL: pgsql/src/backend/bootstrap/bootscanner.l,v 1.39 2005/03/11 19:13:42 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -42,6 +42,7 @@
 
 
 /* Avoid exit() on fatal scanner errors (a bit ugly -- see yy_fatal_error) */
+#undef fprintf
 #define fprintf(file, fmt, msg)  ereport(ERROR, (errmsg_internal("%s", msg)))
 
 
diff --git a/src/backend/parser/scan.l b/src/backend/parser/scan.l
index 5bd817c2252..a0635463bb6 100644
--- a/src/backend/parser/scan.l
+++ b/src/backend/parser/scan.l
@@ -10,7 +10,7 @@
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * IDENTIFICATION
- *	  $PostgreSQL: pgsql/src/backend/parser/scan.l,v 1.120 2005/02/22 04:36:22 momjian Exp $
+ *	  $PostgreSQL: pgsql/src/backend/parser/scan.l,v 1.121 2005/03/11 19:13:42 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -28,6 +28,7 @@
 
 
 /* Avoid exit() on fatal scanner errors (a bit ugly -- see yy_fatal_error) */
+#undef fprintf
 #define fprintf(file, fmt, msg)  ereport(ERROR, (errmsg_internal("%s", msg)))
 
 extern YYSTYPE yylval;
diff --git a/src/backend/utils/misc/guc-file.l b/src/backend/utils/misc/guc-file.l
index 60a42232a67..c65acaff9f1 100644
--- a/src/backend/utils/misc/guc-file.l
+++ b/src/backend/utils/misc/guc-file.l
@@ -4,7 +4,7 @@
  *
  * Copyright (c) 2000-2005, PostgreSQL Global Development Group
  *
- * $PostgreSQL: pgsql/src/backend/utils/misc/guc-file.l,v 1.29 2005/01/01 05:43:08 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/misc/guc-file.l,v 1.30 2005/03/11 19:13:42 momjian Exp $
  */
 
 %{
@@ -19,6 +19,7 @@
 #include "utils/guc.h"
 
 /* Avoid exit() on fatal scanner errors (a bit ugly -- see yy_fatal_error) */
+#undef fprintf
 #define fprintf(file, fmt, msg)  ereport(ERROR, (errmsg_internal("%s", msg)))
 
 static unsigned ConfigFileLineno;
diff --git a/src/include/port.h b/src/include/port.h
index 5a2953ce600..169ee7ac150 100644
--- a/src/include/port.h
+++ b/src/include/port.h
@@ -6,7 +6,7 @@
  * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/include/port.h,v 1.71 2005/03/11 17:20:34 momjian Exp $
+ * $PostgreSQL: pgsql/src/include/port.h,v 1.72 2005/03/11 19:13:42 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -112,17 +112,27 @@ extern int pg_vsnprintf(char *str, size_t count, const char *fmt, va_list args);
 extern int pg_snprintf(char *str, size_t count, const char *fmt,...)
 /* This extension allows gcc to check the format string */
 __attribute__((format(printf, 3, 4)));
+extern int pg_fprintf(FILE *stream, const char *fmt,...)
+/* This extension allows gcc to check the format string */
+__attribute__((format(printf, 2, 3)));
 extern int pg_printf(const char *fmt,...)
 /* This extension allows gcc to check the format string */
 __attribute__((format(printf, 1, 2)));
 
+/*
+ *	The GCC-specific code below prevents the __attribute__(... 'printf')
+ *	above from being replaced, and this is required because gcc doesn't
+ *	know anything about pg_printf.
+ */
 #ifdef __GNUC__
-#define vsnprintf(...)	pg_vsnprintf(__VA_ARGS__)
+#define	vsnprintf(...)	pg_vsnprintf(__VA_ARGS__)
 #define snprintf(...)	pg_snprintf(__VA_ARGS__)
+#define fprintf(...)	pg_fprintf(__VA_ARGS__)
 #define printf(...)		pg_printf(__VA_ARGS__)
 #else
 #define vsnprintf		pg_vsnprintf
 #define snprintf		pg_snprintf
+#define fprintf			pg_fprintf
 #define printf			pg_printf
 #endif
 #endif
diff --git a/src/interfaces/ecpg/compatlib/Makefile b/src/interfaces/ecpg/compatlib/Makefile
index 45f945281bc..c838c159e1a 100644
--- a/src/interfaces/ecpg/compatlib/Makefile
+++ b/src/interfaces/ecpg/compatlib/Makefile
@@ -4,7 +4,7 @@
 #
 # Copyright (c) 1994, Regents of the University of California
 #
-# $PostgreSQL: pgsql/src/interfaces/ecpg/compatlib/Makefile,v 1.19 2005/01/18 05:00:15 momjian Exp $
+# $PostgreSQL: pgsql/src/interfaces/ecpg/compatlib/Makefile,v 1.20 2005/03/11 19:13:42 momjian Exp $
 #
 #-------------------------------------------------------------------------
 
@@ -13,8 +13,8 @@ top_builddir = ../../../..
 include $(top_builddir)/src/Makefile.global
 
 NAME= ecpg_compat
-SO_MAJOR_VERSION= 1
-SO_MINOR_VERSION= 2
+SO_MAJOR_VERSION= 2
+SO_MINOR_VERSION= 0
 DLTYPE= library
 
 override CPPFLAGS := -I$(top_srcdir)/src/interfaces/ecpg/include -I$(libpq_srcdir) \
diff --git a/src/interfaces/ecpg/ecpglib/Makefile b/src/interfaces/ecpg/ecpglib/Makefile
index c28503c1359..1907434839b 100644
--- a/src/interfaces/ecpg/ecpglib/Makefile
+++ b/src/interfaces/ecpg/ecpglib/Makefile
@@ -4,7 +4,7 @@
 #
 # Copyright (c) 1994, Regents of the University of California
 #
-# $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/Makefile,v 1.31 2005/01/26 19:24:01 tgl Exp $
+# $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/Makefile,v 1.32 2005/03/11 19:13:42 momjian Exp $
 #
 #-------------------------------------------------------------------------
 
@@ -13,8 +13,8 @@ top_builddir = ../../../..
 include $(top_builddir)/src/Makefile.global
 
 NAME= ecpg
-SO_MAJOR_VERSION= 4
-SO_MINOR_VERSION= 3
+SO_MAJOR_VERSION= 5
+SO_MINOR_VERSION= 0
 DLTYPE= library
 
 override CPPFLAGS := -DFRONTEND -I$(top_srcdir)/src/interfaces/ecpg/include \
diff --git a/src/interfaces/ecpg/pgtypeslib/Makefile b/src/interfaces/ecpg/pgtypeslib/Makefile
index 8305512dfe9..8b14239b780 100644
--- a/src/interfaces/ecpg/pgtypeslib/Makefile
+++ b/src/interfaces/ecpg/pgtypeslib/Makefile
@@ -4,7 +4,7 @@
 #
 # Copyright (c) 1994, Regents of the University of California
 #
-# $PostgreSQL: pgsql/src/interfaces/ecpg/pgtypeslib/Makefile,v 1.24 2005/01/18 05:00:23 momjian Exp $
+# $PostgreSQL: pgsql/src/interfaces/ecpg/pgtypeslib/Makefile,v 1.25 2005/03/11 19:13:43 momjian Exp $
 #
 #-------------------------------------------------------------------------
 
@@ -13,8 +13,8 @@ top_builddir = ../../../..
 include $(top_builddir)/src/Makefile.global
 
 NAME= pgtypes
-SO_MAJOR_VERSION= 1
-SO_MINOR_VERSION= 3
+SO_MAJOR_VERSION= 2
+SO_MINOR_VERSION= 0
 DLTYPE= library
 
 override CPPFLAGS := -I$(top_srcdir)/src/interfaces/ecpg/include \
diff --git a/src/interfaces/ecpg/preproc/Makefile b/src/interfaces/ecpg/preproc/Makefile
index a0599bcf5ef..ec9fbda4d3d 100644
--- a/src/interfaces/ecpg/preproc/Makefile
+++ b/src/interfaces/ecpg/preproc/Makefile
@@ -4,7 +4,7 @@
 #
 # Copyright (c) 1998-2005, PostgreSQL Global Development Group
 #
-# $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/Makefile,v 1.112 2005/01/25 12:51:31 meskes Exp $
+# $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/Makefile,v 1.113 2005/03/11 19:13:43 momjian Exp $
 #
 #-------------------------------------------------------------------------
 
@@ -13,8 +13,8 @@ subdir = src/interfaces/ecpg/preproc
 top_builddir = ../../../..
 include $(top_builddir)/src/Makefile.global
 
-MAJOR_VERSION=3
-MINOR_VERSION=2
+MAJOR_VERSION= 4
+MINOR_VERSION= 0
 PATCHLEVEL=1
 
 override CPPFLAGS := -I$(srcdir)/../include -I$(srcdir) $(CPPFLAGS) \
diff --git a/src/interfaces/libpq/Makefile b/src/interfaces/libpq/Makefile
index 1867fbd9cb0..d565517e391 100644
--- a/src/interfaces/libpq/Makefile
+++ b/src/interfaces/libpq/Makefile
@@ -5,7 +5,7 @@
 # Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
 # Portions Copyright (c) 1994, Regents of the University of California
 #
-# $PostgreSQL: pgsql/src/interfaces/libpq/Makefile,v 1.128 2005/01/26 19:24:02 tgl Exp $
+# $PostgreSQL: pgsql/src/interfaces/libpq/Makefile,v 1.129 2005/03/11 19:13:43 momjian Exp $
 #
 #-------------------------------------------------------------------------
 
@@ -16,8 +16,8 @@ include $(top_builddir)/src/Makefile.global
 
 # shared library parameters
 NAME= pq
-SO_MAJOR_VERSION= 3
-SO_MINOR_VERSION= 3
+SO_MAJOR_VERSION= 4
+SO_MINOR_VERSION= 0
 DLTYPE= library
 
 override CPPFLAGS :=  -DFRONTEND -I$(srcdir) $(CPPFLAGS) -I$(top_builddir)/src/port
diff --git a/src/pl/plpgsql/src/scan.l b/src/pl/plpgsql/src/scan.l
index b4643d9e618..f9295196439 100644
--- a/src/pl/plpgsql/src/scan.l
+++ b/src/pl/plpgsql/src/scan.l
@@ -4,7 +4,7 @@
  *			  procedural language
  *
  * IDENTIFICATION
- *    $PostgreSQL: pgsql/src/pl/plpgsql/src/scan.l,v 1.39 2005/02/22 07:18:24 neilc Exp $
+ *    $PostgreSQL: pgsql/src/pl/plpgsql/src/scan.l,v 1.40 2005/03/11 19:13:43 momjian Exp $
  *
  *    This software is copyrighted by Jan Wieck - Hamburg.
  *
@@ -45,6 +45,7 @@
 #define YY_READ_BUF_SIZE 16777216
 
 /* Avoid exit() on fatal scanner errors (a bit ugly -- see yy_fatal_error) */
+#undef fprintf
 #define fprintf(file, fmt, msg)  ereport(ERROR, (errmsg_internal("%s", msg)))
 
 /* Handles to the buffer that the lexer uses internally */
diff --git a/src/port/snprintf.c b/src/port/snprintf.c
index 1d85c8d830e..602f7fed9c6 100644
--- a/src/port/snprintf.c
+++ b/src/port/snprintf.c
@@ -65,13 +65,19 @@
  * causing nasty effects.
  **************************************************************/
 
-/*static char _id[] = "$PostgreSQL: pgsql/src/port/snprintf.c,v 1.17 2005/03/11 17:20:35 momjian Exp $";*/
+/*static char _id[] = "$PostgreSQL: pgsql/src/port/snprintf.c,v 1.18 2005/03/11 19:13:43 momjian Exp $";*/
 
 int			pg_snprintf(char *str, size_t count, const char *fmt,...);
 int			pg_vsnprintf(char *str, size_t count, const char *fmt, va_list args);
 int			pg_printf(const char *format, ...);
 static void dopr(char *buffer, const char *format, va_list args, char *end);
 
+/* Prevent recursion */
+#undef	vsnprintf
+#undef	snprintf
+#undef	fprintf
+#undef	printf
+
 int
 pg_vsnprintf(char *str, size_t count, const char *fmt, va_list args)
 {
@@ -96,19 +102,36 @@ pg_snprintf(char *str, size_t count, const char *fmt,...)
 	return len;
 }
 
+int
+pg_fprintf(FILE *stream, const char *fmt,...)
+{
+	int			len;
+	va_list		args;
+	char*		buffer[4096];
+	char*		p;
+
+	va_start(args, fmt);
+	len = pg_vsnprintf((char*)buffer, (size_t)4096, fmt, args);
+	va_end(args);
+	p = (char*)buffer;
+	for( ;*p; p++)
+		putc(*p, stream);
+	return len;
+}
+
 int
 pg_printf(const char *fmt,...)
 {
 	int			len;
-	va_list			args;
+	va_list		args;
 	char*		buffer[4096];
-	char*			p;
+	char*		p;
 
 	va_start(args, fmt);
 	len = pg_vsnprintf((char*)buffer, (size_t)4096, fmt, args);
 	va_end(args);
 	p = (char*)buffer;
-	for(;*p;p++)
+	for( ;*p; p++)
 		putchar(*p);
 	return len;
 }
diff --git a/src/tools/RELEASE_CHANGES b/src/tools/RELEASE_CHANGES
index 309b0f81fad..3ee69b9d3af 100644
--- a/src/tools/RELEASE_CHANGES
+++ b/src/tools/RELEASE_CHANGES
@@ -6,9 +6,10 @@
 * Version numbers
 	o configure.in, and run autoconf or update configure
 	o doc/bug.template
-	o bump interface version numbers
+	o bump library versions
 		- src/interfaces/*/Makefile (major releases only)
 		- src/interfaces/*/*/Makefile (major releases only)
+	o bump interface version numbers
 		- src/interfaces/libpq/libpq.rc.in (major and minor releases)
 		- src/include/pg_config.h.win32 (major and minor releases)
 		- src/port/win32ver.rc (major and minor releases)
-- 
GitLab