#include "postgres.h"#include <dirent.h>
Go to the source code of this file.
Data Structures | |
| struct | DIR |
Functions | |
| DIR * | opendir (const char *dirname) |
| struct dirent * | readdir (DIR *d) |
| int | closedir (DIR *d) |
| int closedir | ( | DIR * | d | ) |
Definition at line 112 of file dirent.c.
References DIR::dirname, free, and DIR::handle.
Referenced by CleanupPriorWALFiles(), CustomizableCleanupPriorWALFiles(), FindEndOfXLOG(), FindStreamingStart(), FreeDesc(), FreeDir(), InitArchiveFmt_Directory(), KillExistingArchiveStatus(), KillExistingXLOG(), pg_check_dir(), pgfnames(), verify_directory(), and walkdir().
| 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(), FindStreamingStart(), InitArchiveFmt_Directory(), KillExistingArchiveStatus(), KillExistingXLOG(), pg_check_dir(), pgfnames(), verify_directory(), and walkdir().
{
DWORD attr;
DIR *d;
/* Make sure it is a directory */
attr = GetFileAttributes(dirname);
if (attr == INVALID_FILE_ATTRIBUTES)
{
errno = ENOENT;
return NULL;
}
if ((attr & FILE_ATTRIBUTE_DIRECTORY) != FILE_ATTRIBUTE_DIRECTORY)
{
errno = ENOTDIR;
return NULL;
}
d = malloc(sizeof(DIR));
if (!d)
{
errno = ENOMEM;
return NULL;
}
d->dirname = malloc(strlen(dirname) + 4);
if (!d->dirname)
{
errno = ENOMEM;
free(d);
return NULL;
}
strcpy(d->dirname, dirname);
if (d->dirname[strlen(d->dirname) - 1] != '/' &&
d->dirname[strlen(d->dirname) - 1] != '\\')
strcat(d->dirname, "\\"); /* Append backslash if not already
* there */
strcat(d->dirname, "*"); /* Search for entries named anything */
d->handle = INVALID_HANDLE_VALUE;
d->ret.d_ino = 0; /* no inodes on win32 */
d->ret.d_reclen = 0; /* not used on win32 */
return d;
}
Definition at line 78 of file dirent.c.
References _dosmaperr(), dirent::d_name, dirent::d_namlen, DIR::dirname, DIR::handle, and DIR::ret.
Referenced by CleanupPriorWALFiles(), CustomizableCleanupPriorWALFiles(), FindEndOfXLOG(), FindStreamingStart(), InitArchiveFmt_Directory(), KillExistingArchiveStatus(), KillExistingXLOG(), pg_check_dir(), pgfnames(), ReadDir(), and walkdir().
{
WIN32_FIND_DATA fd;
if (d->handle == INVALID_HANDLE_VALUE)
{
d->handle = FindFirstFile(d->dirname, &fd);
if (d->handle == INVALID_HANDLE_VALUE)
{
errno = ENOENT;
return NULL;
}
}
else
{
if (!FindNextFile(d->handle, &fd))
{
if (GetLastError() == ERROR_NO_MORE_FILES)
{
/* No more files, force errno=0 (unlike mingw) */
errno = 0;
return NULL;
}
_dosmaperr(GetLastError());
return NULL;
}
}
strcpy(d->ret.d_name, fd.cFileName); /* Both strings are MAX_PATH
* long */
d->ret.d_namlen = strlen(d->ret.d_name);
return &d->ret;
}
1.7.1