Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbc5717b

Browse files
author
itagaki.takahiro
committed
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
1 parent8863b79 commitbc5717b

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

‎catalog.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
#include<dirent.h>
1313
#include<fcntl.h>
1414
#include<libgen.h>
15+
#include<sys/file.h>
1516
#include<sys/stat.h>
1617
#include<sys/types.h>
17-
#include<sys/file.h>
1818
#include<stdlib.h>
1919
#include<time.h>
2020
#include<unistd.h>
@@ -96,19 +96,18 @@ IsDir(const char *dirpath, const DIR *dir, const struct dirent *ent)
9696
#if defined(DT_DIR)
9797
returnent->d_type==DT_DIR;
9898
#elif defined(_finddata_t)
99+
/* Optimization for VC++ on Windows. */
99100
return (dir->dd_dta.attrib&FILE_ATTRIBUTE_DIRECTORY)!=0;
100-
#elif defined(WIN32)
101-
charpath[MAXPGPATH];
102-
DWORDattr;
101+
#else
102+
/* Portable implementation because dirent.d_type is not in POSIX. */
103+
charpath[MAXPGPATH];
104+
structstatst;
103105

104-
/* dirent.d_type does not exists */
105106
strlcpy(path,dirpath,MAXPGPATH);
106107
strlcat(path,"/",MAXPGPATH);
107108
strlcat(path,ent->d_name,MAXPGPATH);
108-
attr=GetFileAttributes(path);
109-
returnattr!= (DWORD)-1&& (attr&FILE_ATTRIBUTE_DIRECTORY)!=0;
110-
#else
111-
#error IsDir: this platform is not supported.
109+
110+
returnstat(path,&st)==0&&S_ISDIR(st.st_mode);
112111
#endif
113112
}
114113

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp