diff options
| author | Tom Lane | 2013-10-22 23:40:26 +0000 |
|---|---|---|
| committer | Tom Lane | 2013-10-22 23:40:26 +0000 |
| commit | 2c66f9924c1162bfba27c77004ccf42fb6ea188d (patch) | |
| tree | 920c20776ef6d13d7a5d3a836202d897abcaf428 /src/bin | |
| parent | 09a89cb5fc29b47c26d151e82293fd3bef592b7b (diff) | |
Replace pg_asprintf() with psprintf().
This eliminates an awkward coding pattern that's also unnecessarily
inconsistent with backend coding. psprintf() is now the thing to
use everywhere.
Diffstat (limited to 'src/bin')
| -rw-r--r-- | src/bin/initdb/initdb.c | 14 | ||||
| -rw-r--r-- | src/bin/pg_ctl/pg_ctl.c | 6 | ||||
| -rw-r--r-- | src/bin/pg_dump/compress_io.c | 4 | ||||
| -rw-r--r-- | src/bin/pg_dump/pg_dump.c | 4 | ||||
| -rw-r--r-- | src/bin/psql/command.c | 16 | ||||
| -rw-r--r-- | src/bin/psql/common.c | 4 | ||||
| -rw-r--r-- | src/bin/psql/copy.c | 2 | ||||
| -rw-r--r-- | src/bin/psql/input.c | 2 | ||||
| -rw-r--r-- | src/bin/psql/startup.c | 8 | ||||
| -rw-r--r-- | src/bin/psql/tab-complete.c | 5 |
10 files changed, 31 insertions, 34 deletions
diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c index f7073e26bd7..3983b237313 100644 --- a/src/bin/initdb/initdb.c +++ b/src/bin/initdb/initdb.c @@ -949,7 +949,7 @@ mkdatadir(const char *subdir) char *path; if (subdir) - pg_asprintf(&path, "%s/%s", pg_data, subdir); + path = psprintf("%s/%s", pg_data, subdir); else path = pg_strdup(pg_data); @@ -969,7 +969,7 @@ mkdatadir(const char *subdir) static void set_input(char **dest, char *filename) { - pg_asprintf(dest, "%s/%s", share_path, filename); + *dest = psprintf("%s/%s", share_path, filename); } /* @@ -1023,9 +1023,9 @@ write_version_file(char *extrapath) char *path; if (extrapath == NULL) - pg_asprintf(&path, "%s/PG_VERSION", pg_data); + path = psprintf("%s/PG_VERSION", pg_data); else - pg_asprintf(&path, "%s/%s/PG_VERSION", pg_data, extrapath); + path = psprintf("%s/%s/PG_VERSION", pg_data, extrapath); if ((version_file = fopen(path, PG_BINARY_W)) == NULL) { @@ -1053,7 +1053,7 @@ set_null_conf(void) FILE *conf_file; char *path; - pg_asprintf(&path, "%s/postgresql.conf", pg_data); + path = psprintf("%s/postgresql.conf", pg_data); conf_file = fopen(path, PG_BINARY_W); if (conf_file == NULL) { @@ -2951,7 +2951,7 @@ setup_pgdata(void) * need quotes otherwise on Windows because paths there are most likely to * have embedded spaces. */ - pg_asprintf(&pgdata_set_env, "PGDATA=%s", pg_data); + pgdata_set_env = psprintf("PGDATA=%s", pg_data); putenv(pgdata_set_env); } @@ -3345,7 +3345,7 @@ create_xlog_symlink(void) } /* form name of the place where the symlink must go */ - pg_asprintf(&linkloc, "%s/pg_xlog", pg_data); + linkloc = psprintf("%s/pg_xlog", pg_data); #ifdef HAVE_SYMLINK if (symlink(xlog_dir, linkloc) != 0) diff --git a/src/bin/pg_ctl/pg_ctl.c b/src/bin/pg_ctl/pg_ctl.c index be51dc62ca7..8399cdd57e3 100644 --- a/src/bin/pg_ctl/pg_ctl.c +++ b/src/bin/pg_ctl/pg_ctl.c @@ -2049,7 +2049,7 @@ main(int argc, char **argv) pgdata_D = pg_strdup(optarg); canonicalize_path(pgdata_D); - pg_asprintf(&env_var, "PGDATA=%s", pgdata_D); + env_var = psprintf("PGDATA=%s", pgdata_D); putenv(env_var); /* @@ -2057,7 +2057,7 @@ main(int argc, char **argv) * variable but we do -D too for clearer postmaster * 'ps' display */ - pg_asprintf(&pgdata_opt, "-D \"%s\" ", pgdata_D); + pgdata_opt = psprintf("-D \"%s\" ", pgdata_D); break; } case 'l': @@ -2098,7 +2098,7 @@ main(int argc, char **argv) register_username = pg_strdup(optarg); else /* Prepend .\ for local accounts */ - pg_asprintf(®ister_username, ".\\%s", optarg); + register_username = psprintf(".\\%s", optarg); break; case 'w': do_wait = true; diff --git a/src/bin/pg_dump/compress_io.c b/src/bin/pg_dump/compress_io.c index d859c8ee1e9..dd62fa013c0 100644 --- a/src/bin/pg_dump/compress_io.c +++ b/src/bin/pg_dump/compress_io.c @@ -489,7 +489,7 @@ cfopen_read(const char *path, const char *mode) { char *fname; - pg_asprintf(&fname, "%s.gz", path); + fname = psprintf("%s.gz", path); fp = cfopen(fname, mode, 1); free(fname); } @@ -519,7 +519,7 @@ cfopen_write(const char *path, const char *mode, int compression) #ifdef HAVE_LIBZ char *fname; - pg_asprintf(&fname, "%s.gz", path); + fname = psprintf("%s.gz", path); fp = cfopen(fname, mode, 1); free(fname); #else diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 01c63b13348..bc70dd6a6ed 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -10439,7 +10439,7 @@ convertOperatorReference(Archive *fout, const char *opr) /* If not schema-qualified, don't need to add OPERATOR() */ if (!sawdot) return name; - pg_asprintf(&oname, "OPERATOR(%s)", name); + oname = psprintf("OPERATOR(%s)", name); free(name); return oname; } @@ -12753,7 +12753,7 @@ dumpTable(Archive *fout, TableInfo *tbinfo) char *acltag; attnamecopy = pg_strdup(fmtId(attname)); - pg_asprintf(&acltag, "%s.%s", tbinfo->dobj.name, attname); + acltag = psprintf("%s.%s", tbinfo->dobj.name, attname); /* Column's GRANT type is always TABLE */ dumpACL(fout, tbinfo->dobj.catId, tbinfo->dobj.dumpId, "TABLE", namecopy, attnamecopy, acltag, diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index 06ed56be683..0daac61e01c 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -1188,7 +1188,7 @@ exec_command(const char *cmd, /* Set variable to the value of the next argument */ char *newval; - pg_asprintf(&newval, "%s=%s", envvar, envval); + newval = psprintf("%s=%s", envvar, envval); putenv(newval); success = true; @@ -1549,7 +1549,7 @@ prompt_for_password(const char *username) { char *prompt_text; - pg_asprintf(&prompt_text, _("Password for user %s: "), username); + prompt_text = psprintf(_("Password for user %s: "), username); result = simple_prompt(prompt_text, 100, false); free(prompt_text); } @@ -1929,17 +1929,17 @@ editFile(const char *fname, int lineno) */ #ifndef WIN32 if (lineno > 0) - pg_asprintf(&sys, "exec %s %s%d '%s'", + sys = psprintf("exec %s %s%d '%s'", editorName, editor_lineno_arg, lineno, fname); else - pg_asprintf(&sys, "exec %s '%s'", + sys = psprintf("exec %s '%s'", editorName, fname); #else if (lineno > 0) - pg_asprintf(&sys, SYSTEMQUOTE "\"%s\" %s%d \"%s\"" SYSTEMQUOTE, + sys = psprintf(SYSTEMQUOTE "\"%s\" %s%d \"%s\"" SYSTEMQUOTE, editorName, editor_lineno_arg, lineno, fname); else - pg_asprintf(&sys, SYSTEMQUOTE "\"%s\" \"%s\"" SYSTEMQUOTE, + sys = psprintf(SYSTEMQUOTE "\"%s\" \"%s\"" SYSTEMQUOTE, editorName, fname); #endif result = system(sys); @@ -2635,9 +2635,9 @@ do_shell(const char *command) /* See EDITOR handling comment for an explanation */ #ifndef WIN32 - pg_asprintf(&sys, "exec %s", shellName); + sys = psprintf("exec %s", shellName); #else - pg_asprintf(&sys, SYSTEMQUOTE "\"%s\"" SYSTEMQUOTE, shellName); + sys = psprintf(SYSTEMQUOTE "\"%s\"" SYSTEMQUOTE, shellName); #endif result = system(sys); free(sys); diff --git a/src/bin/psql/common.c b/src/bin/psql/common.c index 71f0c8a95a8..bbdafab5e05 100644 --- a/src/bin/psql/common.c +++ b/src/bin/psql/common.c @@ -594,7 +594,7 @@ StoreQueryTuple(const PGresult *result) char *value; /* concate prefix and column name */ - pg_asprintf(&varname, "%s%s", pset.gset_prefix, colname); + varname = psprintf("%s%s", pset.gset_prefix, colname); if (!PQgetisnull(result, 0, i)) value = PQgetvalue(result, 0, i); @@ -1685,7 +1685,7 @@ expand_tilde(char **filename) { char *newfn; - pg_asprintf(&newfn, "%s%s", home, p); + newfn = psprintf("%s%s", home, p); free(fn); *filename = newfn; } diff --git a/src/bin/psql/copy.c b/src/bin/psql/copy.c index 6db063ca953..a0c19a8de48 100644 --- a/src/bin/psql/copy.c +++ b/src/bin/psql/copy.c @@ -79,7 +79,7 @@ xstrcat(char **var, const char *more) { char *newvar; - pg_asprintf(&newvar, "%s%s", *var, more); + newvar = psprintf("%s%s", *var, more); free(*var); *var = newvar; } diff --git a/src/bin/psql/input.c b/src/bin/psql/input.c index f2b6e4ed7fa..29f2fa12d30 100644 --- a/src/bin/psql/input.c +++ b/src/bin/psql/input.c @@ -298,7 +298,7 @@ initializeInput(int flags) if (histfile == NULL) { if (get_home_path(home)) - pg_asprintf(&psql_history, "%s/%s", home, PSQLHISTORY); + psql_history = psprintf("%s/%s", home, PSQLHISTORY); } else { diff --git a/src/bin/psql/startup.c b/src/bin/psql/startup.c index a45ec552f42..a9836a59a81 100644 --- a/src/bin/psql/startup.c +++ b/src/bin/psql/startup.c @@ -182,8 +182,8 @@ main(int argc, char *argv[]) if (options.username == NULL) password_prompt = pg_strdup(_("Password: ")); else - pg_asprintf(&password_prompt, _("Password for user %s: "), - options.username); + password_prompt = psprintf(_("Password for user %s: "), + options.username); if (pset.getPassword == TRI_YES) password = simple_prompt(password_prompt, 100, false); @@ -638,8 +638,8 @@ process_psqlrc_file(char *filename) #define R_OK 4 #endif - pg_asprintf(&psqlrc_minor, "%s-%s", filename, PG_VERSION); - pg_asprintf(&psqlrc_major, "%s-%s", filename, PG_MAJORVERSION); + psqlrc_minor = psprintf("%s-%s", filename, PG_VERSION); + psqlrc_major = psprintf("%s-%s", filename, PG_MAJORVERSION); /* check for minor version first, then major, then no version */ if (access(psqlrc_minor, R_OK) == 0) diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c index ae8f8370f95..84d2eb4d420 100644 --- a/src/bin/psql/tab-complete.c +++ b/src/bin/psql/tab-complete.c @@ -3832,8 +3832,6 @@ complete_from_variables(char *text, const char *prefix, const char *suffix) for (ptr = pset.vars->next; ptr; ptr = ptr->next) { - char *buffer; - if (nvars >= maxvars) { maxvars *= 2; @@ -3846,8 +3844,7 @@ complete_from_variables(char *text, const char *prefix, const char *suffix) } } - pg_asprintf(&buffer, "%s%s%s", prefix, ptr->name, suffix); - varnames[nvars++] = buffer; + varnames[nvars++] = psprintf("%s%s%s", prefix, ptr->name, suffix); } varnames[nvars] = NULL; |
