1 /*-------------------------------------------------------------------------
4 * directory handling functions
6 * Portions Copyright (c) 1996-2014, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994, Regents of the University of California
10 * src/common/pgfnames.c
12 *-------------------------------------------------------------------------
18 #include "postgres_fe.h"
26 * return a list of the names of objects in the argument directory. Caller
27 * must call pgfnames_cleanup later to free the memory allocated by this
31 pgfnames(const char *path)
37 int fnsize = 200; /* enough for many small dbs */
43 elog(WARNING, "could not open directory \"%s\": %m", path);
45 fprintf(stderr, _("could not open directory \"%s\": %s\n"),
46 path, strerror(errno));
51 filenames = (char **) palloc(fnsize * sizeof(char *));
53 while (errno = 0, (file = readdir(dir)) != NULL)
55 if (strcmp(file->d_name, ".") != 0 && strcmp(file->d_name, "..") != 0)
57 if (numnames + 1 >= fnsize)
60 filenames = (char **) repalloc(filenames,
61 fnsize * sizeof(char *));
63 filenames[numnames++] = pstrdup(file->d_name);
70 elog(WARNING, "could not read directory \"%s\": %m", path);
72 fprintf(stderr, _("could not read directory \"%s\": %s\n"),
73 path, strerror(errno));
77 filenames[numnames] = NULL;
82 elog(WARNING, "could not close directory \"%s\": %m", path);
84 fprintf(stderr, _("could not close directory \"%s\": %s\n"),
85 path, strerror(errno));
96 * deallocate memory used for filenames
99 pgfnames_cleanup(char **filenames)
103 for (fn = filenames; *fn; fn++)