free(comma_filenodes);
/* now build the query */
- pg_asprintf(&todo,
+ todo = psprintf(
"SELECT pg_catalog.pg_relation_filenode(c.oid) as \"Filenode\", relname as \"Table Name\" %s\n"
"FROM pg_catalog.pg_class c \n"
" LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace \n"
prep_status("Creating script to analyze new cluster");
if (os_info.user_specified)
- pg_asprintf(&user_specification, "-U \"%s\" ", os_info.user);
+ user_specification = psprintf("-U \"%s\" ", os_info.user);
- pg_asprintf(analyze_script_file_name, "analyze_new_cluster.%s",
- SCRIPT_EXT);
+ *analyze_script_file_name = psprintf("analyze_new_cluster.%s", SCRIPT_EXT);
if ((script = fopen_priv(*analyze_script_file_name, "w")) == NULL)
pg_fatal("Could not open file \"%s\": %s\n",
int tblnum;
char old_cluster_pgdata[MAXPGPATH];
- pg_asprintf(deletion_script_file_name, "delete_old_cluster.%s",
- SCRIPT_EXT);
+ *deletion_script_file_name = psprintf("delete_old_cluster.%s", SCRIPT_EXT);
/*
* Some users (oddly) create tablespaces inside the cluster data
/* This cluster has a version-specific subdirectory */
/* The leading slash is needed to start a new directory. */
- pg_asprintf(&cluster->tablespace_suffix, "/PG_%s_%d",
- cluster->major_version_str, cluster->controldata.cat_ver);
+ cluster->tablespace_suffix = psprintf("/PG_%s_%d",
+ cluster->major_version_str,
+ cluster->controldata.cat_ver);
}
}
#ifndef WIN32
char *envstr;
- pg_asprintf(&envstr, "%s=%s", var, val);
+ envstr = psprintf("%s=%s", var, val);
putenv(envstr);
/*
bool typemod_given, bool allow_invalid,
bool force_qualify);
static char *printTypmod(const char *typname, int32 typmod, Oid typmodout);
-static char *
-psnprintf(size_t len, const char *fmt,...)
-/* This lets gcc check the format string for consistency. */
-__attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3)));
/*
}
if (is_array)
- buf = psnprintf(strlen(buf) + 3, "%s[]", buf);
+ buf = psprintf("%s[]", buf);
ReleaseSysCache(tuple);
if (typmodout == InvalidOid)
{
/* Default behavior: just print the integer typmod with parens */
- res = psnprintf(strlen(typname) + MAX_INT32_LEN + 3, "%s(%d)",
- typname, (int) typmod);
+ res = psprintf("%s(%d)", typname, (int) typmod);
}
else
{
tmstr = DatumGetCString(OidFunctionCall1(typmodout,
Int32GetDatum(typmod)));
- res = psnprintf(strlen(typname) + strlen(tmstr) + 1, "%s%s",
- typname, tmstr);
+ res = psprintf("%s%s", typname, tmstr);
}
return res;
PG_RETURN_TEXT_P(cstring_to_text(result));
}
-
-
-/* snprintf into a palloc'd string */
-static char *
-psnprintf(size_t len, const char *fmt,...)
-{
- va_list ap;
- char *buf;
-
- buf = palloc(len);
-
- va_start(ap, fmt);
- vsnprintf(buf, len, fmt, ap);
- va_end(ap);
-
- return buf;
-}
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);
static void
set_input(char **dest, char *filename)
{
- pg_asprintf(dest, "%s/%s", share_path, filename);
+ *dest = psprintf("%s/%s", share_path, filename);
}
/*
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)
{
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)
{
* 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);
}
}
/* 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)
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);
/*
* 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':
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;
{
char *fname;
- pg_asprintf(&fname, "%s.gz", path);
+ fname = psprintf("%s.gz", path);
fp = cfopen(fname, mode, 1);
free(fname);
}
#ifdef HAVE_LIBZ
char *fname;
- pg_asprintf(&fname, "%s.gz", path);
+ fname = psprintf("%s.gz", path);
fp = cfopen(fname, mode, 1);
free(fname);
#else
/* 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;
}
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,
/* 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;
{
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);
}
*/
#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);
/* 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);
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);
{
char *newfn;
- pg_asprintf(&newfn, "%s%s", home, p);
+ newfn = psprintf("%s%s", home, p);
free(fn);
*filename = newfn;
}
{
char *newvar;
- pg_asprintf(&newvar, "%s%s", *var, more);
+ newvar = psprintf("%s%s", *var, more);
free(*var);
*var = newvar;
}
if (histfile == NULL)
{
if (get_home_path(home))
- pg_asprintf(&psql_history, "%s/%s", home, PSQLHISTORY);
+ psql_history = psprintf("%s/%s", home, PSQLHISTORY);
}
else
{
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);
#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)
for (ptr = pset.vars->next; ptr; ptr = ptr->next)
{
- char *buffer;
-
if (nvars >= maxvars)
{
maxvars *= 2;
}
}
- 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;
return len * 2;
}
-
-
-/*
- * XXX this is going away shortly.
- */
-#ifdef FRONTEND
-int
-pg_asprintf(char **ret, const char *fmt, ...)
-{
- size_t len = 128; /* initial assumption about buffer size */
-
- for (;;)
- {
- char *result;
- va_list args;
-
- /*
- * Allocate result buffer. Note that in frontend this maps to malloc
- * with exit-on-error.
- */
- result = (char *) palloc(len);
-
- /* Try to format the data. */
- va_start(args, fmt);
- len = pvsnprintf(result, len, fmt, args);
- va_end(args);
-
- if (len == 0)
- {
- *ret = result;
- return 0;
- }
-
- /* Release buffer and loop around to try again with larger len. */
- pfree(result);
- }
-}
-#endif
extern void *pg_malloc0(size_t size);
extern void *pg_realloc(void *pointer, size_t size);
extern void pg_free(void *pointer);
-extern int pg_asprintf(char **ret, const char *format, ...) __attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3)));
#include "utils/palloc.h"
{
char *prefix;
- pg_asprintf(&prefix, "%s %s", step1->name, step2->name);
+ prefix = psprintf("%s %s", step1->name, step2->name);
if (step1->errormsg)
{
PG_DIAG_MESSAGE_PRIMARY);
if (sev && msg)
- pg_asprintf(&step->errormsg, "%s: %s", sev, msg);
+ step->errormsg = psprintf("%s: %s", sev, msg);
else
step->errormsg = pg_strdup(PQresultErrorMessage(res));
}
{
char *s;
- pg_asprintf(&s, "%s=%s", var, val);
+ s = psprintf("%s=%s", var, val);
putenv(s);
}
char *newval;
if (!oldval || !oldval[0])
+ {
/* no previous value */
- pg_asprintf(&newval, "%s=%s", pathname, addval);
+ newval = psprintf("%s=%s", pathname, addval);
+ }
else
- pg_asprintf(&newval, "%s=%s%c%s", pathname, addval, separator, oldval);
+ newval = psprintf("%s=%s%c%s", pathname, addval, separator, oldval);
putenv(newval);
}
static void
initialize_environment(void)
{
- char *tmp;
-
putenv("PGAPPNAME=pg_regress");
if (nolocale)
if (!old_pgoptions)
old_pgoptions = "";
- pg_asprintf(&new_pgoptions, "PGOPTIONS=%s %s", old_pgoptions, my_pgoptions);
+ new_pgoptions = psprintf("PGOPTIONS=%s %s",
+ old_pgoptions, my_pgoptions);
putenv(new_pgoptions);
}
/*
* Adjust path variables to point into the temp-install tree
*/
- pg_asprintf(&tmp, "%s/install/%s", temp_install, bindir);
- bindir = tmp;
+ bindir = psprintf("%s/install/%s", temp_install, bindir);
- pg_asprintf(&tmp, "%s/install/%s", temp_install, libdir);
- libdir = tmp;
+ libdir = psprintf("%s/install/%s", temp_install, libdir);
- pg_asprintf(&tmp, "%s/install/%s", temp_install, datadir);
- datadir = tmp;
+ datadir = psprintf("%s/install/%s", temp_install, datadir);
/* psql will be installed into temp-install bindir */
psqldir = bindir;
*/
char *cmdline2;
- pg_asprintf(&cmdline2, "exec %s", cmdline);
+ cmdline2 = psprintf("exec %s", cmdline);
execl(shellprog, shellprog, "-c", cmdline2, (char *) NULL);
fprintf(stderr, _("%s: could not exec \"%s\": %s\n"),
progname, shellprog, strerror(errno));
exit(2);
}
- pg_asprintf(&cmdline2, "cmd /c %s", cmdline);
+ cmdline2 = psprintf("cmd /c %s", cmdline);
#ifndef __CYGWIN__
AddUserToTokenDacl(restrictedToken);
}
}
- pg_asprintf(&result, "%s/%s", cwdbuf, in);
+ result = psprintf("%s/%s", cwdbuf, in);
}
canonicalize_path(result);