summaryrefslogtreecommitdiff
path: root/src/include/port.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/include/port.h')
-rw-r--r--src/include/port.h80
1 files changed, 53 insertions, 27 deletions
diff --git a/src/include/port.h b/src/include/port.h
index f9b4a16c0a..3f187159cb 100644
--- a/src/include/port.h
+++ b/src/include/port.h
@@ -126,12 +126,11 @@ extern unsigned char pg_tolower(unsigned char ch);
extern unsigned char pg_ascii_toupper(unsigned char ch);
extern unsigned char pg_ascii_tolower(unsigned char ch);
-#ifdef USE_REPL_SNPRINTF
-
/*
- * Versions of libintl >= 0.13 try to replace printf() and friends with
- * macros to their own versions that understand the %$ format. We do the
- * same, so disable their macros, if they exist.
+ * Capture macro-compatible calls to printf() and friends, and redirect them
+ * to wrappers that throw errors in lieu of reporting failure in a return
+ * value. Versions of libintl >= 0.13 similarly redirect to versions that
+ * understand the %$ format, so disable libintl macros first.
*/
#ifdef vsnprintf
#undef vsnprintf
@@ -155,36 +154,63 @@ extern unsigned char pg_ascii_tolower(unsigned char ch);
#undef printf
#endif
-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,...) pg_attribute_printf(3, 4);
-extern int pg_vsprintf(char *str, const char *fmt, va_list args);
-extern int pg_sprintf(char *str, const char *fmt,...) pg_attribute_printf(2, 3);
-extern int pg_vfprintf(FILE *stream, const char *fmt, va_list args);
-extern int pg_fprintf(FILE *stream, const char *fmt,...) pg_attribute_printf(2, 3);
-extern int pg_printf(const char *fmt,...) pg_attribute_printf(1, 2);
+extern int
+vsnprintf_throw_on_fail(char *str, size_t count, const char *fmt, va_list args)
+pg_attribute_printf(3, 0);
+extern int
+snprintf_throw_on_fail(char *str, size_t count, const char *fmt,...)
+pg_attribute_printf(3, 4);
+extern int
+vsprintf_throw_on_fail(char *str, const char *fmt, va_list args)
+pg_attribute_printf(2, 0);
+extern int
+sprintf_throw_on_fail(char *str, const char *fmt,...)
+pg_attribute_printf(2, 3);
+extern int
+vfprintf_throw_on_fail(FILE *stream, const char *fmt, va_list args)
+pg_attribute_printf(2, 0);
+extern int
+fprintf_throw_on_fail(FILE *stream, const char *fmt,...)
+pg_attribute_printf(2, 3);
+extern int
+printf_throw_on_fail(const char *fmt,...)
+pg_attribute_printf(1, 2);
/*
* The GCC-specific code below prevents the pg_attribute_printf above from
* being replaced, and this is required because gcc doesn't know anything
- * about pg_printf.
+ * about printf_throw_on_fail.
*/
#ifdef __GNUC__
-#define vsnprintf(...) pg_vsnprintf(__VA_ARGS__)
-#define snprintf(...) pg_snprintf(__VA_ARGS__)
-#define vsprintf(...) pg_vsprintf(__VA_ARGS__)
-#define sprintf(...) pg_sprintf(__VA_ARGS__)
-#define vfprintf(...) pg_vfprintf(__VA_ARGS__)
-#define fprintf(...) pg_fprintf(__VA_ARGS__)
-#define printf(...) pg_printf(__VA_ARGS__)
+#define vsnprintf(...) vsnprintf_throw_on_fail(__VA_ARGS__)
+#define snprintf(...) snprintf_throw_on_fail(__VA_ARGS__)
+#define vsprintf(...) vsprintf_throw_on_fail(__VA_ARGS__)
+#define sprintf(...) sprintf_throw_on_fail(__VA_ARGS__)
+#define vfprintf(...) vfprintf_throw_on_fail(__VA_ARGS__)
+#define fprintf(...) fprintf_throw_on_fail(__VA_ARGS__)
+#define printf(...) printf_throw_on_fail(__VA_ARGS__)
#else
-#define vsnprintf pg_vsnprintf
-#define snprintf pg_snprintf
-#define vsprintf pg_vsprintf
-#define sprintf pg_sprintf
-#define vfprintf pg_vfprintf
-#define fprintf pg_fprintf
-#define printf pg_printf
+#define vsnprintf vsnprintf_throw_on_fail
+#define snprintf snprintf_throw_on_fail
+#define vsprintf vsprintf_throw_on_fail
+#define sprintf sprintf_throw_on_fail
+#define vfprintf vfprintf_throw_on_fail
+#define fprintf fprintf_throw_on_fail
+#define printf printf_throw_on_fail
#endif
+
+#ifdef USE_REPL_SNPRINTF
+
+/* Code outside syswrap.c should not call these. */
+
+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,...) pg_attribute_printf(3, 4);
+extern int pg_vsprintf(char *str, const char *fmt, va_list args);
+extern int pg_sprintf(char *str, const char *fmt,...) pg_attribute_printf(2, 3);
+extern int pg_vfprintf(FILE *stream, const char *fmt, va_list args);
+extern int pg_fprintf(FILE *stream, const char *fmt,...) pg_attribute_printf(2, 3);
+extern int pg_printf(const char *fmt,...) pg_attribute_printf(1, 2);
+
#endif /* USE_REPL_SNPRINTF */
#if defined(WIN32)