Hello all, The src/bin/initdb/initdb.c provides three macros to write data to cmdfd. All of these macro do the same, but with different amount of arguments for fprintf().
Attached patch introduces PG_CMD_PRINTF macro which will take set of variadic arguments via __VA_ARGS__ to replace the PG_CMD_PRINTF{1,2,3} macros. Any objections?
diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c index ed3ba7b..cd0ea72 100644 --- a/src/bin/initdb/initdb.c +++ b/src/bin/initdb/initdb.c @@ -307,21 +307,9 @@ do { \ output_failed = true, output_errno = errno; \ } while (0) -#define PG_CMD_PRINTF1(fmt, arg1) \ +#define PG_CMD_PRINTF(fmt, ...) \ do { \ - if (fprintf(cmdfd, fmt, arg1) < 0 || fflush(cmdfd) < 0) \ - output_failed = true, output_errno = errno; \ -} while (0) - -#define PG_CMD_PRINTF2(fmt, arg1, arg2) \ -do { \ - if (fprintf(cmdfd, fmt, arg1, arg2) < 0 || fflush(cmdfd) < 0) \ - output_failed = true, output_errno = errno; \ -} while (0) - -#define PG_CMD_PRINTF3(fmt, arg1, arg2, arg3) \ -do { \ - if (fprintf(cmdfd, fmt, arg1, arg2, arg3) < 0 || fflush(cmdfd) < 0) \ + if (fprintf(cmdfd, fmt, __VA_ARGS__) < 0 || fflush(cmdfd) < 0) \ output_failed = true, output_errno = errno; \ } while (0) @@ -1604,8 +1592,8 @@ get_set_pwd(FILE *cmdfd) } - PG_CMD_PRINTF2("ALTER USER \"%s\" WITH PASSWORD E'%s';\n\n", - username, escape_quotes(pwd1)); + PG_CMD_PRINTF("ALTER USER \"%s\" WITH PASSWORD E'%s';\n\n", + username, escape_quotes(pwd1)); free(pwd1); } @@ -1724,8 +1712,8 @@ setup_description(FILE *cmdfd) " objsubid int4, " " description text) WITHOUT OIDS;\n\n"); - PG_CMD_PRINTF1("COPY tmp_pg_description FROM E'%s';\n\n", - escape_quotes(desc_file)); + PG_CMD_PRINTF("COPY tmp_pg_description FROM E'%s';\n\n", + escape_quotes(desc_file)); PG_CMD_PUTS("INSERT INTO pg_description " " SELECT t.objoid, c.oid, t.objsubid, t.description " @@ -1737,8 +1725,8 @@ setup_description(FILE *cmdfd) " classname name, " " description text) WITHOUT OIDS;\n\n"); - PG_CMD_PRINTF1("COPY tmp_pg_shdescription FROM E'%s';\n\n", - escape_quotes(shdesc_file)); + PG_CMD_PRINTF("COPY tmp_pg_shdescription FROM E'%s';\n\n", + escape_quotes(shdesc_file)); PG_CMD_PUTS("INSERT INTO pg_shdescription " " SELECT t.objoid, c.oid, t.description " @@ -1881,8 +1869,8 @@ setup_collation(FILE *cmdfd) quoted_locale = escape_quotes(localebuf); - PG_CMD_PRINTF3("INSERT INTO tmp_pg_collation VALUES (E'%s', E'%s', %d);\n\n", - quoted_locale, quoted_locale, enc); + PG_CMD_PRINTF("INSERT INTO tmp_pg_collation VALUES (E'%s', E'%s', %d);\n\n", + quoted_locale, quoted_locale, enc); /* * Generate aliases such as "en_US" in addition to "en_US.utf8" for @@ -1893,15 +1881,15 @@ setup_collation(FILE *cmdfd) { char *quoted_alias = escape_quotes(alias); - PG_CMD_PRINTF3("INSERT INTO tmp_pg_collation VALUES (E'%s', E'%s', %d);\n\n", - quoted_alias, quoted_locale, enc); + PG_CMD_PRINTF("INSERT INTO tmp_pg_collation VALUES (E'%s', E'%s', %d);\n\n", + quoted_alias, quoted_locale, enc); free(quoted_alias); } free(quoted_locale); } /* Add an SQL-standard name */ - PG_CMD_PRINTF1("INSERT INTO tmp_pg_collation VALUES ('ucs_basic', 'C', %d);\n\n", PG_UTF8); + PG_CMD_PRINTF("INSERT INTO tmp_pg_collation VALUES ('ucs_basic', 'C', %d);\n\n", PG_UTF8); /* * When copying collations to the final location, eliminate aliases that @@ -1914,6 +1902,7 @@ setup_collation(FILE *cmdfd) * Also, eliminate any aliases that conflict with pg_collation's * hard-wired entries for "C" etc. */ + PG_CMD_PUTS("INSERT INTO pg_collation (collname, collnamespace, collowner, collencoding, collcollate, collctype) " " SELECT DISTINCT ON (collname, encoding)" " collname, " @@ -2058,16 +2047,16 @@ setup_schema(FILE *cmdfd) free(lines); - PG_CMD_PRINTF1("UPDATE information_schema.sql_implementation_info " - " SET character_value = '%s' " - " WHERE implementation_info_name = 'DBMS VERSION';\n\n", - infoversion); + PG_CMD_PRINTF("UPDATE information_schema.sql_implementation_info " + " SET character_value = '%s' " + " WHERE implementation_info_name = 'DBMS VERSION';\n\n", + infoversion); - PG_CMD_PRINTF1("COPY information_schema.sql_features " - " (feature_id, feature_name, sub_feature_id, " - " sub_feature_name, is_supported, comments) " - " FROM E'%s';\n\n", - escape_quotes(features_file)); + PG_CMD_PRINTF("COPY information_schema.sql_features " + " (feature_id, feature_name, sub_feature_id, " + " sub_feature_name, is_supported, comments) " + " FROM E'%s';\n\n", + escape_quotes(features_file)); } /*
-- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers