26 #ifndef _GAZEBO_WIN_DIRENT_H_
27 #define _GAZEBO_WIN_DIRENT_H_
32 #if !defined(_68K_) && !defined(_MPPC_) && !defined(_X86_) && \
33 !defined(_IA64_) && !defined(_AMD64_) && defined(_M_IX86)
36 #if !defined(_68K_) && !defined(_MPPC_) && !defined(_X86_) && \
37 !defined(_IA64_) && !defined(_AMD64_) && defined(_M_AMD64)
50 #include <sys/types.h>
55 #define _DIRENT_HAVE_D_TYPE
58 #define _DIRENT_HAVE_D_NAMLEN
61 #if !defined(FILE_ATTRIBUTE_DEVICE)
62 # define FILE_ATTRIBUTE_DEVICE 0x40
68 # define S_IFMT _S_IFMT
72 # define S_IFDIR _S_IFDIR
76 # define S_IFCHR _S_IFCHR
78 #if !defined(S_IFFIFO)
80 # define S_IFFIFO _S_IFFIFO
84 # define S_IFREG _S_IFREG
88 # define S_IREAD _S_IREAD
90 #if !defined(S_IWRITE)
92 # define S_IWRITE _S_IWRITE
96 # define S_IEXEC _S_IEXEC
100 # define S_IFIFO _S_IFIFO
102 #if !defined(S_IFBLK)
106 #if !defined(S_IFLNK)
110 #if !defined(S_IFSOCK)
115 #if defined(_MSC_VER)
117 # define S_IRUSR S_IREAD
119 # define S_IWUSR S_IWRITE
137 #if !defined(PATH_MAX)
138 # define PATH_MAX MAX_PATH
140 #if !defined(FILENAME_MAX)
141 # define FILENAME_MAX MAX_PATH
143 #if !defined(NAME_MAX)
144 # define NAME_MAX FILENAME_MAX
149 #define DT_REG S_IFREG
150 #define DT_DIR S_IFDIR
151 #define DT_FIFO S_IFIFO
152 #define DT_SOCK S_IFSOCK
153 #define DT_CHR S_IFCHR
154 #define DT_BLK S_IFBLK
155 #define DT_LNK S_IFLNK
158 #define IFTODT(mode) ((mode) & S_IFMT)
159 #define DTTOIF(type) (type)
165 #define S_ISFIFO(mode) (((mode) & S_IFMT) == S_IFIFO)
166 #define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
167 #define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG)
168 #define S_ISLNK(mode) (((mode) & S_IFMT) == S_IFLNK)
169 #define S_ISSOCK(mode) (((mode) & S_IFMT) == S_IFSOCK)
170 #define S_ISCHR(mode) (((mode) & S_IFMT) == S_IFCHR)
171 #define S_ISBLK(mode) (((mode) & S_IFMT) == S_IFBLK)
174 #define _D_EXACT_NAMLEN(p) ((p)->d_namlen)
177 #define _D_ALLOC_NAMLEN(p) (PATH_MAX)
228 # define wdirent _wdirent
230 # define wopendir _wopendir
231 # define wreaddir _wreaddir
232 # define wclosedir _wclosedir
233 # define wrewinddir _wrewinddir
273 size_t *pReturnValue,
280 size_t *pReturnValue,
283 const wchar_t *wcstr,
297 if (dirname ==
NULL || dirname[0] ==
'\0')
304 dirp =
static_cast<_WDIR*
>(malloc(
sizeof(
struct _WDIR)));
310 dirp->
handle = INVALID_HANDLE_VALUE;
315 n = GetFullPathNameW(dirname, 0,
NULL,
NULL);
318 dirp->
patt =
static_cast<wchar_t*
>(malloc(
sizeof(
wchar_t) * n + 16));
324 n = GetFullPathNameW(dirname, n, dirp->
patt,
NULL);
400 WIN32_FIND_DATAW *datap;
417 while (n + 1 <
PATH_MAX && datap->cFileName[n] != 0)
419 entp->
d_name[n] = datap->cFileName[n];
428 attr = datap->dwFileAttributes;
433 else if ((attr & FILE_ATTRIBUTE_DIRECTORY) != 0)
464 if (dirp->
handle != INVALID_HANDLE_VALUE)
467 dirp->
handle = INVALID_HANDLE_VALUE;
501 if (dirp->
handle != INVALID_HANDLE_VALUE)
514 WIN32_FIND_DATAW *datap;
518 if (dirp->
handle != INVALID_HANDLE_VALUE)
545 else if (dirp->
handle != INVALID_HANDLE_VALUE)
548 if (FindNextFileW (dirp->
handle, &dirp->
data) != FALSE)
557 dirp->
handle = INVALID_HANDLE_VALUE;
576 if (dirname ==
NULL || dirname[0] ==
'\0')
583 dirp =
static_cast<DIR*
>(malloc(
sizeof(
struct DIR)));
663 size_t *pReturnValue,
671 # if defined(_MSC_VER) && _MSC_VER >= 1400
673 error = mbstowcs_s(pReturnValue, wcstr, sizeInWords, mbstr, count);
681 n = mbstowcs(wcstr, mbstr, sizeInWords);
682 if (!wcstr || n < count)
685 if (wcstr && sizeInWords)
687 if (n >= sizeInWords)
697 *pReturnValue = n + 1;
714 size_t *pReturnValue,
718 const wchar_t *wcstr,
723 # if defined(_MSC_VER) && _MSC_VER >= 1400
726 error = wcstombs_s(pReturnValue, mbstr, sizeInBytes, wcstr, count);
734 n = wcstombs(mbstr, wcstr, sizeInBytes);
735 if (!mbstr || n < count)
738 if (mbstr && sizeInBytes)
740 if (n >= sizeInBytes)
750 *pReturnValue = n + 1;
769 # if defined(_MSC_VER) && _MSC_VER >= 1400
static struct _wdirent * _wreaddir(_WDIR *dirp)
Definition: win_dirent.h:398
static int dirent_wcstombs_s(size_t *pReturnValue, char *mbstr, size_t sizeInBytes, const wchar_t *wcstr, size_t count)
Definition: win_dirent.h:713
static void rewinddir(DIR *dirp)
Definition: win_dirent.h:655
uint16_t d_reclen
Definition: win_dirent.h:243
int cached
Definition: win_dirent.h:212
int64_t d_ino
Definition: win_dirent.h:240
int d_type
Definition: win_dirent.h:249
#define DT_CHR
Definition: win_dirent.h:153
Definition: win_dirent.h:237
size_t d_namlen
Definition: win_dirent.h:246
static DIR * opendir(const char *dirname)
Definition: win_dirent.h:570
Definition: win_dirent.h:256
struct dirent ent
Definition: win_dirent.h:258
static int closedir(DIR *dirp)
Definition: win_dirent.h:631
wchar_t * patt
Definition: win_dirent.h:218
static WIN32_FIND_DATAW * dirent_first(_WDIR *dirp)
Definition: win_dirent.h:512
int64_t d_ino
Definition: win_dirent.h:187
#define FILE_ATTRIBUTE_DEVICE
Definition: win_dirent.h:62
static void dirent_set_errno(int error)
Definition: win_dirent.h:767
static WIN32_FIND_DATAW * dirent_next(_WDIR *dirp)
Definition: win_dirent.h:534
Definition: win_dirent.h:184
static int _wclosedir(_WDIR *dirp)
Definition: win_dirent.h:458
int d_type
Definition: win_dirent.h:196
#define NULL
Definition: CommonTypes.hh:30
HANDLE handle
Definition: win_dirent.h:215
static void _wrewinddir(_WDIR *dirp)
Definition: win_dirent.h:496
static int dirent_mbstowcs_s(size_t *pReturnValue, wchar_t *wcstr, size_t sizeInWords, const char *mbstr, size_t count)
Definition: win_dirent.h:662
uint16_t d_reclen
Definition: win_dirent.h:190
#define PATH_MAX
Definition: win_dirent.h:138
static _WDIR * _wopendir(const wchar_t *dirname)
Definition: win_dirent.h:291
#define DT_DIR
Definition: win_dirent.h:150
#define DT_REG
Definition: win_dirent.h:149
struct _WDIR * wdirp
Definition: win_dirent.h:259
size_t d_namlen
Definition: win_dirent.h:193
char d_name[MAX_PATH]
Definition: win_dirent.h:252
struct _wdirent ent
Definition: win_dirent.h:206
WIN32_FIND_DATAW data
Definition: win_dirent.h:209
Definition: win_dirent.h:203
wchar_t d_name[MAX_PATH]
Definition: win_dirent.h:199