diff options
author | Bruce Momjian <bruce@momjian.us> | 2012-07-26 06:22:06 -0400 |
---|---|---|
committer | Bruce Momjian <bruce@momjian.us> | 2012-07-26 06:22:20 -0400 |
commit | ba98239dcacb276929e5447473dcaa713e643913 (patch) | |
tree | 43cd5e722a3ab00b9b6aff80c581341abe9b78fa /contrib/pg_upgrade/file.c | |
parent | a4a7eb37d4c067f3d8d76338cda1bb33722e50ec (diff) |
Simplify pg_upgrade's handling when returning directory listings.
Backpatch to 9.2.
Diffstat (limited to 'contrib/pg_upgrade/file.c')
-rw-r--r-- | contrib/pg_upgrade/file.c | 25 |
1 files changed, 8 insertions, 17 deletions
diff --git a/contrib/pg_upgrade/file.c b/contrib/pg_upgrade/file.c index 962cbaccc53..550967009b3 100644 --- a/contrib/pg_upgrade/file.c +++ b/contrib/pg_upgrade/file.c @@ -225,23 +225,21 @@ copy_file(const char *srcfile, const char *dstfile, bool force) * load_directory() * * Read all the file names in the specified directory, and return them as - * an array of "struct dirent" pointers. The array address is returned in + * an array of "char *" pointers. The array address is returned in * *namelist, and the function result is the count of file names. * - * To free the result data, free each namelist array member, then free the + * To free the result data, free each (char *) array member, then free the * namelist array itself. */ int -load_directory(const char *dirname, struct dirent *** namelist) +load_directory(const char *dirname, char ***namelist) { DIR *dirdesc; struct dirent *direntry; int count = 0; - int allocsize = 64; - size_t entrysize; + int allocsize = 64; /* initial array size */ - *namelist = (struct dirent **) - pg_malloc(allocsize * sizeof(struct dirent *)); + *namelist = (char **) pg_malloc(allocsize * sizeof(char *)); if ((dirdesc = opendir(dirname)) == NULL) pg_log(PG_FATAL, "could not open directory \"%s\": %s\n", @@ -252,18 +250,11 @@ load_directory(const char *dirname, struct dirent *** namelist) if (count >= allocsize) { allocsize *= 2; - *namelist = (struct dirent **) - pg_realloc(*namelist, allocsize * sizeof(struct dirent *)); + *namelist = (char **) + pg_realloc(*namelist, allocsize * sizeof(char *)); } - entrysize = offsetof(struct dirent, d_name) + - strlen(direntry->d_name) + 1; - - (*namelist)[count] = (struct dirent *) pg_malloc(entrysize); - - memcpy((*namelist)[count], direntry, entrysize); - - count++; + (*namelist)[count++] = pg_strdup(direntry->d_name); } #ifdef WIN32 |