Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit f023fc6

Browse files
committed
Use ReadDir() not readdir() so as to have some modicum of error checking.
1 parent 74888b9 commit f023fc6

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

src/backend/utils/adt/dbsize.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/*
22
* dbsize.c
3-
* object size functions
3+
* object size functions
44
*
55
* Copyright (c) 2002-2005, PostgreSQL Global Development Group
66
*
77
* IDENTIFICATION
8-
* $PostgreSQL: pgsql/src/backend/utils/adt/dbsize.c,v 1.2 2005/08/02 14:07:27 tgl Exp $
8+
* $PostgreSQL: pgsql/src/backend/utils/adt/dbsize.c,v 1.3 2005/08/02 15:17:24 tgl Exp $
99
*
1010
*/
1111

@@ -40,7 +40,7 @@ db_dir_size(const char *path)
4040
if (!dirdesc)
4141
return 0;
4242

43-
while ((direntry = readdir(dirdesc)) != NULL)
43+
while ((direntry = ReadDir(dirdesc, path)) != NULL)
4444
{
4545
struct stat fst;
4646

@@ -71,6 +71,7 @@ calculate_database_size(Oid dbOid)
7171
int64 totalsize = 0;
7272
DIR *dirdesc;
7373
struct dirent *direntry;
74+
char dirpath[MAXPGPATH];
7475
char pathname[MAXPGPATH];
7576

7677
/* Shared storage in pg_global is not counted */
@@ -80,15 +81,15 @@ calculate_database_size(Oid dbOid)
8081
totalsize += db_dir_size(pathname);
8182

8283
/* Scan the non-default tablespaces */
83-
snprintf(pathname, MAXPGPATH, "%s/pg_tblspc", DataDir);
84-
dirdesc = AllocateDir(pathname);
84+
snprintf(dirpath, MAXPGPATH, "%s/pg_tblspc", DataDir);
85+
dirdesc = AllocateDir(dirpath);
8586
if (!dirdesc)
8687
ereport(ERROR,
8788
(errcode_for_file_access(),
8889
errmsg("could not open tablespace directory \"%s\": %m",
89-
pathname)));
90+
dirpath)));
9091

91-
while ((direntry = readdir(dirdesc)) != NULL)
92+
while ((direntry = ReadDir(dirdesc, dirpath)) != NULL)
9293
{
9394
if (strcmp(direntry->d_name, ".") == 0 ||
9495
strcmp(direntry->d_name, "..") == 0)
@@ -161,7 +162,7 @@ calculate_tablespace_size(Oid tblspcOid)
161162
errmsg("could not open tablespace directory \"%s\": %m",
162163
tblspcPath)));
163164

164-
while ((direntry = readdir(dirdesc)) != NULL)
165+
while ((direntry = ReadDir(dirdesc, tblspcPath)) != NULL)
165166
{
166167
struct stat fst;
167168

0 commit comments

Comments
 (0)