aboutsummaryrefslogtreecommitdiff
path: root/contrib/dbsize/dbsize.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2005-06-19 21:34:03 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2005-06-19 21:34:03 +0000
commit3f749924f82efd5b2f4b424f6c69a89a2959e4b3 (patch)
tree3bd4c6588dc45f0b88f394e0dee85f201f54d4d0 /contrib/dbsize/dbsize.c
parente26b0abda3919448d5ccbcaac0415010022864b7 (diff)
downloadpostgresql-3f749924f82efd5b2f4b424f6c69a89a2959e4b3.tar.gz
postgresql-3f749924f82efd5b2f4b424f6c69a89a2959e4b3.zip
Simplify uses of readdir() by creating a function ReadDir() that
includes error checking and an appropriate ereport(ERROR) message. This gets rid of rather tedious and error-prone manipulation of errno, as well as a Windows-specific bug workaround, at more than a dozen call sites. After an idea in a recent patch by Heikki Linnakangas.
Diffstat (limited to 'contrib/dbsize/dbsize.c')
-rw-r--r--contrib/dbsize/dbsize.c19
1 files changed, 4 insertions, 15 deletions
diff --git a/contrib/dbsize/dbsize.c b/contrib/dbsize/dbsize.c
index afa1937145c..903de97b374 100644
--- a/contrib/dbsize/dbsize.c
+++ b/contrib/dbsize/dbsize.c
@@ -5,7 +5,7 @@
* Copyright (c) 2002-2005, PostgreSQL Global Development Group
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/contrib/dbsize/dbsize.c,v 1.17 2005/05/27 00:57:48 neilc Exp $
+ * $PostgreSQL: pgsql/contrib/dbsize/dbsize.c,v 1.18 2005/06/19 21:34:00 tgl Exp $
*
*/
@@ -58,7 +58,7 @@ db_dir_size(const char *path)
if (!dirdesc)
return 0;
- while ((direntry = readdir(dirdesc)) != NULL)
+ while ((direntry = ReadDir(dirdesc, path)) != NULL)
{
struct stat fst;
@@ -97,13 +97,8 @@ calculate_database_size(Oid dbOid)
/* Scan the non-default tablespaces */
snprintf(pathname, MAXPGPATH, "%s/pg_tblspc", DataDir);
dirdesc = AllocateDir(pathname);
- if (!dirdesc)
- ereport(ERROR,
- (errcode_for_file_access(),
- errmsg("could not open tablespace directory \"%s\": %m",
- pathname)));
- while ((direntry = readdir(dirdesc)) != NULL)
+ while ((direntry = ReadDir(dirdesc, pathname)) != NULL)
{
if (strcmp(direntry->d_name, ".") == 0 ||
strcmp(direntry->d_name, "..") == 0)
@@ -147,13 +142,7 @@ pg_tablespace_size(PG_FUNCTION_ARGS)
dirdesc = AllocateDir(tblspcPath);
- if (!dirdesc)
- ereport(ERROR,
- (errcode_for_file_access(),
- errmsg("could not open tablespace directory \"%s\": %m",
- tblspcPath)));
-
- while ((direntry = readdir(dirdesc)) != NULL)
+ while ((direntry = ReadDir(dirdesc, tblspcPath)) != NULL)
{
struct stat fst;