summaryrefslogtreecommitdiff
path: root/src/backend/commands/tablespace.c
diff options
context:
space:
mode:
authorPeter Eisentraut <peter_e@gmx.net>2013-10-13 00:09:18 -0400
committerPeter Eisentraut <peter_e@gmx.net>2013-10-13 00:09:18 -0400
commit5b6d08cd2992922b667564a49f19580f11676050 (patch)
tree4104a4255eeb88e78da71477b5f7b129f9a1b599 /src/backend/commands/tablespace.c
parenta53dee43fe585e673658b01e7354892dcede957e (diff)
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>
Diffstat (limited to 'src/backend/commands/tablespace.c')
-rw-r--r--src/backend/commands/tablespace.c16
1 files changed, 6 insertions, 10 deletions
diff --git a/src/backend/commands/tablespace.c b/src/backend/commands/tablespace.c
index 155eb7c2481..ddc8ec759fc 100644
--- a/src/backend/commands/tablespace.c
+++ b/src/backend/commands/tablespace.c
@@ -541,12 +541,11 @@ DropTableSpace(DropTableSpaceStmt *stmt)
static void
create_tablespace_directories(const char *location, const Oid tablespaceoid)
{
- char *linkloc = palloc(OIDCHARS + OIDCHARS + 1);
- char *location_with_version_dir = palloc(strlen(location) + 1 +
- strlen(TABLESPACE_VERSION_DIRECTORY) + 1);
+ char *linkloc;
+ char *location_with_version_dir;
- sprintf(linkloc, "pg_tblspc/%u", tablespaceoid);
- sprintf(location_with_version_dir, "%s/%s", location,
+ linkloc = psprintf("pg_tblspc/%u", tablespaceoid);
+ location_with_version_dir = psprintf("%s/%s", location,
TABLESPACE_VERSION_DIRECTORY);
/*
@@ -652,9 +651,7 @@ destroy_tablespace_directories(Oid tablespaceoid, bool redo)
char *subfile;
struct stat st;
- linkloc_with_version_dir = palloc(9 + 1 + OIDCHARS + 1 +
- strlen(TABLESPACE_VERSION_DIRECTORY));
- sprintf(linkloc_with_version_dir, "pg_tblspc/%u/%s", tablespaceoid,
+ linkloc_with_version_dir = psprintf("pg_tblspc/%u/%s", tablespaceoid,
TABLESPACE_VERSION_DIRECTORY);
/*
@@ -711,8 +708,7 @@ destroy_tablespace_directories(Oid tablespaceoid, bool redo)
strcmp(de->d_name, "..") == 0)
continue;
- subfile = palloc(strlen(linkloc_with_version_dir) + 1 + strlen(de->d_name) + 1);
- sprintf(subfile, "%s/%s", linkloc_with_version_dir, de->d_name);
+ subfile = psprintf("%s/%s", linkloc_with_version_dir, de->d_name);
/* This check is just to deliver a friendlier error message */
if (!redo && !directory_is_empty(subfile))