1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-03 09:13:20 +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

@@ -487,10 +487,9 @@ cfopen_read(const char *path, const char *mode)
#ifdef HAVE_LIBZ
if (fp == NULL)
{
int fnamelen = strlen(path) + 4;
char *fname = pg_malloc(fnamelen);
char *fname;
snprintf(fname, fnamelen, "%s%s", path, ".gz");
pg_asprintf(&fname, "%s.gz", path);
fp = cfopen(fname, mode, 1);
free(fname);
}
@@ -518,10 +517,9 @@ cfopen_write(const char *path, const char *mode, int compression)
else
{
#ifdef HAVE_LIBZ
int fnamelen = strlen(path) + 4;
char *fname = pg_malloc(fnamelen);
char *fname;
snprintf(fname, fnamelen, "%s%s", path, ".gz");
pg_asprintf(&fname, "%s.gz", path);
fp = cfopen(fname, mode, 1);
free(fname);
#else