72{
76 char **filenames = NULL;
77 int size_filenames;
78
79 /*
80 * Reject directory name that is all-blank (including empty), as that
81 * leads to confusion --- we'd read the containing directory, typically
82 * resulting in recursive inclusion of the same file(s).
83 */
84 if (strspn(includedir, " \t\r\n") == strlen(includedir))
85 {
87 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
88 errmsg(
"empty configuration directory name: \"%s\"",
89 includedir)));
90 *err_msg = "empty configuration directory name";
91 return NULL;
92 }
93
96 if (d == NULL)
97 {
100 errmsg(
"could not open configuration directory \"%s\": %m",
104 }
105
106 /*
107 * Read the directory and put the filenames in an array, so we can sort
108 * them prior to caller processing the contents.
109 */
110 size_filenames = 32;
111 filenames = (
char **)
palloc(size_filenames *
sizeof(
char *));
112 *num_filenames = 0;
113
115 {
118
119 /*
120 * Only parse files with names ending in ".conf". Explicitly reject
121 * files starting with ".". This excludes things like "." and "..",
122 * as well as typical hidden files, backup files, and editor debris.
123 */
124 if (strlen(de->
d_name) < 6)
125 continue;
127 continue;
128 if (strcmp(de->
d_name + strlen(de->
d_name) - 5,
".conf") != 0)
129 continue;
130
135 {
138 filenames = NULL;
140 }
142 {
143 /* Add file to array, increasing its size in blocks of 32 */
144 if (*num_filenames >= size_filenames)
145 {
146 size_filenames += 32;
147 filenames = (
char **)
repalloc(filenames,
148 size_filenames * sizeof(char *));
149 }
151 (*num_filenames)++;
152 }
153 }
154
155 /* Sort the files by name before leaving */
156 if (*num_filenames > 0)
158
160 if (d)
163 return filenames;
164}
static void cleanup(void)
char * AbsoluteConfigLocation(const char *location, const char *calling_file)
int errcode_for_file_access(void)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
DIR * AllocateDir(const char *dirname)
struct dirent * ReadDir(DIR *dir, const char *dirname)
PGFileType get_dirent_type(const char *path, const struct dirent *de, bool look_through_symlinks, int elevel)
void * repalloc(void *pointer, Size size)
void pfree(void *pointer)
int pg_qsort_strcmp(const void *a, const void *b)
#define qsort(a, b, c, d)
char * psprintf(const char *fmt,...)
static const char * directory