PostgreSQL Source Code  git master
pgfnames.c File Reference
#include "postgres.h"
#include <dirent.h>
Include dependency graph for pgfnames.c:

Go to the source code of this file.

Macros

#define pg_log_warning(...)   elog(WARNING, __VA_ARGS__)
 

Functions

char ** pgfnames (const char *path)
 
void pgfnames_cleanup (char **filenames)
 

Macro Definition Documentation

◆ pg_log_warning

#define pg_log_warning (   ...)    elog(WARNING, __VA_ARGS__)

Definition at line 24 of file pgfnames.c.

Function Documentation

◆ pgfnames()

char** pgfnames ( const char *  path)

Definition at line 37 of file pgfnames.c.

38 {
39  DIR *dir;
40  struct dirent *file;
41  char **filenames;
42  int numnames = 0;
43  int fnsize = 200; /* enough for many small dbs */
44 
45  dir = opendir(path);
46  if (dir == NULL)
47  {
48  pg_log_warning("could not open directory \"%s\": %m", path);
49  return NULL;
50  }
51 
52  filenames = (char **) palloc(fnsize * sizeof(char *));
53 
54  while (errno = 0, (file = readdir(dir)) != NULL)
55  {
56  if (strcmp(file->d_name, ".") != 0 && strcmp(file->d_name, "..") != 0)
57  {
58  if (numnames + 1 >= fnsize)
59  {
60  fnsize *= 2;
61  filenames = (char **) repalloc(filenames,
62  fnsize * sizeof(char *));
63  }
64  filenames[numnames++] = pstrdup(file->d_name);
65  }
66  }
67 
68  if (errno)
69  pg_log_warning("could not read directory \"%s\": %m", path);
70 
71  filenames[numnames] = NULL;
72 
73  if (closedir(dir))
74  pg_log_warning("could not close directory \"%s\": %m", path);
75 
76  return filenames;
77 }
int closedir(DIR *)
Definition: dirent.c:127
struct dirent * readdir(DIR *)
Definition: dirent.c:78
DIR * opendir(const char *)
Definition: dirent.c:33
char * pstrdup(const char *in)
Definition: mcxt.c:1696
void * repalloc(void *pointer, Size size)
Definition: mcxt.c:1541
void * palloc(Size size)
Definition: mcxt.c:1317
#define pg_log_warning(...)
Definition: pgfnames.c:24
Definition: dirent.c:26
Definition: dirent.h:10
char d_name[MAX_PATH]
Definition: dirent.h:15

References closedir(), dirent::d_name, opendir(), palloc(), pg_log_warning, pstrdup(), readdir(), and repalloc().

Referenced by scan_available_timezones().

◆ pgfnames_cleanup()

void pgfnames_cleanup ( char **  filenames)

Definition at line 86 of file pgfnames.c.

87 {
88  char **fn;
89 
90  for (fn = filenames; *fn; fn++)
91  pfree(*fn);
92 
93  pfree(filenames);
94 }
void pfree(void *pointer)
Definition: mcxt.c:1521
static void * fn(void *arg)
Definition: thread-alloc.c:119

References fn(), and pfree().

Referenced by scan_available_timezones().