1
0
mirror of https://github.com/postgrespro/pg_probackup.git synced 2026-06-21 01:34:15 +02:00

Add a portable implementation for IsDir().

dirent.d_type is not in POSIX and does not exist at least on Solaris.

git-svn-id: http://pg-rman.googlecode.com/svn/trunk@23 182aca00-e38e-11de-a668-6fd11605f5ce
This commit is contained in:
itagaki.takahiro
2009-12-18 02:44:35 +00:00
parent 8863b7944b
commit bc5717b1e0
+8 -9
View File
@@ -12,9 +12,9 @@
#include <dirent.h>
#include <fcntl.h>
#include <libgen.h>
#include <sys/file.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/file.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
@@ -96,19 +96,18 @@ IsDir(const char *dirpath, const DIR *dir, const struct dirent *ent)
#if defined(DT_DIR)
return ent->d_type == DT_DIR;
#elif defined(_finddata_t)
/* Optimization for VC++ on Windows. */
return (dir->dd_dta.attrib & FILE_ATTRIBUTE_DIRECTORY) != 0;
#elif defined(WIN32)
char path[MAXPGPATH];
DWORD attr;
#else
/* Portable implementation because dirent.d_type is not in POSIX. */
char path[MAXPGPATH];
struct stat st;
/* dirent.d_type does not exists */
strlcpy(path, dirpath, MAXPGPATH);
strlcat(path, "/", MAXPGPATH);
strlcat(path, ent->d_name, MAXPGPATH);
attr = GetFileAttributes(path);
return attr != (DWORD) -1 && (attr & FILE_ATTRIBUTE_DIRECTORY) != 0;
#else
#error IsDir: this platform is not supported.
return stat(path, &st) == 0 && S_ISDIR(st.st_mode);
#endif
}