1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-31 22:04:40 +03:00

Add use of asprintf()

Add asprintf(), pg_asprintf(), and psprintf() to simplify string
allocation and composition.  Replacement implementations taken from
NetBSD.

Reviewed-by: Álvaro Herrera <alvherre@2ndquadrant.com>
Reviewed-by: Asif Naeem <anaeem.it@gmail.com>
This commit is contained in:
Peter Eisentraut
2013-10-13 00:09:18 -04:00
parent a53dee43fe
commit 5b6d08cd29
47 changed files with 253 additions and 363 deletions

View File

@ -455,18 +455,13 @@ create_script_for_cluster_analyze(char **analyze_script_file_name)
FILE *script = NULL;
char *user_specification = "";
if (os_info.user_specified)
{
user_specification = pg_malloc(strlen(os_info.user) + 7);
sprintf(user_specification, "-U \"%s\" ", os_info.user);
}
*analyze_script_file_name = pg_malloc(MAXPGPATH);
prep_status("Creating script to analyze new cluster");
snprintf(*analyze_script_file_name, MAXPGPATH, "analyze_new_cluster.%s",
SCRIPT_EXT);
if (os_info.user_specified)
pg_asprintf(&user_specification, "-U \"%s\" ", os_info.user);
pg_asprintf(analyze_script_file_name, "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",
@ -597,10 +592,8 @@ create_script_for_old_cluster_deletion(char **deletion_script_file_name)
int tblnum;
char old_cluster_pgdata[MAXPGPATH];
*deletion_script_file_name = pg_malloc(MAXPGPATH);
snprintf(*deletion_script_file_name, MAXPGPATH, "delete_old_cluster.%s",
SCRIPT_EXT);
pg_asprintf(deletion_script_file_name, "delete_old_cluster.%s",
SCRIPT_EXT);
/*
* Some users (oddly) create tablespaces inside the cluster data