35#if !defined(_68K_) && !defined(_MPPC_) && !defined(_X86_) && !defined(_IA64_) && !defined(_AMD64_) && defined(_M_IX86)
38#if !defined(_68K_) && !defined(_MPPC_) && !defined(_X86_) && !defined(_IA64_) && !defined(_AMD64_) && defined(_M_AMD64)
55#define _DIRENT_HAVE_D_TYPE
58#define _DIRENT_HAVE_D_NAMLEN
61#if !defined(FILE_ATTRIBUTE_DEVICE)
62 #define FILE_ATTRIBUTE_DEVICE 0x40
67 #define S_IFMT _S_IFMT
70 #define S_IFDIR _S_IFDIR
73 #define S_IFCHR _S_IFCHR
76 #define S_IFFIFO _S_IFFIFO
79 #define S_IFREG _S_IFREG
82 #define S_IREAD _S_IREAD
85 #define S_IWRITE _S_IWRITE
88 #define S_IEXEC _S_IEXEC
91 #define S_IFIFO _S_IFIFO
104 #define S_IRUSR S_IREAD
105 #define S_IWUSR S_IWRITE
116#if !defined(PATH_MAX)
117 #define PATH_MAX MAX_PATH
119#if !defined(FILENAME_MAX)
120 #define FILENAME_MAX MAX_PATH
122#if !defined(NAME_MAX)
123 #define NAME_MAX FILENAME_MAX
128#define DT_REG S_IFREG
129#define DT_DIR S_IFDIR
130#define DT_FIFO S_IFIFO
131#define DT_SOCK S_IFSOCK
132#define DT_CHR S_IFCHR
133#define DT_BLK S_IFBLK
134#define DT_LNK S_IFLNK
137#define IFTODT(mode) ((mode)&S_IFMT)
138#define DTTOIF(type) (type)
146#define S_ISFIFO(mode) (((mode)&S_IFMT) == S_IFIFO)
147#define S_ISDIR(mode) (((mode)&S_IFMT) == S_IFDIR)
148#define S_ISREG(mode) (((mode)&S_IFMT) == S_IFREG)
149#define S_ISLNK(mode) (((mode)&S_IFMT) == S_IFLNK)
150#define S_ISSOCK(mode) (((mode)&S_IFMT) == S_IFSOCK)
151#define S_ISCHR(mode) (((mode)&S_IFMT) == S_IFCHR)
152#define S_ISBLK(mode) (((mode)&S_IFMT) == S_IFBLK)
155#define _D_EXACT_NAMLEN(p) ((p)->d_namlen)
158#define _D_ALLOC_NAMLEN(p) (PATH_MAX)
189#define wdirent _wdirent
191#define wopendir _wopendir
192#define wreaddir _wreaddir
193#define wclosedir _wclosedir
194#define wrewinddir _wrewinddir
221static int dirent_mbstowcs_s(
size_t *pReturnValue,
wchar_t *wcstr,
size_t sizeInWords,
const char *mbstr,
size_t count);
223static int dirent_wcstombs_s(
size_t *pReturnValue,
char *mbstr,
size_t sizeInBytes,
const wchar_t *wcstr,
size_t count);
238 if (dirname == NULL || dirname[0] ==
'\0') {
249 dirp->
handle = INVALID_HANDLE_VALUE;
254 n = GetFullPathNameW(dirname, 0, NULL, NULL);
257 dirp->
patt = (
wchar_t *)malloc(
sizeof(
wchar_t) * n + 16);
264 n = GetFullPathNameW(dirname, n, dirp->
patt, NULL);
270 if (dirp->
patt < p) {
330 WIN32_FIND_DATAW *datap;
348 while (n + 1 <
PATH_MAX && datap->cFileName[n] != 0) {
349 entp->
d_name[n] = datap->cFileName[n];
358 attr = datap->dwFileAttributes;
361 }
else if ((attr & FILE_ATTRIBUTE_DIRECTORY) != 0) {
389 if (dirp->
handle != INVALID_HANDLE_VALUE) {
391 dirp->
handle = INVALID_HANDLE_VALUE;
420 if (dirp->
handle != INVALID_HANDLE_VALUE) { FindClose(dirp->
handle); }
430 WIN32_FIND_DATAW *datap;
434 if (dirp->
handle != INVALID_HANDLE_VALUE) {
458 }
else if (dirp->
handle != INVALID_HANDLE_VALUE) {
460 if (FindNextFileW(dirp->
handle, &dirp->
data) != FALSE) {
466 dirp->
handle = INVALID_HANDLE_VALUE;
487 if (dirname == NULL || dirname[0] ==
'\0') {
493 dirp = (
DIR *)malloc(
sizeof(
struct DIR));
550 WIN32_FIND_DATAW *datap;
584 attr = datap->dwFileAttributes;
587 }
else if ((attr & FILE_ATTRIBUTE_DIRECTORY) != 0) {
653static int dirent_mbstowcs_s(
size_t *pReturnValue,
wchar_t *wcstr,
size_t sizeInWords,
const char *mbstr,
size_t count)
657#if defined(_MSC_VER) && _MSC_VER >= 1400
660 error = mbstowcs_s(pReturnValue, wcstr, sizeInWords, mbstr, count);
668 n = mbstowcs(wcstr, mbstr, sizeInWords);
669 if (!wcstr || n < count) {
671 if (wcstr && sizeInWords) {
672 if (n >= sizeInWords) { n = sizeInWords - 1; }
677 if (pReturnValue) { *pReturnValue = n + 1; }
694 const wchar_t *wcstr,
size_t count)
698#if defined(_MSC_VER) && _MSC_VER >= 1400
701 error = wcstombs_s(pReturnValue, mbstr, sizeInBytes, wcstr, count);
709 n = wcstombs(mbstr, wcstr, sizeInBytes);
710 if (!mbstr || n < count) {
712 if (mbstr && sizeInBytes) {
713 if (n >= sizeInBytes) { n = sizeInBytes - 1; }
718 if (pReturnValue) { *pReturnValue = n + 1; }
736#if defined(_MSC_VER) && _MSC_VER >= 1400
static WIN32_FIND_DATAW * dirent_first(_WDIR *dirp)
static void dirent_set_errno(int error)
static DIR * opendir(const char *dirname)
static int closedir(DIR *dirp)
static void rewinddir(DIR *dirp)
static WIN32_FIND_DATAW * dirent_next(_WDIR *dirp)
static _WDIR * _wopendir(const wchar_t *dirname)
#define FILE_ATTRIBUTE_DEVICE
static void _wrewinddir(_WDIR *dirp)
static int _wclosedir(_WDIR *dirp)
static struct _wdirent * _wreaddir(_WDIR *dirp)
static int dirent_mbstowcs_s(size_t *pReturnValue, wchar_t *wcstr, size_t sizeInWords, const char *mbstr, size_t count)
static int dirent_wcstombs_s(size_t *pReturnValue, char *mbstr, size_t sizeInBytes, const wchar_t *wcstr, size_t count)
static struct dirent * readdir(DIR *dirp)