Fix "unrecognized format function type" warnings in old GCC.
authorHiroshi Inoue <h-inoue@dream.email.ne.jp>
Wed, 20 Sep 2017 09:52:40 +0000 (18:52 +0900)
committerHiroshi Inoue <h-inoue@dream.email.ne.jp>
Wed, 20 Sep 2017 10:40:53 +0000 (19:40 +0900)
Also use PG_PRINTF_ATTRIBUTE instead of printf in __attribute__((format(printf, .., ..))) function attribute.

connection.h
misc.h
mylog.h
psqlodbc.h

index d620b422e610e816490a116d63c718689c71395e..2118957510213bf0fdd3a90d5eb4fc356b01b31a 100644 (file)
@@ -9,24 +9,10 @@
 #ifndef __CONNECTION_H__
 #define __CONNECTION_H__
 
-#ifdef __INCLUDE_POSTGRES_FE_H__ /* currently not defined */
-/*
- * Unfortunately #including postgres_fe.h causes various trobles.
- */
-#include "postgres_fe.h"
-#else /* currently */
-#if defined(__GNUC__) || defined(__IBMC__)
-#define PG_PRINTF_ATTRIBUTE gnu_printf
-#define pg_attribute_printf(f,a) __attribute__((format(PG_PRINTF_ATTRIBUTE, f, a)))
-#else
-#define pg_attribute_printf(f,a)
-#endif /* __GNUC__ || __IBMC__ */
-#endif /* __INCLUDE_POSTGRES_FE_H__ */
-
+#include "psqlodbc.h"
 #include <libpq-fe.h>
 #include "pqexpbuffer.h"
 
-#include "psqlodbc.h"
 #include <time.h>
 
 #include <stdlib.h>
diff --git a/misc.h b/misc.h
index 81c18ef6aed79085538827a5b091d02f764a17b6..9518335c4eaeb99f647ef8e591a9a959ae03e6dc 100644 (file)
--- a/misc.h
+++ b/misc.h
@@ -22,7 +22,7 @@ char     *strncpy_null(char *dst, const char *src, ssize_t len);
 #ifndef    HAVE_STRLCAT
 size_t     strlcat(char *, const char *, size_t);
 #endif /* HAVE_STRLCAT */
-int       snprintfcat(char *buf, size_t size, const char *format, ...) __attribute__((format(printf,3,4)));
+int       snprintfcat(char *buf, size_t size, const char *format, ...) __attribute__((format(PG_PRINTF_ATTRIBUTE,3,4)));
 size_t    snprintf_len(char *buf, size_t size, const char *format, ...);
 
 char      *my_trim(char *string);
diff --git a/mylog.h b/mylog.h
index cd2a1b0c38fa4f2c0fbe2428a81b756d8bd7350b..772665037e5da66f3db43844d415357adbeb6662 100644 (file)
--- a/mylog.h
+++ b/mylog.h
@@ -34,14 +34,14 @@ extern "C" {
 #endif
 
 #ifndef    __GNUC__
-#define    __attribute__(x)
+#define __attribute__(x)
 #endif
 
-DLL_DECLARE int mylog(const char *fmt,...) __attribute__((format(printf, 1, 2)));
-DLL_DECLARE int myprintf(const char *fmt,...) __attribute__((format(printf, 1, 2)));
+DLL_DECLARE int mylog(const char *fmt,...) __attribute__((format(PG_PRINTF_ATTRIBUTE, 1, 2)));
+DLL_DECLARE int myprintf(const char *fmt,...) __attribute__((format(PG_PRINTF_ATTRIBUTE, 1, 2)));
 
-extern int qlog(char *fmt,...) __attribute__((format(printf, 1, 2)));
-extern int qprintf(char *fmt,...) __attribute__((format(printf, 1, 2)));
+extern int qlog(char *fmt,...) __attribute__((format(PG_PRINTF_ATTRIBUTE, 1, 2)));
+extern int qprintf(char *fmt,...) __attribute__((format(PG_PRINTF_ATTRIBUTE, 1, 2)));
 
 const char *po_basename(const char *path);
 
index b91969d00bf21d327f2f8fcd90dbd71fc2ed9d07..de5bd5299bc84ea31f337293464d8bd12bd8302d 100644 (file)
 #include <stdlib.h>
 #endif /* WIN32 */
 
-#ifndef    __GNUC__
+#ifdef  __INCLUDE_POSTGRES_FE_H__ /* currently not defined */
+/*
+ *      Unfortunately #including postgres_fe.h causes various trobles.
+ */
+#include "postgres_fe.h"
+#else /* currently */
+#if defined(__GNUC__) || defined(__IBMC__)
+#if ((__GNUC__ * 100) + __GNUC_MINOR__) >= 404
+#define PG_PRINTF_ATTRIBUTE gnu_printf
+#else
+#define PG_PRINTF_ATTRIBUTE printf
+#endif
+#define pg_attribute_printf(f,a) __attribute__((format(PG_PRINTF_ATTRIBUTE, f, a)))
+#else
 #define    __attribute__(x)
-#endif /* __GNUC__ */
+#define pg_attribute_printf(f,a)
+#endif  /* __GNUC__ || __IBMC__ */
+#endif  /* __INCLUDE_POSTGRES_FE_H__ */
 
 #ifdef _MEMORY_DEBUG_
 void       *pgdebug_alloc(size_t);