diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2005-06-19 21:34:03 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2005-06-19 21:34:03 +0000 |
commit | 3f749924f82efd5b2f4b424f6c69a89a2959e4b3 (patch) | |
tree | 3bd4c6588dc45f0b88f394e0dee85f201f54d4d0 /src/backend/utils/adt/misc.c | |
parent | e26b0abda3919448d5ccbcaac0415010022864b7 (diff) | |
download | postgresql-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 'src/backend/utils/adt/misc.c')
-rw-r--r-- | src/backend/utils/adt/misc.c | 12 |
1 files changed, 4 insertions, 8 deletions
diff --git a/src/backend/utils/adt/misc.c b/src/backend/utils/adt/misc.c index 886ff011221..45532539664 100644 --- a/src/backend/utils/adt/misc.c +++ b/src/backend/utils/adt/misc.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/adt/misc.c,v 1.43 2005/05/19 21:35:47 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/utils/adt/misc.c,v 1.44 2005/06/19 21:34:02 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -187,11 +187,10 @@ pg_tablespace_databases(PG_FUNCTION_ARGS) if (!fctx->dirdesc) /* not a tablespace */ SRF_RETURN_DONE(funcctx); - while ((de = readdir(fctx->dirdesc)) != NULL) + while ((de = ReadDir(fctx->dirdesc, fctx->location)) != NULL) { char *subdir; DIR *dirdesc; - Oid datOid = atooid(de->d_name); /* this test skips . and .., but is awfully weak */ @@ -204,16 +203,13 @@ pg_tablespace_databases(PG_FUNCTION_ARGS) subdir = palloc(strlen(fctx->location) + 1 + strlen(de->d_name) + 1); sprintf(subdir, "%s/%s", fctx->location, de->d_name); dirdesc = AllocateDir(subdir); - pfree(subdir); - if (!dirdesc) - continue; /* XXX more sloppiness */ - - while ((de = readdir(dirdesc)) != 0) + while ((de = ReadDir(dirdesc, subdir)) != NULL) { if (strcmp(de->d_name, ".") != 0 && strcmp(de->d_name, "..") != 0) break; } FreeDir(dirdesc); + pfree(subdir); if (!de) continue; /* indeed, nothing in it */ |