1 /*-------------------------------------------------------------------------
4 * directory handling functions
6 * Portions Copyright (c) 1996-2023, 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"
24 #define pg_log_warning(...) elog(WARNING, __VA_ARGS__)
26 #include "common/logging.h"
32 * return a list of the names of objects in the argument directory. Caller
33 * must call pgfnames_cleanup later to free the memory allocated by this
37 pgfnames(const char *path
)
43 int fnsize
= 200; /* enough for many small dbs */
48 pg_log_warning("could not open directory \"%s\": %m", path
);
52 filenames
= (char **) palloc(fnsize
* sizeof(char *));
54 while (errno
= 0, (file
= readdir(dir
)) != NULL
)
56 if (strcmp(file
->d_name
, ".") != 0 && strcmp(file
->d_name
, "..") != 0)
58 if (numnames
+ 1 >= fnsize
)
61 filenames
= (char **) repalloc(filenames
,
62 fnsize
* sizeof(char *));
64 filenames
[numnames
++] = pstrdup(file
->d_name
);
69 pg_log_warning("could not read directory \"%s\": %m", path
);
71 filenames
[numnames
] = NULL
;
74 pg_log_warning("could not close directory \"%s\": %m", path
);
83 * deallocate memory used for filenames
86 pgfnames_cleanup(char **filenames
)
90 for (fn
= filenames
; *fn
; fn
++)