PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
dirent.c File Reference
#include "postgres.h"
#include <dirent.h>
Include dependency graph for dirent.c:

Go to the source code of this file.

Data Structures

struct  DIR
 

Functions

DIRopendir (const char *dirname)
 
struct direntreaddir (DIR *d)
 
int closedir (DIR *d)
 

Function Documentation

int closedir ( DIR d)

Definition at line 111 of file dirent.c.

References DIR::dirname, free, and DIR::handle.

Referenced by CleanupPriorWALFiles(), close_destination_dir(), CustomizableCleanupPriorWALFiles(), dsm_cleanup_for_mmap(), FindEndOfXLOG(), FreeDesc(), FreeDir(), InitArchiveFmt_Directory(), KillExistingArchiveStatus(), KillExistingXLOG(), pg_check_dir(), pgfnames(), recurse_dir(), search_directory(), verify_directory(), and walkdir().

112 {
113  int ret = 0;
114 
115  if (d->handle != INVALID_HANDLE_VALUE)
116  ret = !FindClose(d->handle);
117  free(d->dirname);
118  free(d);
119 
120  return ret;
121 }
HANDLE handle
Definition: dirent.c:29
char * dirname
Definition: dirent.c:27
#define free(a)
Definition: header.h:65
DIR* opendir ( const char *  dirname)

Definition at line 33 of file dirent.c.

References dirent::d_ino, dirent::d_reclen, DIR::dirname, free, DIR::handle, malloc, and DIR::ret.

Referenced by AllocateDir(), CleanupPriorWALFiles(), CustomizableCleanupPriorWALFiles(), FindEndOfXLOG(), get_destination_dir(), InitArchiveFmt_Directory(), KillExistingArchiveStatus(), KillExistingXLOG(), pg_check_dir(), pgfnames(), recurse_dir(), search_directory(), verify_directory(), and walkdir().

34 {
35  DWORD attr;
36  DIR *d;
37 
38  /* Make sure it is a directory */
39  attr = GetFileAttributes(dirname);
40  if (attr == INVALID_FILE_ATTRIBUTES)
41  {
42  errno = ENOENT;
43  return NULL;
44  }
45  if ((attr & FILE_ATTRIBUTE_DIRECTORY) != FILE_ATTRIBUTE_DIRECTORY)
46  {
47  errno = ENOTDIR;
48  return NULL;
49  }
50 
51  d = malloc(sizeof(DIR));
52  if (!d)
53  {
54  errno = ENOMEM;
55  return NULL;
56  }
57  d->dirname = malloc(strlen(dirname) + 4);
58  if (!d->dirname)
59  {
60  errno = ENOMEM;
61  free(d);
62  return NULL;
63  }
64  strcpy(d->dirname, dirname);
65  if (d->dirname[strlen(d->dirname) - 1] != '/' &&
66  d->dirname[strlen(d->dirname) - 1] != '\\')
67  strcat(d->dirname, "\\"); /* Append backslash if not already there */
68  strcat(d->dirname, "*"); /* Search for entries named anything */
69  d->handle = INVALID_HANDLE_VALUE;
70  d->ret.d_ino = 0; /* no inodes on win32 */
71  d->ret.d_reclen = 0; /* not used on win32 */
72 
73  return d;
74 }
HANDLE handle
Definition: dirent.c:29
unsigned short d_reclen
Definition: dirent.h:12
#define malloc(a)
Definition: header.h:50
Definition: dirent.c:25
char * dirname
Definition: dirent.c:27
long d_ino
Definition: dirent.h:11
struct dirent ret
Definition: dirent.c:28
#define free(a)
Definition: header.h:65
struct dirent* readdir ( DIR d)

Definition at line 77 of file dirent.c.

References _dosmaperr(), dirent::d_name, dirent::d_namlen, DIR::dirname, fd(), DIR::handle, and DIR::ret.

Referenced by CleanupPriorWALFiles(), CustomizableCleanupPriorWALFiles(), FindEndOfXLOG(), FindStreamingStart(), InitArchiveFmt_Directory(), KillExistingArchiveStatus(), KillExistingXLOG(), pg_check_dir(), pgfnames(), ReadDirExtended(), recurse_dir(), search_directory(), and walkdir().

78 {
79  WIN32_FIND_DATA fd;
80 
81  if (d->handle == INVALID_HANDLE_VALUE)
82  {
83  d->handle = FindFirstFile(d->dirname, &fd);
84  if (d->handle == INVALID_HANDLE_VALUE)
85  {
86  errno = ENOENT;
87  return NULL;
88  }
89  }
90  else
91  {
92  if (!FindNextFile(d->handle, &fd))
93  {
94  if (GetLastError() == ERROR_NO_MORE_FILES)
95  {
96  /* No more files, force errno=0 (unlike mingw) */
97  errno = 0;
98  return NULL;
99  }
100  _dosmaperr(GetLastError());
101  return NULL;
102  }
103  }
104  strcpy(d->ret.d_name, fd.cFileName); /* Both strings are MAX_PATH long */
105  d->ret.d_namlen = strlen(d->ret.d_name);
106 
107  return &d->ret;
108 }
HANDLE handle
Definition: dirent.c:29
static int fd(const char *x, int i)
Definition: preproc-init.c:105
unsigned short d_namlen
Definition: dirent.h:13
char * dirname
Definition: dirent.c:27
struct dirent ret
Definition: dirent.c:28
void _dosmaperr(unsigned long)
Definition: win32error.c:171
char d_name[MAX_PATH]
Definition: dirent.h:14