Em sex., 9 de set. de 2022 às 10:45, Ranier Vilela <ranier...@gmail.com> escreveu:
> Based on work in [1]. > According to https://cplusplus.com/reference/cstdio/fprintf/ > The use of fprintf is related to the need to generate a string based on a > format, which should be different from "%s". > Since fprintf has overhead when parsing the "format" parameter, plus all > the trouble of checking the va_arg parameters. > I think this is one of the low fruits available and easy to reap. > By replacing fprintf with its equivalents, fputs and fputc, > we avoid overhead and increase security [2] and [3]. > > The downside is a huge big churm, which unfortunately will occur. > But, IHMO, I think the advantages are worth it. > Note that behavior remains the same, since fputs and fputc do not change > the expected behavior of fprintf. > > A small performance gain is expected, mainly for the client, since there > are several occurrences in some critical places, such as > (usr/src/fe_utils/print.c). > > Patch attached. > This pass check-world. > Rechecked for the hundredth time. One typo. regards, Ranier Vilela
diff --git a/contrib/oid2name/oid2name.c b/contrib/oid2name/oid2name.c index 32d5444831..4672d8b2a4 100644 --- a/contrib/oid2name/oid2name.c +++ b/contrib/oid2name/oid2name.c @@ -422,7 +422,7 @@ sql_exec(PGconn *conn, const char *todo, bool quiet) fprintf(stdout, "%*s", length[j] + 2, PQfname(res, j)); l += length[j] + 2; } - fprintf(stdout, "\n"); + fputc('\n', stdout); pad = (char *) pg_malloc(l + 1); memset(pad, '-', l); pad[l] = '\0'; @@ -435,7 +435,7 @@ sql_exec(PGconn *conn, const char *todo, bool quiet) { for (j = 0; j < nfields; j++) fprintf(stdout, "%*s", length[j] + 2, PQgetvalue(res, i, j)); - fprintf(stdout, "\n"); + fputc('\n', stdout); } /* cleanup */ diff --git a/contrib/pg_trgm/trgm_regexp.c b/contrib/pg_trgm/trgm_regexp.c index 58d32ba946..ed1ab65940 100644 --- a/contrib/pg_trgm/trgm_regexp.c +++ b/contrib/pg_trgm/trgm_regexp.c @@ -2201,7 +2201,7 @@ printSourceNFA(regex_t *regex, TrgmColorInfo *colors, int ncolors) /* dot -Tpng -o /tmp/source.png < /tmp/source.gv */ FILE *fp = fopen("/tmp/source.gv", "w"); - fprintf(fp, "%s", buf.data); + fputs(buf.data, fp); fclose(fp); } @@ -2263,7 +2263,7 @@ printTrgmNFA(TrgmNFA *trgmNFA) /* dot -Tpng -o /tmp/transformed.png < /tmp/transformed.gv */ FILE *fp = fopen("/tmp/transformed.gv", "w"); - fprintf(fp, "%s", buf.data); + fputs(buf.data, fp); fclose(fp); } @@ -2354,7 +2354,7 @@ printTrgmPackedGraph(TrgmPackedGraph *packedGraph, TRGM *trigrams) /* dot -Tpng -o /tmp/packed.png < /tmp/packed.gv */ FILE *fp = fopen("/tmp/packed.gv", "w"); - fprintf(fp, "%s", buf.data); + fputs(buf.data, fp); fclose(fp); } diff --git a/contrib/vacuumlo/vacuumlo.c b/contrib/vacuumlo/vacuumlo.c index 264b879bd3..e51ce8df57 100644 --- a/contrib/vacuumlo/vacuumlo.c +++ b/contrib/vacuumlo/vacuumlo.c @@ -133,7 +133,7 @@ vacuumlo(const char *database, const struct _param *param) { fprintf(stdout, "Connected to database \"%s\"\n", database); if (param->dry_run) - fprintf(stdout, "Test run: no large objects will be removed!\n"); + fputs("Test run: no large objects will be removed!\n", stdout); } res = PQexec(conn, ALWAYS_SECURE_SEARCH_PATH_SQL); diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index 7a710e6490..343555e095 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -8641,7 +8641,7 @@ do_pg_backup_stop(char *labelfile, bool waitforarchive, TimeLineID *stoptli_p) * Transfer remaining lines including label and start timeline to * history file. */ - fprintf(fp, "%s", remaining); + fputs(remaining, fp); fprintf(fp, "STOP TIME: %s\n", strfbuf); fprintf(fp, "STOP TIMELINE: %u\n", stoptli); if (fflush(fp) || ferror(fp) || FreeFile(fp)) diff --git a/src/backend/optimizer/geqo/geqo_misc.c b/src/backend/optimizer/geqo/geqo_misc.c index 890ac363e9..0d024f227f 100644 --- a/src/backend/optimizer/geqo/geqo_misc.c +++ b/src/backend/optimizer/geqo/geqo_misc.c @@ -114,17 +114,17 @@ print_edge_table(FILE *fp, Edge *edge_table, int num_gene) int i, j; - fprintf(fp, "\nEDGE TABLE\n"); + fputs("\nEDGE TABLE\n", fp); for (i = 1; i <= num_gene; i++) { fprintf(fp, "%d :", i); for (j = 0; j < edge_table[i].unused_edges; j++) fprintf(fp, " %d", edge_table[i].edge_list[j]); - fprintf(fp, "\n"); + fputc('\n', fp); } - fprintf(fp, "\n"); + fputc('\n', fp); fflush(fp); } diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c index e75611fdd5..36808438c8 100644 --- a/src/backend/postmaster/postmaster.c +++ b/src/backend/postmaster/postmaster.c @@ -5601,10 +5601,10 @@ CreateOptsFile(int argc, char *argv[], char *fullprogname) return false; } - fprintf(fp, "%s", fullprogname); + fputs(fullprogname, fp); for (i = 1; i < argc; i++) fprintf(fp, " \"%s\"", argv[i]); - fputs("\n", fp); + fputc('\n', fp); if (fclose(fp)) { diff --git a/src/backend/regex/regc_color.c b/src/backend/regex/regc_color.c index 30bda0e5ad..affeb099ee 100644 --- a/src/backend/regex/regc_color.c +++ b/src/backend/regex/regc_color.c @@ -1134,7 +1134,7 @@ dumpcolors(struct colormap *cm, for (c = CHR_MIN; c <= MAX_SIMPLE_CHR; c++) if (GETCOLOR(cm, c) == co) dumpchr(c, f); - fprintf(f, "\n"); + fputc('\n', f); } } /* dump the high colormap if it contains anything interesting */ @@ -1144,12 +1144,12 @@ dumpcolors(struct colormap *cm, c; const color *rowptr; - fprintf(f, "other:\t"); + fputs("other:\t", f); for (c = 0; c < cm->hiarraycols; c++) { fprintf(f, "\t%ld", (long) cm->hicolormap[c]); } - fprintf(f, "\n"); + fputc('\n', f); for (r = 0; r < cm->numcmranges; r++) { dumpchr(cm->cmranges[r].cmin, f); @@ -1161,7 +1161,7 @@ dumpcolors(struct colormap *cm, { fprintf(f, "\t%ld", (long) rowptr[c]); } - fprintf(f, "\n"); + fputc('\n', f); } } } diff --git a/src/backend/regex/regc_nfa.c b/src/backend/regex/regc_nfa.c index 60fb0bec5d..27ea726768 100644 --- a/src/backend/regex/regc_nfa.c +++ b/src/backend/regex/regc_nfa.c @@ -3667,7 +3667,7 @@ dumpnfa(struct nfa *nfa, else fprintf(f, ", maxmatchall %d", nfa->maxmatchall); } - fprintf(f, "\n"); + fputc('\n', f); for (s = nfa->states; s != NULL; s = s->next) { dumpstate(s, f); @@ -3730,7 +3730,7 @@ dumparcs(struct state *s, dumparc(a, s, f); if (pos == 5) { - fprintf(f, "\n"); + fputc('\n', f); pos = 1; } else @@ -3738,7 +3738,7 @@ dumparcs(struct state *s, a = a->outchainRev; } while (a != NULL); if (pos != 1) - fprintf(f, "\n"); + fputc('\n', f); } /* @@ -3751,7 +3751,7 @@ dumparc(struct arc *a, { struct arc *aa; - fprintf(f, "\t"); + fputc('\t', ); switch (a->type) { case PLAIN: @@ -3836,7 +3836,7 @@ dumpcnfa(struct cnfa *cnfa, else fprintf(f, ", maxmatchall %d", cnfa->maxmatchall); } - fprintf(f, "\n"); + fputc('\n', f); for (st = 0; st < cnfa->nstates; st++) dumpcstate(st, cnfa, f); fflush(f); @@ -3868,14 +3868,14 @@ dumpcstate(int st, fprintf(f, "\t:%ld:->%d", (long) (ca->co - cnfa->ncolors), ca->to); if (pos == 5) { - fprintf(f, "\n"); + fputc('\n', f); pos = 1; } else pos++; } if (ca == cnfa->states[st] || pos != 1) - fprintf(f, "\n"); + fputc('\n', f); fflush(f); } diff --git a/src/backend/regex/regcomp.c b/src/backend/regex/regcomp.c index 473738040b..ca7b9252b9 100644 --- a/src/backend/regex/regcomp.c +++ b/src/backend/regex/regcomp.c @@ -2517,7 +2517,7 @@ dump(regex_t *re, fprintf(f, "\nla%d (%s):\n", i, latype); dumpcnfa(&lasub->cnfa, f); } - fprintf(f, "\n"); + fputc('\n', f); dumpst(g->tree, f, 0); } @@ -2530,7 +2530,7 @@ dumpst(struct subre *t, int nfapresent) /* is the original NFA still around? */ { if (t == NULL) - fprintf(f, "null tree\n"); + fputs("null tree\n", f); else stdump(t, f, nfapresent); fflush(f); @@ -2586,10 +2586,10 @@ stdump(struct subre *t, fprintf(f, " S:%s", stid(t->sibling, idbuf, sizeof(idbuf))); if (!NULLCNFA(t->cnfa)) { - fprintf(f, "\n"); + fputc('\n', f); dumpcnfa(&t->cnfa, f); } - fprintf(f, "\n"); + fputc('\n', f); for (t2 = t->child; t2 != NULL; t2 = t2->sibling) stdump(t2, f, nfapresent); } diff --git a/src/backend/storage/lmgr/s_lock.c b/src/backend/storage/lmgr/s_lock.c index 4e473ec27e..357eb11cab 100644 --- a/src/backend/storage/lmgr/s_lock.c +++ b/src/backend/storage/lmgr/s_lock.c @@ -139,7 +139,7 @@ perform_spin_delay(SpinDelayStatus *status) pg_usleep(status->cur_delay); #if defined(S_LOCK_TEST) - fprintf(stdout, "*"); + fputc('*', stdout); fflush(stdout); #endif diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c index 55bf998511..effcddc422 100644 --- a/src/backend/utils/misc/guc.c +++ b/src/backend/utils/misc/guc.c @@ -11010,7 +11010,7 @@ write_one_nondefault_variable(FILE *fp, struct config_generic *gconf) if (gconf->source == PGC_S_DEFAULT) return; - fprintf(fp, "%s", gconf->name); + fputs(gconf->name, fp); fputc(0, fp); switch (gconf->vartype) @@ -11020,9 +11020,9 @@ write_one_nondefault_variable(FILE *fp, struct config_generic *gconf) struct config_bool *conf = (struct config_bool *) gconf; if (*conf->variable) - fprintf(fp, "true"); + fputs("true", fp); else - fprintf(fp, "false"); + fputs("false", fp); } break; @@ -11046,7 +11046,7 @@ write_one_nondefault_variable(FILE *fp, struct config_generic *gconf) { struct config_string *conf = (struct config_string *) gconf; - fprintf(fp, "%s", *conf->variable); + fputs(*conf->variable, fp); } break; @@ -11054,8 +11054,7 @@ write_one_nondefault_variable(FILE *fp, struct config_generic *gconf) { struct config_enum *conf = (struct config_enum *) gconf; - fprintf(fp, "%s", - config_enum_lookup_by_value(conf, *conf->variable)); + fputs(config_enum_lookup_by_value(conf, *conf->variable), fp); } break; } @@ -11063,7 +11062,7 @@ write_one_nondefault_variable(FILE *fp, struct config_generic *gconf) fputc(0, fp); if (gconf->sourcefile) - fprintf(fp, "%s", gconf->sourcefile); + fputs(gconf->sourcefile, fp); fputc(0, fp); fwrite(&gconf->sourceline, 1, sizeof(gconf->sourceline), fp); diff --git a/src/backend/utils/mmgr/mcxt.c b/src/backend/utils/mmgr/mcxt.c index 115a64cfe4..649f6a589f 100644 --- a/src/backend/utils/mmgr/mcxt.c +++ b/src/backend/utils/mmgr/mcxt.c @@ -680,7 +680,7 @@ MemoryContextStatsInternal(MemoryContext context, int level, int i; for (i = 0; i <= level; i++) - fprintf(stderr, " "); + fputs(" ", stderr); fprintf(stderr, "%d more child contexts containing %zu total in %zu blocks; %zu free (%zu chunks); %zu used\n", ichild - max_children, @@ -782,7 +782,7 @@ MemoryContextStatsPrint(MemoryContext context, void *passthru, if (print_to_stderr) { for (i = 0; i < level; i++) - fprintf(stderr, " "); + fputs(" ", stderr); fprintf(stderr, "%s: %s%s\n", name, stats_string, truncated_ident); } else diff --git a/src/bin/pg_amcheck/pg_amcheck.c b/src/bin/pg_amcheck/pg_amcheck.c index fea35e4b14..330d296fa4 100644 --- a/src/bin/pg_amcheck/pg_amcheck.c +++ b/src/bin/pg_amcheck/pg_amcheck.c @@ -726,7 +726,7 @@ main(int argc, char *argv[]) if (opts.verbose) { if (opts.show_progress && progress_since_last_stderr) - fprintf(stderr, "\n"); + fputc('\n', stderr); pg_log_info("checking heap table \"%s.%s.%s\"", rel->datinfo->datname, rel->nspname, rel->relname); progress_since_last_stderr = false; @@ -741,7 +741,7 @@ main(int argc, char *argv[]) if (opts.verbose) { if (opts.show_progress && progress_since_last_stderr) - fprintf(stderr, "\n"); + fputc('\n', stderr); pg_log_info("checking btree index \"%s.%s.%s\"", rel->datinfo->datname, rel->nspname, rel->relname); @@ -1095,7 +1095,7 @@ verify_btree_slot_handler(PGresult *res, PGconn *conn, void *context) * event loop, so it doesn't matter. */ if (opts.show_progress && progress_since_last_stderr) - fprintf(stderr, "\n"); + fputc('\n', stderr); pg_log_warning("btree index \"%s.%s.%s\": btree checking function returned unexpected number of rows: %d", rel->datinfo->datname, rel->nspname, rel->relname, ntups); if (opts.verbose) diff --git a/src/bin/pg_basebackup/pg_basebackup.c b/src/bin/pg_basebackup/pg_basebackup.c index 9ce30d43a4..888dfa7fc0 100644 --- a/src/bin/pg_basebackup/pg_basebackup.c +++ b/src/bin/pg_basebackup/pg_basebackup.c @@ -1904,11 +1904,11 @@ BaseBackup(char *compression_algorithm, char *compression_detail, if (showprogress && !verbose) { - fprintf(stderr, "waiting for checkpoint"); + fputs("waiting for checkpoint", stderr); if (isatty(fileno(stderr))) - fprintf(stderr, "\r"); + fputc('\r', stderr); else - fprintf(stderr, "\n"); + fputc('\n', stderr); } if (use_new_option_syntax && buf.len > 0) diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c index 69ae027bd3..9481e68c5e 100644 --- a/src/bin/pg_dump/pg_dumpall.c +++ b/src/bin/pg_dump/pg_dumpall.c @@ -535,7 +535,7 @@ main(int argc, char *argv[]) if (quote_all_identifiers) executeCommand(conn, "SET quote_all_identifiers = true"); - fprintf(OPF, "--\n-- PostgreSQL database cluster dump\n--\n\n"); + fputs("--\n-- PostgreSQL database cluster dump\n--\n\n", OPF); if (verbose) dumpTimestamp("Started on"); @@ -547,15 +547,15 @@ main(int argc, char *argv[]) */ /* Restore will need to write to the target cluster */ - fprintf(OPF, "SET default_transaction_read_only = off;\n\n"); + fputs("SET default_transaction_read_only = off;\n\n", OPF); /* Replicate encoding and std_strings in output */ fprintf(OPF, "SET client_encoding = '%s';\n", pg_encoding_to_char(encoding)); fprintf(OPF, "SET standard_conforming_strings = %s;\n", std_strings); if (strcmp(std_strings, "off") == 0) - fprintf(OPF, "SET escape_string_warning = off;\n"); - fprintf(OPF, "\n"); + fputs("SET escape_string_warning = off;\n", OPF); + fputc('\n', OPF); if (!data_only) { @@ -606,7 +606,7 @@ main(int argc, char *argv[]) if (verbose) dumpTimestamp("Completed on"); - fprintf(OPF, "--\n-- PostgreSQL database cluster dump complete\n--\n\n"); + fputs("--\n-- PostgreSQL database cluster dump complete\n--\n\n", OPF); if (filename) { @@ -716,7 +716,7 @@ dropRoles(PGconn *conn) i_rolname = PQfnumber(res, "rolname"); if (PQntuples(res) > 0) - fprintf(OPF, "--\n-- Drop roles\n--\n\n"); + fputs("--\n-- Drop roles\n--\n\n", OPF); for (i = 0; i < PQntuples(res); i++) { @@ -732,7 +732,7 @@ dropRoles(PGconn *conn) PQclear(res); destroyPQExpBuffer(buf); - fprintf(OPF, "\n\n"); + fputs("\n\n", OPF); } /* @@ -811,7 +811,7 @@ dumpRoles(PGconn *conn) i_is_current_user = PQfnumber(res, "is_current_user"); if (PQntuples(res) > 0) - fprintf(OPF, "--\n-- Roles\n--\n\n"); + fputs("--\n-- Roles\n--\n\n", OPF); for (i = 0; i < PQntuples(res); i++) { @@ -915,7 +915,7 @@ dumpRoles(PGconn *conn) "ROLE", rolename, buf); - fprintf(OPF, "%s", buf->data); + fputs(buf->data, OPF); } /* @@ -924,14 +924,14 @@ dumpRoles(PGconn *conn) * names of other roles. */ if (PQntuples(res) > 0) - fprintf(OPF, "\n--\n-- User Configurations\n--\n"); + fputs("\n--\n-- User Configurations\n--\n", OPF); for (i = 0; i < PQntuples(res); i++) dumpUserConfig(conn, PQgetvalue(res, i, i_rolname)); PQclear(res); - fprintf(OPF, "\n\n"); + fputs("\n\n", OPF); destroyPQExpBuffer(buf); } @@ -989,7 +989,7 @@ dumpRoleMembership(PGconn *conn) i_inherit_option = PQfnumber(res, "inherit_option"); if (PQntuples(res) > 0) - fprintf(OPF, "--\n-- Role memberships\n--\n\n"); + fputs("--\n-- Role memberships\n--\n\n", OPF); /* * We can't dump these GRANT commands in arbitary order, because a role @@ -1111,7 +1111,7 @@ dumpRoleMembership(PGconn *conn) fprintf(OPF, " WITH %s", optbuf->data); if (dump_grantors) fprintf(OPF, " GRANTED BY %s", fmtId(grantor)); - fprintf(OPF, ";\n"); + fputs(";\n", OPF); } } @@ -1123,7 +1123,7 @@ dumpRoleMembership(PGconn *conn) PQclear(res); destroyPQExpBuffer(buf); - fprintf(OPF, "\n\n"); + fputs("\n\n", OPF); } @@ -1151,7 +1151,7 @@ dumpRoleGUCPrivs(PGconn *conn) "ORDER BY 1"); if (PQntuples(res) > 0) - fprintf(OPF, "--\n-- Role privileges on configuration parameters\n--\n\n"); + fputs("--\n-- Role privileges on configuration parameters\n--\n\n", OPF); for (i = 0; i < PQntuples(res); i++) { @@ -1175,14 +1175,14 @@ dumpRoleGUCPrivs(PGconn *conn) exit_nicely(1); } - fprintf(OPF, "%s", buf->data); + fputs(buf->data, OPF); free(fparname); destroyPQExpBuffer(buf); } PQclear(res); - fprintf(OPF, "\n\n"); + fputs("\n\n", OPF); } @@ -1205,7 +1205,7 @@ dropTablespaces(PGconn *conn) "ORDER BY 1"); if (PQntuples(res) > 0) - fprintf(OPF, "--\n-- Drop tablespaces\n--\n\n"); + fputs("--\n-- Drop tablespaces\n--\n\n", OPF); for (i = 0; i < PQntuples(res); i++) { @@ -1218,7 +1218,7 @@ dropTablespaces(PGconn *conn) PQclear(res); - fprintf(OPF, "\n\n"); + fputs("\n\n", OPF); } /* @@ -1245,7 +1245,7 @@ dumpTablespaces(PGconn *conn) "ORDER BY 1"); if (PQntuples(res) > 0) - fprintf(OPF, "--\n-- Tablespaces\n--\n\n"); + fputs("--\n-- Tablespaces\n--\n\n", OPF); for (i = 0; i < PQntuples(res); i++) { @@ -1305,14 +1305,14 @@ dumpTablespaces(PGconn *conn) "TABLESPACE", spcname, buf); - fprintf(OPF, "%s", buf->data); + fputs(buf->data, OPF); free(fspcname); destroyPQExpBuffer(buf); } PQclear(res); - fprintf(OPF, "\n\n"); + fputs("\n\n", OPF); } @@ -1336,7 +1336,7 @@ dropDBs(PGconn *conn) "ORDER BY datname"); if (PQntuples(res) > 0) - fprintf(OPF, "--\n-- Drop databases (except postgres and template1)\n--\n\n"); + fputs("--\n-- Drop databases (except postgres and template1)\n--\n\n", OPF); for (i = 0; i < PQntuples(res); i++) { @@ -1359,7 +1359,7 @@ dropDBs(PGconn *conn) PQclear(res); - fprintf(OPF, "\n\n"); + fputs("\n\n", OPF); } @@ -1390,7 +1390,7 @@ dumpUserConfig(PGconn *conn, const char *username) makeAlterConfigCommand(conn, PQgetvalue(res, i, 0), "ROLE", username, NULL, NULL, buf); - fprintf(OPF, "%s", buf->data); + fputs(buf->data, OPF); } PQclear(res); @@ -1479,7 +1479,7 @@ dumpDatabases(PGconn *conn) "ORDER BY (datname <> 'template1'), datname"); if (PQntuples(res) > 0) - fprintf(OPF, "--\n-- Databases\n--\n\n"); + fputs("--\n-- Databases\n--\n\n", OPF); for (i = 0; i < PQntuples(res); i++) { diff --git a/src/bin/pg_upgrade/check.c b/src/bin/pg_upgrade/check.c index f4969bcdad..b3c90cf121 100644 --- a/src/bin/pg_upgrade/check.c +++ b/src/bin/pg_upgrade/check.c @@ -582,7 +582,7 @@ create_script_for_old_cluster_deletion(char **deletion_script_file_name) #ifndef WIN32 /* add shebang header */ - fprintf(script, "#!/bin/sh\n\n"); + fputs("#!/bin/sh\n\n", script); #endif /* delete old cluster's default tablespace */ @@ -601,7 +601,7 @@ create_script_for_old_cluster_deletion(char **deletion_script_file_name) /* delete per-database directories */ int dbnum; - fprintf(script, "\n"); + fputc('\n', script); for (dbnum = 0; dbnum < old_cluster.dbarr.ndbs; dbnum++) fprintf(script, RMDIR_CMD " %c%s%c%u%c\n", PATH_QUOTE, diff --git a/src/bin/pg_upgrade/exec.c b/src/bin/pg_upgrade/exec.c index 60f4b5443e..470fc4855b 100644 --- a/src/bin/pg_upgrade/exec.c +++ b/src/bin/pg_upgrade/exec.c @@ -159,13 +159,13 @@ exec_prog(const char *log_filename, const char *opt_log_file, #ifdef WIN32 /* Are we printing "command:" before its output? */ if (mainThreadId == GetCurrentThreadId()) - fprintf(log, "\n\n"); + fputs("\n\n", log); #endif fprintf(log, "command: %s\n", cmd); #ifdef WIN32 /* Are we printing "command:" after its output? */ if (mainThreadId != GetCurrentThreadId()) - fprintf(log, "\n\n"); + fputs("\n\n", log); #endif /* @@ -213,7 +213,7 @@ exec_prog(const char *log_filename, const char *opt_log_file, */ if ((log = fopen(log_file, "a")) == NULL) pg_fatal("could not write to log file \"%s\": %m", log_file); - fprintf(log, "\n\n"); + fputs("\n\n", log); fclose(log); #endif diff --git a/src/bin/pg_upgrade/util.c b/src/bin/pg_upgrade/util.c index 593a843917..486918021b 100644 --- a/src/bin/pg_upgrade/util.c +++ b/src/bin/pg_upgrade/util.c @@ -181,7 +181,7 @@ pg_log_v(eLogType type, const char *fmt, va_list ap) /* status messages get two leading spaces, see below */ fprintf(log_opts.internal, " %s\n", message); else if (type == PG_REPORT_NONL) - fprintf(log_opts.internal, "%s", message); + fputs(message, log_opts.internal); else fprintf(log_opts.internal, "%s\n", message); fflush(log_opts.internal); diff --git a/src/bin/pgbench/pgbench.c b/src/bin/pgbench/pgbench.c index 098fb43b3c..338bc31904 100644 --- a/src/bin/pgbench/pgbench.c +++ b/src/bin/pgbench/pgbench.c @@ -2532,7 +2532,7 @@ evalStandardFunc(CState *st, st->use_file, st->command + 1); if (varg->type == PGBT_NULL) - fprintf(stderr, "null\n"); + fputs("null\n", stderr); else if (varg->type == PGBT_BOOLEAN) fprintf(stderr, "boolean %s\n", varg->u.bval ? "true" : "false"); else if (varg->type == PGBT_INT) @@ -4633,7 +4633,7 @@ disconnect_all(CState *state, int length) static void initDropTables(PGconn *con) { - fprintf(stderr, "dropping old tables...\n"); + fputs("dropping old tables...\n", stderr); /* * We drop all the tables in one command, so that whether there are @@ -4771,7 +4771,7 @@ initCreateTables(PGconn *con) int i; PQExpBufferData query; - fprintf(stderr, "creating tables...\n"); + fputs("creating tables...\n", stderr); initPQExpBuffer(&query); @@ -4845,7 +4845,7 @@ initGenerateDataClientSide(PGconn *con) /* Stay on the same line if reporting to a terminal */ char eol = isatty(fileno(stderr)) ? '\r' : '\n'; - fprintf(stderr, "generating data (client-side)...\n"); + fputs("generating data (client-side)...\n", stderr); /* * we do all of this in one transaction to enable the backend's @@ -4970,7 +4970,7 @@ initGenerateDataServerSide(PGconn *con) { PQExpBufferData sql; - fprintf(stderr, "generating data (server-side)...\n"); + fputs("generating data (server-side)...\n", stderr); /* * we do all of this in one transaction to enable the backend's @@ -5013,7 +5013,7 @@ initGenerateDataServerSide(PGconn *con) static void initVacuum(PGconn *con) { - fprintf(stderr, "vacuuming...\n"); + fputs("vacuuming...\n", stderr); executeStatement(con, "vacuum analyze pgbench_branches"); executeStatement(con, "vacuum analyze pgbench_tellers"); executeStatement(con, "vacuum analyze pgbench_accounts"); @@ -5034,7 +5034,7 @@ initCreatePKeys(PGconn *con) int i; PQExpBufferData query; - fprintf(stderr, "creating primary keys...\n"); + fputs("creating primary keys...\n", stderr); initPQExpBuffer(&query); for (i = 0; i < lengthof(DDLINDEXes); i++) @@ -5073,7 +5073,7 @@ initCreateFKeys(PGconn *con) }; int i; - fprintf(stderr, "creating foreign keys...\n"); + fputs("creating foreign keys...\n", stderr); for (i = 0; i < lengthof(DDLKEYs); i++) { executeStatement(con, DDLKEYs[i]); @@ -5992,10 +5992,10 @@ listAvailableScripts(void) { int i; - fprintf(stderr, "Available builtin scripts:\n"); + fputs("Available builtin scripts:\n", stderr); for (i = 0; i < lengthof(builtin_script); i++) fprintf(stderr, " %13s: %s\n", builtin_script[i].name, builtin_script[i].desc); - fprintf(stderr, "\n"); + fputc('\n', stderr); } /* return builtin script "name" if unambiguous, fails if not found */ @@ -6181,7 +6181,7 @@ printProgressReport(TState *threads, int64 test_start, pg_time_usec_t now, fprintf(stderr, ", " INT64_FORMAT " retried, " INT64_FORMAT " retries", retried, cur.retries - last->retries); - fprintf(stderr, "\n"); + fputc('\n', stderr); *last = cur; *last_report = now; @@ -7138,17 +7138,17 @@ main(int argc, char **argv) if (!is_no_vacuum) { - fprintf(stderr, "starting vacuum..."); + fputs("starting vacuum...", stderr); tryExecuteStatement(con, "vacuum pgbench_branches"); tryExecuteStatement(con, "vacuum pgbench_tellers"); tryExecuteStatement(con, "truncate pgbench_history"); - fprintf(stderr, "end.\n"); + fputs("end.\n", stderr); if (do_vacuum_accounts) { - fprintf(stderr, "starting vacuum pgbench_accounts..."); + fputs("starting vacuum pgbench_accounts...", stderr); tryExecuteStatement(con, "vacuum analyze pgbench_accounts"); - fprintf(stderr, "end.\n"); + fputs("end.\n", stderr); } } PQfinish(con); diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index a141146e70..75fe181c15 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -1243,7 +1243,7 @@ exec_command_echo(PsqlScanState scan_state, bool active_branch, const char *cmd) free(value); } if (!no_newline) - fputs("\n", fout); + fputc('\n', fout); } else ignore_slash_options(scan_state); @@ -5212,7 +5212,7 @@ do_watch(PQExpBuffer query_buf, double sleep) * using a pager, because pagers are expected to restore the screen to * a sane state on exit. */ - fprintf(stdout, "\n"); + fputc('\n', stdout); fflush(stdout); } diff --git a/src/bin/psql/common.c b/src/bin/psql/common.c index e611e3266d..d7222c8489 100644 --- a/src/bin/psql/common.c +++ b/src/bin/psql/common.c @@ -309,12 +309,12 @@ CheckConnection(void) exit(EXIT_BADCONN); } - fprintf(stderr, _("The connection to the server was lost. Attempting reset: ")); + fputs(_("The connection to the server was lost. Attempting reset: "), stderr); PQreset(pset.db); OK = ConnectionUp(); if (!OK) { - fprintf(stderr, _("Failed.\n")); + fputs(_("Failed.\n"), stderr); /* * Transition to having no connection; but stash away the failed @@ -331,7 +331,7 @@ CheckConnection(void) } else { - fprintf(stderr, _("Succeeded.\n")); + fputs(_("Succeeded.\n"), stderr); /* * Re-sync, just in case anything changed. Keep this in sync with @@ -1404,8 +1404,7 @@ DescribeQuery(const char *query, double *elapsed_msec) termPQExpBuffer(&buf); } else - fprintf(pset.queryFout, - _("The command has no result, or the result has no columns.\n")); + fputs(_("The command has no result, or the result has no columns.\n"), pset.queryFout); } SetResultVariables(result, OK); diff --git a/src/bin/psql/help.c b/src/bin/psql/help.c index f8ce1a0706..d00e6197d9 100644 --- a/src/bin/psql/help.c +++ b/src/bin/psql/help.c @@ -617,14 +617,13 @@ helpSQL(const char *topic, unsigned short int pager) for (i = 0; i < nrows; i++) { - fprintf(output, " "); + fputs(" ", output); for (j = 0; j < ncolumns - 1; j++) fprintf(output, "%-*s", QL_MAX_CMD_LEN + 1, VALUE_OR_NULL(QL_HELP[i + j * nrows].cmd)); if (i + j * nrows < QL_HELP_COUNT) - fprintf(output, "%s", - VALUE_OR_NULL(QL_HELP[i + j * nrows].cmd)); + fputs(VALUE_OR_NULL(QL_HELP[i + j * nrows].cmd), output); fputc('\n', output); } diff --git a/src/bin/psql/large_obj.c b/src/bin/psql/large_obj.c index 64338d538e..9ba573dc08 100644 --- a/src/bin/psql/large_obj.c +++ b/src/bin/psql/large_obj.c @@ -32,7 +32,7 @@ print_lo_result(const char *fmt,...) if (pset.popt.topt.format == PRINT_HTML) fputs("</p>\n", pset.queryFout); else - fputs("\n", pset.queryFout); + fputc('\n', pset.queryFout); } if (pset.logfile) @@ -40,7 +40,7 @@ print_lo_result(const char *fmt,...) va_start(ap, fmt); vfprintf(pset.logfile, fmt, ap); va_end(ap); - fputs("\n", pset.logfile); + fputc('\n', pset.logfile); } } diff --git a/src/bin/scripts/createuser.c b/src/bin/scripts/createuser.c index 991930a1ae..d635e71c54 100644 --- a/src/bin/scripts/createuser.c +++ b/src/bin/scripts/createuser.c @@ -233,7 +233,7 @@ main(int argc, char *argv[]) pw2 = simple_prompt("Enter it again: ", false); if (strcmp(newpassword, pw2) != 0) { - fprintf(stderr, _("Passwords didn't match.\n")); + fputs(_("Passwords didn't match.\n"), stderr); exit(1); } free(pw2); diff --git a/src/common/fe_memutils.c b/src/common/fe_memutils.c index b1e6c65576..3e169b823e 100644 --- a/src/common/fe_memutils.c +++ b/src/common/fe_memutils.c @@ -32,7 +32,7 @@ pg_malloc_internal(size_t size, int flags) { if ((flags & MCXT_ALLOC_NO_OOM) == 0) { - fprintf(stderr, _("out of memory\n")); + fputs(_("out of memory\n"), stderr); exit(EXIT_FAILURE); } return NULL; @@ -72,7 +72,7 @@ pg_realloc(void *ptr, size_t size) tmp = realloc(ptr, size); if (!tmp) { - fprintf(stderr, _("out of memory\n")); + fputs(_("out of memory\n"), stderr); exit(EXIT_FAILURE); } return tmp; @@ -88,14 +88,13 @@ pg_strdup(const char *in) if (!in) { - fprintf(stderr, - _("cannot duplicate null pointer (internal error)\n")); + fputs(_("cannot duplicate null pointer (internal error)\n"), stderr); exit(EXIT_FAILURE); } tmp = strdup(in); if (!tmp) { - fprintf(stderr, _("out of memory\n")); + fputs(_("out of memory\n"), stderr); exit(EXIT_FAILURE); } return tmp; @@ -149,8 +148,7 @@ pnstrdup(const char *in, Size size) if (!in) { - fprintf(stderr, - _("cannot duplicate null pointer (internal error)\n")); + fputs(_("cannot duplicate null pointer (internal error)\n"), stderr); exit(EXIT_FAILURE); } @@ -158,7 +156,7 @@ pnstrdup(const char *in, Size size) tmp = malloc(len + 1); if (tmp == NULL) { - fprintf(stderr, _("out of memory\n")); + fputs(_("out of memory\n"), stderr); exit(EXIT_FAILURE); } diff --git a/src/common/logging.c b/src/common/logging.c index 64604c5209..896c89f487 100644 --- a/src/common/logging.c +++ b/src/common/logging.c @@ -258,9 +258,9 @@ pg_log_generic_v(enum pg_log_level level, enum pg_log_part part, if (lineno > 0) fprintf(stderr, UINT64_FORMAT ":", lineno); } - fprintf(stderr, " "); + fputc(' ', stderr); if (sgr_locus) - fprintf(stderr, ANSI_ESCAPE_RESET); + fputs(ANSI_ESCAPE_RESET, stderr); } if (!(log_flags & PG_LOG_FLAG_TERSE)) @@ -275,14 +275,14 @@ pg_log_generic_v(enum pg_log_level level, enum pg_log_part part, fprintf(stderr, ANSI_ESCAPE_FMT, sgr_error); fprintf(stderr, _("error: ")); if (sgr_error) - fprintf(stderr, ANSI_ESCAPE_RESET); + fputs(ANSI_ESCAPE_RESET, stderr); break; case PG_LOG_WARNING: if (sgr_warning) fprintf(stderr, ANSI_ESCAPE_FMT, sgr_warning); - fprintf(stderr, _("warning: ")); + fputs(_("warning: "), stderr); if (sgr_warning) - fprintf(stderr, ANSI_ESCAPE_RESET); + fputs(ANSI_ESCAPE_RESET, stderr); break; default: break; @@ -291,16 +291,16 @@ pg_log_generic_v(enum pg_log_level level, enum pg_log_part part, case PG_LOG_DETAIL: if (sgr_note) fprintf(stderr, ANSI_ESCAPE_FMT, sgr_note); - fprintf(stderr, _("detail: ")); + fputs(_("detail: "), stderr); if (sgr_note) - fprintf(stderr, ANSI_ESCAPE_RESET); + fputs(ANSI_ESCAPE_RESET, stderr); break; case PG_LOG_HINT: if (sgr_note) fprintf(stderr, ANSI_ESCAPE_FMT, sgr_note); - fprintf(stderr, _("hint: ")); + fputs(_("hint: "), stderr); if (sgr_note) - fprintf(stderr, ANSI_ESCAPE_RESET); + fputs(ANSI_ESCAPE_RESET, stderr); break; } } diff --git a/src/common/psprintf.c b/src/common/psprintf.c index a5a5cb121c..79eb41c1e5 100644 --- a/src/common/psprintf.c +++ b/src/common/psprintf.c @@ -142,7 +142,7 @@ pvsnprintf(char *buf, size_t len, const char *fmt, va_list args) (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED), errmsg("out of memory"))); #else - fprintf(stderr, _("out of memory\n")); + fputs(_("out of memory\n"), stderr); exit(EXIT_FAILURE); #endif } diff --git a/src/common/sprompt.c b/src/common/sprompt.c index 8b836846e3..ebab6c44fd 100644 --- a/src/common/sprompt.c +++ b/src/common/sprompt.c @@ -156,18 +156,18 @@ simple_prompt_extended(const char *prompt, bool echo, /* restore previous echo behavior, then echo \n */ #if defined(HAVE_TERMIOS_H) tcsetattr(fileno(termin), TCSAFLUSH, &t_orig); - fputs("\n", termout); + fputc('\n', termout); fflush(termout); #elif defined(WIN32) SetConsoleMode(t, t_orig); - fputs("\n", termout); + fputc('\n', termout); fflush(termout); #endif } else if (prompt_ctx && prompt_ctx->canceled) { /* also echo \n if prompt was canceled */ - fputs("\n", termout); + fputc('\n', termout); fflush(termout); } diff --git a/src/fe_utils/print.c b/src/fe_utils/print.c index 55288f8876..87d23887b0 100644 --- a/src/fe_utils/print.c +++ b/src/fe_utils/print.c @@ -1640,7 +1640,7 @@ print_aligned_vertical(const printTableContent *cont, { /* Left border */ if (opt_border == 2) - fprintf(fout, "%s", dformat->leftvrule); + fputs(dformat->leftvrule, fout); /* Header (never wrapped so just need to deal with newlines) */ if (!hcomplete) @@ -1685,7 +1685,7 @@ print_aligned_vertical(const printTableContent *cont, /* This was the last line of the header */ if ((opt_border > 0) || (hmultiline && (format != &pg_asciiformat_old))) - fputs(" ", fout); + fputc(' ', fout); hcomplete = 1; } } @@ -1775,7 +1775,7 @@ print_aligned_vertical(const printTableContent *cont, { if (swidth > 0) fprintf(fout, "%*s", swidth, " "); - fputs(" ", fout); + fputc(' ', fout); } dcomplete = 1; } @@ -1784,7 +1784,7 @@ print_aligned_vertical(const printTableContent *cont, if (opt_border == 2) fputs(dformat->rightvrule, fout); - fputs("\n", fout); + fputc('\n', fout); } else { @@ -1793,7 +1793,7 @@ print_aligned_vertical(const printTableContent *cont, * data due to newlines in the header) */ if (opt_border < 2) - fputs("\n", fout); + fputc('\n', fout); else fprintf(fout, "%*s %s\n", dwidth, "", dformat->rightvrule); } @@ -1977,7 +1977,7 @@ html_escaped_print(const char *in, FILE *fout) if (leading_space) fputs(" ", fout); else - fputs(" ", fout); + fputc(' ', fout); break; default: fputc(*p, fout); @@ -2195,14 +2195,14 @@ print_asciidoc_text(const printTableContent *cont, FILE *fout) if (cont->opt->start_table) { /* print table in new paragraph - enforce preliminary new line */ - fputs("\n", fout); + fputc('\n', fout); /* print title */ if (!opt_tuples_only && cont->title) { - fputs(".", fout); + fputc('.', fout); fputs(cont->title, fout); - fputs("\n", fout); + fputc('\n', fout); } /* print table [] header definition */ @@ -2210,10 +2210,10 @@ print_asciidoc_text(const printTableContent *cont, FILE *fout) for (i = 0; i < cont->ncolumns; i++) { if (i != 0) - fputs(",", fout); - fprintf(fout, "%s", cont->aligns[(i) % cont->ncolumns] == 'r' ? ">l" : "<l"); + fputc(',', fout); + fputs((cont->aligns[(i) % cont->ncolumns]) == 'r' ? ">l" : "<l", fout); } - fputs("\"", fout); + fputc('"', fout); switch (opt_border) { case 0: @@ -2235,11 +2235,11 @@ print_asciidoc_text(const printTableContent *cont, FILE *fout) for (ptr = cont->headers; *ptr; ptr++) { if (ptr != cont->headers) - fputs(" ", fout); + fputc(' ', fout); fputs("^l|", fout); asciidoc_escaped_print(*ptr, fout); } - fputs("\n", fout); + fputc('\n', fout); } } @@ -2253,20 +2253,20 @@ print_asciidoc_text(const printTableContent *cont, FILE *fout) } if (i % cont->ncolumns != 0) - fputs(" ", fout); - fputs("|", fout); + fputc(' ', fout); + fputc('|', fout); /* protect against needless spaces */ if ((*ptr)[strspn(*ptr, " \t")] == '\0') { if ((i + 1) % cont->ncolumns != 0) - fputs(" ", fout); + fputc(' ', fout); } else asciidoc_escaped_print(*ptr, fout); if ((i + 1) % cont->ncolumns == 0) - fputs("\n", fout); + fputc('\n', fout); } fputs("|====\n", fout); @@ -2284,7 +2284,7 @@ print_asciidoc_text(const printTableContent *cont, FILE *fout) for (f = footers; f; f = f->next) { fputs(f->data, fout); - fputs("\n", fout); + fputc('\n', fout); } fputs("....\n", fout); } @@ -2306,14 +2306,14 @@ print_asciidoc_vertical(const printTableContent *cont, FILE *fout) if (cont->opt->start_table) { /* print table in new paragraph - enforce preliminary new line */ - fputs("\n", fout); + fputc('\n', fout); /* print title */ if (!opt_tuples_only && cont->title) { - fputs(".", fout); + fputc('.', fout); fputs(cont->title, fout); - fputs("\n", fout); + fputc('\n', fout); } /* print table [] header definition */ @@ -2355,10 +2355,10 @@ print_asciidoc_vertical(const printTableContent *cont, FILE *fout) fprintf(fout, " %s|", cont->aligns[i % cont->ncolumns] == 'r' ? ">l" : "<l"); /* is string only whitespace? */ if ((*ptr)[strspn(*ptr, " \t")] == '\0') - fputs(" ", fout); + fputc(' ', fout); else asciidoc_escaped_print(*ptr, fout); - fputs("\n", fout); + fputc('\n', fout); } fputs("|====\n", fout); @@ -2374,7 +2374,7 @@ print_asciidoc_vertical(const printTableContent *cont, FILE *fout) for (f = cont->footers; f; f = f->next) { fputs(f->data, fout); - fputs("\n", fout); + fputc('\n', fout); } fputs("....\n", fout); } @@ -3150,7 +3150,7 @@ ClosePager(FILE *pagerpipe) * anywhere ... */ if (cancel_pressed) - fprintf(pagerpipe, _("Interrupted\n")); + fputs(_("Interrupted\n"), pagerpipe); pclose(pagerpipe); restore_sigpipe_trap(); diff --git a/src/interfaces/libpq/fe-connect.c b/src/interfaces/libpq/fe-connect.c index 917b19e0e9..510e34f096 100644 --- a/src/interfaces/libpq/fe-connect.c +++ b/src/interfaces/libpq/fe-connect.c @@ -7025,7 +7025,7 @@ defaultNoticeProcessor(void *arg, const char *message) { (void) arg; /* not used */ /* Note: we expect the supplied string to end with a newline already. */ - fprintf(stderr, "%s", message); + fputs(message, stderr); } /* diff --git a/src/interfaces/libpq/fe-print.c b/src/interfaces/libpq/fe-print.c index 21d346a08b..eac118f30b 100644 --- a/src/interfaces/libpq/fe-print.c +++ b/src/interfaces/libpq/fe-print.c @@ -113,7 +113,7 @@ PQprint(FILE *fout, const PGresult *res, const PQprintOpt *po) fieldMax = (int *) calloc(nFields, sizeof(int)); if (!fieldNames || !fieldNotNum || !fieldMax) { - fprintf(stderr, libpq_gettext("out of memory\n")); + fputs(libpq_gettext("out of memory\n"), stderr); goto exit; } for (numFieldName = 0; @@ -205,7 +205,7 @@ PQprint(FILE *fout, const PGresult *res, const PQprintOpt *po) nFields * sizeof(char *)); if (!fields) { - fprintf(stderr, libpq_gettext("out of memory\n")); + fputs(libpq_gettext("out of memory\n"), stderr); goto exit; } } @@ -404,7 +404,7 @@ do_field(const PQprintOpt *po, const PGresult *res, fieldMax[j] = plen; if (!(fields[i * nFields + j] = (char *) malloc(plen + 1))) { - fprintf(stderr, libpq_gettext("out of memory\n")); + fputs(libpq_gettext("out of memory\n"), stderr); return false; } strcpy(fields[i * nFields + j], pval); @@ -475,7 +475,7 @@ do_header(FILE *fout, const PQprintOpt *po, const int nFields, int *fieldMax, border = malloc(tot + 1); if (!border) { - fprintf(stderr, libpq_gettext("out of memory\n")); + fputs(libpq_gettext("out of memory\n"), stderr); return NULL; } p = border; @@ -615,7 +615,7 @@ PQdisplayTuples(const PGresult *res, fLength = (int *) malloc(nFields * sizeof(int)); if (!fLength) { - fprintf(stderr, libpq_gettext("out of memory\n")); + fputs(libpq_gettext("out of memory\n"), stderr); return; } @@ -642,7 +642,7 @@ PQdisplayTuples(const PGresult *res, fill(strlen(PQfname(res, i)), fLength[i], ' ', fp); fputs(fieldSep, fp); } - fprintf(fp, "\n"); + fputc('\n', fp); /* Underline the attribute names */ for (i = 0; i < nFields; i++) @@ -651,7 +651,7 @@ PQdisplayTuples(const PGresult *res, fill(0, fLength[i], '-', fp); fputs(fieldSep, fp); } - fprintf(fp, "\n"); + fputc('\n', fp); } /* next, print out the instances */ @@ -659,12 +659,12 @@ PQdisplayTuples(const PGresult *res, { for (j = 0; j < nFields; j++) { - fprintf(fp, "%s", PQgetvalue(res, i, j)); + fputs(PQgetvalue(res, i, j), fp); if (fillAlign) fill(strlen(PQgetvalue(res, i, j)), fLength[j], ' ', fp); fputs(fieldSep, fp); } - fprintf(fp, "\n"); + fputc('\n', fp); } if (!quiet) @@ -712,7 +712,7 @@ PQprintTuples(const PGresult *res, tborder = (char *) malloc(width + 1); if (!tborder) { - fprintf(stderr, libpq_gettext("out of memory\n")); + fputs(libpq_gettext("out of memory\n"), stderr); return; } for (i = 0; i < width; i++) @@ -734,7 +734,7 @@ PQprintTuples(const PGresult *res, if (PrintAttNames) { if (TerseOutput) - fprintf(fout, "\n"); + fputc('\n', fout); else fprintf(fout, "|\n%s\n", tborder); } @@ -750,7 +750,7 @@ PQprintTuples(const PGresult *res, pval ? pval : ""); } if (TerseOutput) - fprintf(fout, "\n"); + fputc('\n', fout); else fprintf(fout, "|\n%s\n", tborder); } diff --git a/src/interfaces/libpq/fe-secure-openssl.c b/src/interfaces/libpq/fe-secure-openssl.c index 3798bb3f11..5c3c836028 100644 --- a/src/interfaces/libpq/fe-secure-openssl.c +++ b/src/interfaces/libpq/fe-secure-openssl.c @@ -1939,7 +1939,7 @@ PQdefaultSSLKeyPassHook_OpenSSL(char *buf, int size, PGconn *conn) if (conn && conn->sslpassword) { if (strlen(conn->sslpassword) + 1 > size) - fprintf(stderr, libpq_gettext("WARNING: sslpassword truncated\n")); + fputs(libpq_gettext("WARNING: sslpassword truncated\n"), stderr); strncpy(buf, conn->sslpassword, size); buf[size - 1] = '\0'; return strlen(buf); diff --git a/src/interfaces/libpq/fe-trace.c b/src/interfaces/libpq/fe-trace.c index 5d68cf2eb3..1a6f447f50 100644 --- a/src/interfaces/libpq/fe-trace.c +++ b/src/interfaces/libpq/fe-trace.c @@ -149,7 +149,7 @@ pqTraceOutputInt32(FILE *pfdebug, const char *data, int *cursor, bool suppress) *cursor += 4; result = (int) pg_ntoh32(result); if (suppress) - fprintf(pfdebug, " NNNN"); + fputs(" NNNN", pfdebug); else fprintf(pfdebug, " %d", result); @@ -166,7 +166,7 @@ pqTraceOutputString(FILE *pfdebug, const char *data, int *cursor, bool suppress) if (suppress) { - fprintf(pfdebug, " \"SSSS\""); + fputs(" \"SSSS\"", pfdebug); *cursor += strlen(data + *cursor) + 1; } else @@ -191,7 +191,7 @@ pqTraceOutputNchar(FILE *pfdebug, int len, const char *data, int *cursor) next; /* first char not yet printed */ const char *v = data + *cursor; - fprintf(pfdebug, " \'"); + fputs(" \'", pfdebug); for (next = i = 0; i < len; ++i) { @@ -207,7 +207,7 @@ pqTraceOutputNchar(FILE *pfdebug, int len, const char *data, int *cursor) if (next < len) fwrite(v + next, 1, len - next, pfdebug); - fprintf(pfdebug, "\'"); + fputc('\'', pfdebug); *cursor += len; } @@ -219,7 +219,7 @@ pqTraceOutputNchar(FILE *pfdebug, int len, const char *data, int *cursor) static void pqTraceOutputA(FILE *f, const char *message, int *cursor, bool regress) { - fprintf(f, "NotificationResponse\t"); + fputs("NotificationResponse\t", f); pqTraceOutputInt32(f, message, cursor, regress); pqTraceOutputString(f, message, cursor, false); pqTraceOutputString(f, message, cursor, false); @@ -231,7 +231,7 @@ pqTraceOutputB(FILE *f, const char *message, int *cursor) { int nparams; - fprintf(f, "Bind\t"); + fputs("Bind\t", f); pqTraceOutputString(f, message, cursor, false); pqTraceOutputString(f, message, cursor, false); nparams = pqTraceOutputInt16(f, message, cursor); @@ -262,13 +262,13 @@ pqTraceOutputC(FILE *f, bool toServer, const char *message, int *cursor) { if (toServer) { - fprintf(f, "Close\t"); + fputs("Close\t", f); pqTraceOutputByte1(f, message, cursor); pqTraceOutputString(f, message, cursor, false); } else { - fprintf(f, "CommandComplete\t"); + fputs("CommandComplete\t", f); pqTraceOutputString(f, message, cursor, false); } } @@ -279,7 +279,7 @@ pqTraceOutputD(FILE *f, bool toServer, const char *message, int *cursor) { if (toServer) { - fprintf(f, "Describe\t"); + fputs("Describe\t", f); pqTraceOutputByte1(f, message, cursor); pqTraceOutputString(f, message, cursor, false); } @@ -289,7 +289,7 @@ pqTraceOutputD(FILE *f, bool toServer, const char *message, int *cursor) int len; int i; - fprintf(f, "DataRow\t"); + fputs("DataRow\t", f); nfields = pqTraceOutputInt16(f, message, cursor); for (i = 0; i < nfields; i++) { @@ -328,7 +328,7 @@ pqTraceOutputE(FILE *f, bool toServer, const char *message, int *cursor, bool re { if (toServer) { - fprintf(f, "Execute\t"); + fputs("Execute\t", f); pqTraceOutputString(f, message, cursor, false); pqTraceOutputInt32(f, message, cursor, false); } @@ -340,7 +340,7 @@ pqTraceOutputE(FILE *f, bool toServer, const char *message, int *cursor, bool re static void pqTraceOutputf(FILE *f, const char *message, int *cursor) { - fprintf(f, "CopyFail\t"); + fputs("CopyFail\t", f); pqTraceOutputString(f, message, cursor, false); } @@ -351,7 +351,7 @@ pqTraceOutputF(FILE *f, const char *message, int *cursor, bool regress) int nfields; int nbytes; - fprintf(f, "FunctionCall\t"); + fputs("FunctionCall\t", f); pqTraceOutputInt32(f, message, cursor, regress); nfields = pqTraceOutputInt16(f, message, cursor); @@ -377,7 +377,7 @@ pqTraceOutputG(FILE *f, const char *message, int *cursor) { int nfields; - fprintf(f, "CopyInResponse\t"); + fputs("CopyInResponse\t", f); pqTraceOutputByte1(f, message, cursor); nfields = pqTraceOutputInt16(f, message, cursor); @@ -391,7 +391,7 @@ pqTraceOutputH(FILE *f, const char *message, int *cursor) { int nfields; - fprintf(f, "CopyOutResponse\t"); + fputs("CopyOutResponse\t", f); pqTraceOutputByte1(f, message, cursor); nfields = pqTraceOutputInt16(f, message, cursor); @@ -403,7 +403,7 @@ pqTraceOutputH(FILE *f, const char *message, int *cursor) static void pqTraceOutputK(FILE *f, const char *message, int *cursor, bool regress) { - fprintf(f, "BackendKeyData\t"); + fputs("BackendKeyData\t", f); pqTraceOutputInt32(f, message, cursor, regress); pqTraceOutputInt32(f, message, cursor, regress); } @@ -414,7 +414,7 @@ pqTraceOutputP(FILE *f, const char *message, int *cursor, bool regress) { int nparams; - fprintf(f, "Parse\t"); + fputs("Parse\t", f); pqTraceOutputString(f, message, cursor, false); pqTraceOutputString(f, message, cursor, false); nparams = pqTraceOutputInt16(f, message, cursor); @@ -427,7 +427,7 @@ pqTraceOutputP(FILE *f, const char *message, int *cursor, bool regress) static void pqTraceOutputQ(FILE *f, const char *message, int *cursor) { - fprintf(f, "Query\t"); + fputs("Query\t", f); pqTraceOutputString(f, message, cursor, false); } @@ -435,7 +435,7 @@ pqTraceOutputQ(FILE *f, const char *message, int *cursor) static void pqTraceOutputR(FILE *f, const char *message, int *cursor) { - fprintf(f, "Authentication\t"); + fputs("Authentication\t", f); pqTraceOutputInt32(f, message, cursor, false); } @@ -443,7 +443,7 @@ pqTraceOutputR(FILE *f, const char *message, int *cursor) static void pqTraceOutputS(FILE *f, const char *message, int *cursor) { - fprintf(f, "ParameterStatus\t"); + fputs("ParameterStatus\t", f); pqTraceOutputString(f, message, cursor, false); pqTraceOutputString(f, message, cursor, false); } @@ -454,7 +454,7 @@ pqTraceOutputt(FILE *f, const char *message, int *cursor, bool regress) { int nfields; - fprintf(f, "ParameterDescription\t"); + fputs("ParameterDescription\t", f); nfields = pqTraceOutputInt16(f, message, cursor); for (int i = 0; i < nfields; i++) @@ -467,7 +467,7 @@ pqTraceOutputT(FILE *f, const char *message, int *cursor, bool regress) { int nfields; - fprintf(f, "RowDescription\t"); + fputs("RowDescription\t", f); nfields = pqTraceOutputInt16(f, message, cursor); for (int i = 0; i < nfields; i++) @@ -486,7 +486,7 @@ pqTraceOutputT(FILE *f, const char *message, int *cursor, bool regress) static void pqTraceOutputv(FILE *f, const char *message, int *cursor) { - fprintf(f, "NegotiateProtocolVersion\t"); + fputs("NegotiateProtocolVersion\t", f); pqTraceOutputInt32(f, message, cursor, false); pqTraceOutputInt32(f, message, cursor, false); } @@ -497,7 +497,7 @@ pqTraceOutputV(FILE *f, const char *message, int *cursor) { int len; - fprintf(f, "FunctionCallResponse\t"); + fputs("FunctionCallResponse\t", f); len = pqTraceOutputInt32(f, message, cursor, false); if (len != -1) pqTraceOutputNchar(f, len, message, cursor); @@ -507,7 +507,7 @@ pqTraceOutputV(FILE *f, const char *message, int *cursor) static void pqTraceOutputW(FILE *f, const char *message, int *cursor, int length) { - fprintf(f, "CopyBothResponse\t"); + fputs("CopyBothResponse\t", f); pqTraceOutputByte1(f, message, cursor); while (length > *cursor) @@ -518,7 +518,7 @@ pqTraceOutputW(FILE *f, const char *message, int *cursor, int length) static void pqTraceOutputZ(FILE *f, const char *message, int *cursor) { - fprintf(f, "ReadyForQuery\t"); + fputs("ReadyForQuery\t", f); pqTraceOutputByte1(f, message, cursor); } @@ -563,15 +563,15 @@ pqTraceOutputMessage(PGconn *conn, const char *message, bool toServer) switch (id) { case '1': - fprintf(conn->Pfdebug, "ParseComplete"); + fputs("ParseComplete", conn->Pfdebug); /* No message content */ break; case '2': - fprintf(conn->Pfdebug, "BindComplete"); + fputs("BindComplete", conn->Pfdebug); /* No message content */ break; case '3': - fprintf(conn->Pfdebug, "CloseComplete"); + fputs("CloseComplete", conn->Pfdebug); /* No message content */ break; case 'A': /* Notification Response */ @@ -581,7 +581,7 @@ pqTraceOutputMessage(PGconn *conn, const char *message, bool toServer) pqTraceOutputB(conn->Pfdebug, message, &logCursor); break; case 'c': - fprintf(conn->Pfdebug, "CopyDone"); + fputs("CopyDone", conn->Pfdebug); /* No message content */ break; case 'C': /* Close(F) or Command Complete(B) */ @@ -610,17 +610,17 @@ pqTraceOutputMessage(PGconn *conn, const char *message, bool toServer) if (!toServer) pqTraceOutputH(conn->Pfdebug, message, &logCursor); else - fprintf(conn->Pfdebug, "Flush"); /* no message content */ + fputs("Flush", conn->Pfdebug); /* no message content */ break; case 'I': - fprintf(conn->Pfdebug, "EmptyQueryResponse"); + fputs("EmptyQueryResponse", conn->Pfdebug); /* No message content */ break; case 'K': /* secret key data from the backend */ pqTraceOutputK(conn->Pfdebug, message, &logCursor, regress); break; case 'n': - fprintf(conn->Pfdebug, "NoData"); + fputs("NoData", conn->Pfdebug); /* No message content */ break; case 'N': @@ -637,14 +637,14 @@ pqTraceOutputMessage(PGconn *conn, const char *message, bool toServer) pqTraceOutputR(conn->Pfdebug, message, &logCursor); break; case 's': - fprintf(conn->Pfdebug, "PortalSuspended"); + fputs("PortalSuspended", conn->Pfdebug); /* No message content */ break; case 'S': /* Parameter Status(B) or Sync(F) */ if (!toServer) pqTraceOutputS(conn->Pfdebug, message, &logCursor); else - fprintf(conn->Pfdebug, "Sync"); /* no message content */ + fputs("Sync", conn->Pfdebug); /* no message content */ break; case 't': /* Parameter Description */ pqTraceOutputt(conn->Pfdebug, message, &logCursor, regress); @@ -662,7 +662,7 @@ pqTraceOutputMessage(PGconn *conn, const char *message, bool toServer) pqTraceOutputW(conn->Pfdebug, message, &logCursor, length); break; case 'X': - fprintf(conn->Pfdebug, "Terminate"); + fputs("Terminate", conn->Pfdebug); /* No message content */ break; case 'Z': /* Ready For Query */ diff --git a/src/interfaces/libpq/test/libpq_testclient.c b/src/interfaces/libpq/test/libpq_testclient.c index d945bacf1b..1766ea3158 100644 --- a/src/interfaces/libpq/test/libpq_testclient.c +++ b/src/interfaces/libpq/test/libpq_testclient.c @@ -18,7 +18,7 @@ print_ssl_library() const char *lib = PQsslAttribute(NULL, "library"); if (!lib) - fprintf(stderr, "SSL is not enabled\n"); + fputs("SSL is not enabled\n", stderr); else printf("%s\n", lib); } diff --git a/src/interfaces/libpq/test/libpq_uri_regress.c b/src/interfaces/libpq/test/libpq_uri_regress.c index 60469002fd..52f4afedc1 100644 --- a/src/interfaces/libpq/test/libpq_uri_regress.c +++ b/src/interfaces/libpq/test/libpq_uri_regress.c @@ -40,7 +40,7 @@ main(int argc, char *argv[]) defs = PQconndefaults(); if (defs == NULL) { - fprintf(stderr, "libpq_uri_regress: cannot fetch default options\n"); + fputs("libpq_uri_regress: cannot fetch default options\n", stderr); return 1; } diff --git a/src/port/path.c b/src/port/path.c index 05fe812f75..7f3d61966b 100644 --- a/src/port/path.c +++ b/src/port/path.c @@ -750,7 +750,7 @@ make_absolute_path(const char *path) (errcode(ERRCODE_OUT_OF_MEMORY), errmsg("out of memory"))); #else - fprintf(stderr, _("out of memory\n")); + fputs(_("out of memory\n"), stderr); return NULL; #endif } @@ -788,7 +788,7 @@ make_absolute_path(const char *path) (errcode(ERRCODE_OUT_OF_MEMORY), errmsg("out of memory"))); #else - fprintf(stderr, _("out of memory\n")); + fputs(_("out of memory\n"), stderr); return NULL; #endif } @@ -805,7 +805,7 @@ make_absolute_path(const char *path) (errcode(ERRCODE_OUT_OF_MEMORY), errmsg("out of memory"))); #else - fprintf(stderr, _("out of memory\n")); + fputs(_("out of memory\n"), stderr); return NULL; #endif } diff --git a/src/test/examples/testlibpq.c b/src/test/examples/testlibpq.c index 0372781eaf..99d3c2578a 100644 --- a/src/test/examples/testlibpq.c +++ b/src/test/examples/testlibpq.c @@ -43,7 +43,7 @@ main(int argc, char **argv) /* Check to see that the backend connection was successfully made */ if (PQstatus(conn) != CONNECTION_OK) { - fprintf(stderr, "%s", PQerrorMessage(conn)); + fputs(PQerrorMessage(conn), stderr); exit_nicely(conn); } diff --git a/src/test/examples/testlibpq2.c b/src/test/examples/testlibpq2.c index 05ce8c3f13..24d9687bc2 100644 --- a/src/test/examples/testlibpq2.c +++ b/src/test/examples/testlibpq2.c @@ -70,7 +70,7 @@ main(int argc, char **argv) /* Check to see that the backend connection was successfully made */ if (PQstatus(conn) != CONNECTION_OK) { - fprintf(stderr, "%s", PQerrorMessage(conn)); + fputs(PQerrorMessage(conn), stderr); exit_nicely(conn); } @@ -141,7 +141,7 @@ main(int argc, char **argv) } } - fprintf(stderr, "Done.\n"); + fputs("Done.\n", stderr); /* close the connection to the database and cleanup */ PQfinish(conn); diff --git a/src/test/examples/testlibpq3.c b/src/test/examples/testlibpq3.c index 4f7b791388..f2d5797d53 100644 --- a/src/test/examples/testlibpq3.c +++ b/src/test/examples/testlibpq3.c @@ -138,7 +138,7 @@ main(int argc, char **argv) /* Check to see that the backend connection was successfully made */ if (PQstatus(conn) != CONNECTION_OK) { - fprintf(stderr, "%s", PQerrorMessage(conn)); + fputs(PQerrorMessage(conn), stderr); exit_nicely(conn); } diff --git a/src/test/examples/testlibpq4.c b/src/test/examples/testlibpq4.c index da4443072d..14d14b5d7c 100644 --- a/src/test/examples/testlibpq4.c +++ b/src/test/examples/testlibpq4.c @@ -29,7 +29,7 @@ check_prepare_conn(PGconn *conn, const char *dbName) /* check to see that the backend connection was successfully made */ if (PQstatus(conn) != CONNECTION_OK) { - fprintf(stderr, "%s", PQerrorMessage(conn)); + fputs(PQerrorMessage(conn), stderr); exit(1); } diff --git a/src/test/examples/testlo.c b/src/test/examples/testlo.c index 1b08b6cac5..1761d36788 100644 --- a/src/test/examples/testlo.c +++ b/src/test/examples/testlo.c @@ -54,7 +54,7 @@ importFile(PGconn *conn, char *filename) */ lobjId = lo_creat(conn, INV_READ | INV_WRITE); if (lobjId == 0) - fprintf(stderr, "cannot create large object"); + fputs("cannot create large object", stderr); lobj_fd = lo_open(conn, lobjId, INV_WRITE); @@ -100,7 +100,7 @@ pickout(PGconn *conn, Oid lobjId, int start, int len) break; /* no more data? */ } free(buf); - fprintf(stderr, "\n"); + fputc('\n', stderr); lo_close(conn, lobj_fd); } @@ -131,12 +131,12 @@ overwrite(PGconn *conn, Oid lobjId, int start, int len) nwritten += nbytes; if (nbytes <= 0) { - fprintf(stderr, "\nWRITE FAILED!\n"); + fputs("\nWRITE FAILED!\n", stderr); break; } } free(buf); - fprintf(stderr, "\n"); + fputc('\n', stderr); lo_close(conn, lobj_fd); } @@ -225,7 +225,7 @@ main(int argc, char **argv) /* check to see that the backend connection was successfully made */ if (PQstatus(conn) != CONNECTION_OK) { - fprintf(stderr, "%s", PQerrorMessage(conn)); + fputs(PQerrorMessage(conn), stderr); exit_nicely(conn); } diff --git a/src/test/examples/testlo64.c b/src/test/examples/testlo64.c index 981e29ad78..550b1a7dd3 100644 --- a/src/test/examples/testlo64.c +++ b/src/test/examples/testlo64.c @@ -54,7 +54,7 @@ importFile(PGconn *conn, char *filename) */ lobjId = lo_creat(conn, INV_READ | INV_WRITE); if (lobjId == 0) - fprintf(stderr, "cannot create large object"); + fputs("cannot create large object", stderr); lobj_fd = lo_open(conn, lobjId, INV_WRITE); @@ -105,7 +105,7 @@ pickout(PGconn *conn, Oid lobjId, pg_int64 start, int len) break; /* no more data? */ } free(buf); - fprintf(stderr, "\n"); + fputc('\n', stderr); lo_close(conn, lobj_fd); } @@ -138,12 +138,12 @@ overwrite(PGconn *conn, Oid lobjId, pg_int64 start, int len) nwritten += nbytes; if (nbytes <= 0) { - fprintf(stderr, "\nWRITE FAILED!\n"); + fputs("\nWRITE FAILED!\n", stderr); break; } } free(buf); - fprintf(stderr, "\n"); + fputc('\n', stderr); lo_close(conn, lobj_fd); } @@ -249,7 +249,7 @@ main(int argc, char **argv) /* check to see that the backend connection was successfully made */ if (PQstatus(conn) != CONNECTION_OK) { - fprintf(stderr, "%s", PQerrorMessage(conn)); + fputs(PQerrorMessage(conn), stderr); exit_nicely(conn); } diff --git a/src/test/isolation/isolation_main.c b/src/test/isolation/isolation_main.c index 31a0e6b709..37251647ad 100644 --- a/src/test/isolation/isolation_main.c +++ b/src/test/isolation/isolation_main.c @@ -45,7 +45,7 @@ isolation_start_test(const char *testname, if (find_other_exec(saved_argv0, "isolationtester", PG_ISOLATION_VERSIONSTR, isolation_exec) != 0) { - fprintf(stderr, _("could not find proper isolationtester binary\n")); + fputs(_("could not find proper isolationtester binary\n"), stderr); exit(2); } looked_up_isolation_exec = true; @@ -81,7 +81,7 @@ isolation_start_test(const char *testname, "%s ", launcher); if (offset >= sizeof(psql_cmd)) { - fprintf(stderr, _("command too long\n")); + fputs(_("command too long\n"), stderr); exit(2); } } @@ -94,7 +94,7 @@ isolation_start_test(const char *testname, outfile); if (offset >= sizeof(psql_cmd)) { - fprintf(stderr, _("command too long\n")); + fputs(_("command too long\n"), stderr); exit(2); } diff --git a/src/test/modules/libpq_pipeline/libpq_pipeline.c b/src/test/modules/libpq_pipeline/libpq_pipeline.c index 0407c4a8c0..57aaf36102 100644 --- a/src/test/modules/libpq_pipeline/libpq_pipeline.c +++ b/src/test/modules/libpq_pipeline/libpq_pipeline.c @@ -80,7 +80,7 @@ pg_fatal_impl(int line, const char *fmt,...) vfprintf(stderr, fmt, args); va_end(args); Assert(fmt[strlen(fmt) - 1] != '\n'); - fprintf(stderr, "\n"); + fputc('\n', stderr); exit(1); } @@ -89,7 +89,7 @@ test_disallowed_in_pipeline(PGconn *conn) { PGresult *res = NULL; - fprintf(stderr, "test error cases... "); + fputs("test error cases... ", stderr); if (PQisnonblocking(conn)) pg_fatal("Expected blocking connection mode"); @@ -129,7 +129,7 @@ test_disallowed_in_pipeline(PGconn *conn) pg_fatal("PQexec should succeed after exiting pipeline mode but failed with: %s", PQerrorMessage(conn)); - fprintf(stderr, "ok\n"); + fputs("ok\n", stderr); } static void @@ -139,7 +139,7 @@ test_multi_pipelines(PGconn *conn) const char *dummy_params[1] = {"1"}; Oid dummy_param_oids[1] = {INT4OID}; - fprintf(stderr, "multi pipeline... "); + fputs("multi pipeline... ", stderr); /* * Queue up a couple of small pipelines and process each without returning @@ -227,7 +227,7 @@ test_multi_pipelines(PGconn *conn) if (PQpipelineStatus(conn) != PQ_PIPELINE_OFF) pg_fatal("exiting pipeline mode didn't seem to work"); - fprintf(stderr, "ok\n"); + fputs("ok\n", stderr); } /* @@ -241,7 +241,7 @@ test_nosync(PGconn *conn) int results = 0; int sock = PQsocket(conn); - fprintf(stderr, "nosync... "); + fputs("nosync... ", stderr); if (sock < 0) pg_fatal("invalid socket"); @@ -314,7 +314,7 @@ test_nosync(PGconn *conn) pg_fatal("got unexpected %s\n", PQresStatus(PQresultStatus(res))); } - fprintf(stderr, "ok\n"); + fputs("ok\n", stderr); } /* @@ -336,7 +336,7 @@ test_pipeline_abort(PGconn *conn) int gotrows; bool goterror; - fprintf(stderr, "aborted pipeline... "); + fputs("aborted pipeline... ", stderr); res = PQexec(conn, drop_table_sql); if (PQresultStatus(res) != PGRES_COMMAND_OK) @@ -524,7 +524,7 @@ test_pipeline_abort(PGconn *conn) if (PQresultStatus(res) != PGRES_PIPELINE_SYNC) pg_fatal("Unexpected result code %s from pipeline sync", PQresStatus(PQresultStatus(res))); - fprintf(stderr, "ok\n"); + fputs("ok\n", stderr); /* Test single-row mode with an error partways */ if (PQsendQuery(conn, "SELECT 1.0/g FROM generate_series(3, -1, -1) g") != 1) @@ -611,7 +611,7 @@ test_pipeline_abort(PGconn *conn) PQclear(res); - fprintf(stderr, "ok\n"); + fputs("ok\n", stderr); } /* State machine enum for test_pipelined_insert */ @@ -850,7 +850,7 @@ test_pipelined_insert(PGconn *conn, int n_rows) { if (PQpipelineSync(conn) == 1) { - fprintf(stdout, "pipeline sync sent\n"); + fputs("pipeline sync sent\n", stdout); send_step++; } else @@ -870,7 +870,7 @@ test_pipelined_insert(PGconn *conn, int n_rows) if (PQsetnonblocking(conn, 0) != 0) pg_fatal("failed to clear nonblocking mode: %s", PQerrorMessage(conn)); - fprintf(stderr, "ok\n"); + fputs("ok\n", stderr); } static void @@ -881,7 +881,7 @@ test_prepared(PGconn *conn) Oid expected_oids[4]; Oid typ; - fprintf(stderr, "prepared... "); + fputs("prepared... ", stderr); if (PQenterPipelineMode(conn) != 1) pg_fatal("failed to enter pipeline mode: %s", PQerrorMessage(conn)); @@ -963,7 +963,7 @@ test_prepared(PGconn *conn) if (PQexitPipelineMode(conn) != 1) pg_fatal("could not exit pipeline mode: %s", PQerrorMessage(conn)); - fprintf(stderr, "ok\n"); + fputs("ok\n", stderr); } /* Notice processor: print notices, and count how many we got */ @@ -983,7 +983,7 @@ test_pipeline_idle(PGconn *conn) PGresult *res; int n_notices = 0; - fprintf(stderr, "\npipeline idle...\n"); + fputs("\npipeline idle...\n", stderr); PQsetNoticeProcessor(conn, notice_processor, &n_notices); @@ -1033,7 +1033,7 @@ test_pipeline_idle(PGconn *conn) */ if (n_notices > 0) pg_fatal("got %d notice(s)", n_notices); - fprintf(stderr, "ok - 1\n"); + fputs("ok - 1\n", stderr); /* * Verify that we can send a query using simple query protocol after one @@ -1071,7 +1071,7 @@ test_pipeline_idle(PGconn *conn) pg_fatal("did not receive terminating NULL"); if (n_notices > 0) pg_fatal("got %d notice(s)", n_notices); - fprintf(stderr, "ok - 2\n"); + fputs("ok - 2\n", fputs); /* * Case 2: exiting pipeline mode is not OK if a second command is sent. @@ -1149,7 +1149,7 @@ test_pipeline_idle(PGconn *conn) if (n_notices > 0) pg_fatal("got %d notice(s)", n_notices); - fprintf(stderr, "ok - 3\n"); + fputs("ok - 3\n", stderr); /* Have a WARNING in the middle of a resultset */ if (PQenterPipelineMode(conn) != 1) @@ -1164,7 +1164,7 @@ test_pipeline_idle(PGconn *conn) pg_fatal("unexpected result code %s", PQresStatus(PQresultStatus(res))); if (PQexitPipelineMode(conn) != 1) pg_fatal("failed to exit pipeline mode: %s", PQerrorMessage(conn)); - fprintf(stderr, "ok - 4\n"); + fputs("ok - 4\n", stderr); } static void @@ -1174,7 +1174,7 @@ test_simple_pipeline(PGconn *conn) const char *dummy_params[1] = {"1"}; Oid dummy_param_oids[1] = {INT4OID}; - fprintf(stderr, "simple pipeline... "); + fputs("simple pipeline... ", stderr); /* * Enter pipeline mode and dispatch a set of operations, which we'll then @@ -1251,7 +1251,7 @@ test_simple_pipeline(PGconn *conn) if (PQpipelineStatus(conn) != PQ_PIPELINE_OFF) pg_fatal("Exiting pipeline mode didn't seem to work"); - fprintf(stderr, "ok\n"); + fputs("ok\n", stderr); } static void @@ -1308,7 +1308,7 @@ test_singlerowmode(PGconn *conn) if (est == PGRES_PIPELINE_SYNC) { - fprintf(stderr, "end of pipeline reached\n"); + fputs("end of pipeline reached\n", stderr); pipeline_ended = true; PQclear(res); if (i != 3) @@ -1360,7 +1360,7 @@ test_singlerowmode(PGconn *conn) if (PQexitPipelineMode(conn) != 1) pg_fatal("failed to end pipeline mode: %s", PQerrorMessage(conn)); - fprintf(stderr, "ok\n"); + fputs("ok\n", stderr); } /* @@ -1507,7 +1507,7 @@ test_transaction(PGconn *conn) pg_fatal("did not get expected tuple"); PQclear(res); - fprintf(stderr, "ok\n"); + fputs("ok\n", stderr); } /* @@ -1536,7 +1536,7 @@ test_uniqviol(PGconn *conn) fd_set in_fds; fd_set out_fds; - fprintf(stderr, "uniqviol ..."); + fputs("uniqviol ...", stderr); PQsetnonblocking(conn, 1); @@ -1631,12 +1631,12 @@ test_uniqviol(PGconn *conn) if (switched >= 1 && !error_sent && ctr % socketful >= socketful / 2) { sprintf(paramValue0, "%d", numsent / 2); - fprintf(stderr, "E"); + fputc('E', stderr); error_sent = true; } else { - fprintf(stderr, "."); + fputc('.', stderr); sprintf(paramValue0, "%d", ctr++); } @@ -1650,7 +1650,7 @@ test_uniqviol(PGconn *conn) if (PQsendFlushRequest(conn) != 1) pg_fatal("failed to send flush request"); write_done = true; - fprintf(stderr, "\ndone writing\n"); + fputs("\ndone writing\n", stderr); PQflush(conn); break; } @@ -1663,7 +1663,7 @@ test_uniqviol(PGconn *conn) { if (socketful == 0) socketful = numsent; - fprintf(stderr, "\nswitch to reading\n"); + fputs("\nswitch to reading\n", stderr); switched++; break; } @@ -1674,7 +1674,7 @@ test_uniqviol(PGconn *conn) if (!got_error) pg_fatal("did not get expected error"); - fprintf(stderr, "ok\n"); + fputs("ok\n", stderr); } /* diff --git a/src/test/regress/pg_regress.c b/src/test/regress/pg_regress.c index 7290948eee..13157724c3 100644 --- a/src/test/regress/pg_regress.c +++ b/src/test/regress/pg_regress.c @@ -245,10 +245,10 @@ status(const char *fmt,...) static void status_end(void) { - fprintf(stdout, "\n"); + fputc('\n', stdout); fflush(stdout); if (logfile) - fprintf(logfile, "\n"); + fputc('\n', logfile); } /* diff --git a/src/test/regress/pg_regress_main.c b/src/test/regress/pg_regress_main.c index a4b354c9e6..594d0ce570 100644 --- a/src/test/regress/pg_regress_main.c +++ b/src/test/regress/pg_regress_main.c @@ -68,7 +68,7 @@ psql_start_test(const char *testname, "%s ", launcher); if (offset >= sizeof(psql_cmd)) { - fprintf(stderr, _("command too long\n")); + fputs(_("command too long\n"), stderr); exit(2); } } @@ -87,7 +87,7 @@ psql_start_test(const char *testname, outfile); if (offset >= sizeof(psql_cmd)) { - fprintf(stderr, _("command too long\n")); + fputs(_("command too long\n"), stderr); exit(2); } diff --git a/src/timezone/zic.c b/src/timezone/zic.c index 0ea6ead2db..ec432b6a23 100644 --- a/src/timezone/zic.c +++ b/src/timezone/zic.c @@ -495,7 +495,7 @@ verror(const char *string, va_list args) if (rfilename != NULL) fprintf(stderr, _(" (rule from \"%s\", line %d)"), rfilename, rlinenum); - fprintf(stderr, "\n"); + fputc('\n', stderr); } static void @@ -514,7 +514,7 @@ warning(const char *string,...) { va_list args; - fprintf(stderr, _("warning: ")); + fputs(_("warning: "), stderr); va_start(args, string); verror(string, args); va_end(args);