dirent_windows.h File Reference
`#include <stdio.h>`
`#include <stdarg.h>`
`#include <windef.h>`
`#include <winbase.h>`
`#include <wchar.h>`
`#include <string.h>`
`#include <stdlib.h>`
`#include <malloc.h>`
`#include <sys/types.h>`
`#include <sys/stat.h>`
`#include <errno.h>`
Include dependency graph for dirent_windows.h:

Go to the source code of this file.

## Classes

struct | _wdirent
struct | _WDIR
struct | dirent
struct | DIR

## Macros

#define | _DIRENT_HAVE_D_TYPE
#define | _DIRENT_HAVE_D_NAMLEN
#define | FILE_ATTRIBUTE_DEVICE 0x40
#define | S_IFMT _S_IFMT /* File type mask */
#define | S_IFDIR _S_IFDIR /* Directory */
#define | S_IFCHR _S_IFCHR /* Character device */
#define | S_IFFIFO _S_IFFIFO /* Pipe */
#define | S_IFREG _S_IFREG /* Regular file */
#define | S_IREAD _S_IREAD /* Read permission */
#define | S_IWRITE _S_IWRITE /* Write permission */
#define | S_IEXEC _S_IEXEC /* Execute permission */
#define | S_IFIFO _S_IFIFO /* Pipe */
#define | S_IFBLK 0 /* Block device */
#define | S_IFLNK 0 /* Link */
#define | S_IFSOCK 0 /* Socket */
#define | PATH_MAX MAX_PATH
#define | FILENAME_MAX MAX_PATH
#define | NAME_MAX FILENAME_MAX
#define | DT_UNKNOWN 0
#define | DT_REG S_IFREG
#define | DT_DIR S_IFDIR
#define | DT_FIFO S_IFIFO
#define | DT_SOCK S_IFSOCK
#define | DT_CHR S_IFCHR
#define | DT_BLK S_IFBLK
#define | DT_LNK S_IFLNK
#define | IFTODT(mode) ((mode) & S_IFMT)
#define | DTTOIF(type) (type)
#define | S_ISFIFO(mode) (((mode) & S_IFMT) == S_IFIFO)
#define | S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
#define | S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG)
#define | S_ISLNK(mode) (((mode) & S_IFMT) == S_IFLNK)
#define | S_ISSOCK(mode) (((mode) & S_IFMT) == S_IFSOCK)
#define | S_ISCHR(mode) (((mode) & S_IFMT) == S_IFCHR)
#define | S_ISBLK(mode) (((mode) & S_IFMT) == S_IFBLK)
#define | _D_EXACT_NAMLEN(p) ((p)->d_namlen)
#define | _D_ALLOC_NAMLEN(p) (PATH_MAX)
#define | wdirent _wdirent
#define | WDIR _WDIR
#define | wopendir _wopendir
#define | wreaddir _wreaddir
#define | wclosedir _wclosedir
#define | wrewinddir _wrewinddir

## Typedefs

typedef struct _wdirent | _wdirent
typedef struct _WDIR | _WDIR
typedef struct dirent | dirent
typedef struct DIR | DIR

## Functions

static _WDIR * | _wopendir (const wchar_t *dirname)
static struct _wdirent * | _wreaddir (_WDIR *dirp)
static int | _wclosedir (_WDIR *dirp)
static void | _wrewinddir (_WDIR *dirp)
static DIR * | opendir (const char *dirname)
static struct dirent * | readdir (DIR *dirp)
static int | closedir (DIR *dirp)
static void | rewinddir (DIR *dirp)
static WIN32_FIND_DATAW * | dirent_first (_WDIR *dirp)
static WIN32_FIND_DATAW * | dirent_next (_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 void | dirent_set_errno (int error)

## Macro Definition Documentation

## _D_ALLOC_NAMLEN

#define _D_ALLOC_NAMLEN | ( |  | p | ) | (PATH_MAX)

Definition at line 158 of file dirent_windows.h.

## _D_EXACT_NAMLEN

#define _D_EXACT_NAMLEN | ( |  | p | ) | ((p)->d_namlen)

Definition at line 155 of file dirent_windows.h.

## _DIRENT_HAVE_D_NAMLEN

#define _DIRENT_HAVE_D_NAMLEN

Definition at line 58 of file dirent_windows.h.

## _DIRENT_HAVE_D_TYPE

#define _DIRENT_HAVE_D_TYPE

Definition at line 55 of file dirent_windows.h.

## DT_BLK

#define DT_BLK S_IFBLK

Definition at line 133 of file dirent_windows.h.

## DT_CHR

#define DT_CHR S_IFCHR

Definition at line 132 of file dirent_windows.h.

## DT_DIR

#define DT_DIR S_IFDIR

Definition at line 129 of file dirent_windows.h.

## DT_FIFO

#define DT_FIFO S_IFIFO

Definition at line 130 of file dirent_windows.h.

## DT_LNK

#define DT_LNK S_IFLNK

Definition at line 134 of file dirent_windows.h.

## DT_REG

#define DT_REG S_IFREG

Definition at line 128 of file dirent_windows.h.

## DT_SOCK

#define DT_SOCK S_IFSOCK

Definition at line 131 of file dirent_windows.h.

## DT_UNKNOWN

#define DT_UNKNOWN 0

Definition at line 127 of file dirent_windows.h.

## DTTOIF

#define DTTOIF | ( |  | type | ) | (type)

Definition at line 138 of file dirent_windows.h.

## FILE_ATTRIBUTE_DEVICE

#define FILE_ATTRIBUTE_DEVICE 0x40

Definition at line 62 of file dirent_windows.h.

## FILENAME_MAX

#define FILENAME_MAX MAX_PATH

Definition at line 120 of file dirent_windows.h.

## IFTODT

#define IFTODT | ( |  | mode | ) | ((mode) & S_IFMT)

Definition at line 137 of file dirent_windows.h.

## NAME_MAX

#define NAME_MAX FILENAME_MAX

Definition at line 123 of file dirent_windows.h.

## PATH_MAX

#define PATH_MAX MAX_PATH

Definition at line 117 of file dirent_windows.h.

## S_IEXEC

#define S_IEXEC _S_IEXEC /* Execute permission */

Definition at line 88 of file dirent_windows.h.

## S_IFBLK

#define S_IFBLK 0 /* Block device */

Definition at line 94 of file dirent_windows.h.

## S_IFCHR

#define S_IFCHR _S_IFCHR /* Character device */

Definition at line 73 of file dirent_windows.h.

## S_IFDIR

#define S_IFDIR _S_IFDIR /* Directory */

Definition at line 70 of file dirent_windows.h.

## S_IFFIFO

#define S_IFFIFO _S_IFFIFO /* Pipe */

Definition at line 76 of file dirent_windows.h.

## S_IFIFO

#define S_IFIFO _S_IFIFO /* Pipe */

Definition at line 91 of file dirent_windows.h.

## S_IFLNK

#define S_IFLNK 0 /* Link */

Definition at line 97 of file dirent_windows.h.

## S_IFMT

#define S_IFMT _S_IFMT /* File type mask */

Definition at line 67 of file dirent_windows.h.

## S_IFREG

#define S_IFREG _S_IFREG /* Regular file */

Definition at line 79 of file dirent_windows.h.

## S_IFSOCK

#define S_IFSOCK 0 /* Socket */

Definition at line 100 of file dirent_windows.h.

## S_IREAD

#define S_IREAD _S_IREAD /* Read permission */

Definition at line 82 of file dirent_windows.h.

## S_ISBLK

#define S_ISBLK | ( |  | mode | ) | (((mode) & S_IFMT) == S_IFBLK)

Definition at line 152 of file dirent_windows.h.

## S_ISCHR

#define S_ISCHR | ( |  | mode | ) | (((mode) & S_IFMT) == S_IFCHR)

Definition at line 151 of file dirent_windows.h.

## S_ISDIR

#define S_ISDIR | ( |  | mode | ) | (((mode) & S_IFMT) == S_IFDIR)

Definition at line 147 of file dirent_windows.h.

## S_ISFIFO

#define S_ISFIFO | ( |  | mode | ) | (((mode) & S_IFMT) == S_IFIFO)

Definition at line 146 of file dirent_windows.h.

## S_ISLNK

#define S_ISLNK | ( |  | mode | ) | (((mode) & S_IFMT) == S_IFLNK)

Definition at line 149 of file dirent_windows.h.

## S_ISREG

#define S_ISREG | ( |  | mode | ) | (((mode) & S_IFMT) == S_IFREG)

Definition at line 148 of file dirent_windows.h.

## S_ISSOCK

#define S_ISSOCK | ( |  | mode | ) | (((mode) & S_IFMT) == S_IFSOCK)

Definition at line 150 of file dirent_windows.h.

## S_IWRITE

#define S_IWRITE _S_IWRITE /* Write permission */

Definition at line 85 of file dirent_windows.h.

## wclosedir

#define wclosedir _wclosedir

Definition at line 196 of file dirent_windows.h.

## WDIR

#define WDIR _WDIR

Definition at line 193 of file dirent_windows.h.

## wdirent

#define wdirent _wdirent

Definition at line 192 of file dirent_windows.h.

## wopendir

#define wopendir _wopendir

Definition at line 194 of file dirent_windows.h.

## wreaddir

#define wreaddir _wreaddir

Definition at line 195 of file dirent_windows.h.

## wrewinddir

#define wrewinddir _wrewinddir

Definition at line 197 of file dirent_windows.h.

## Typedef Documentation

## _WDIR

typedef struct _WDIR _WDIR

Definition at line 183 of file dirent_windows.h.

## _wdirent

typedef struct _wdirent _wdirent

Definition at line 174 of file dirent_windows.h.

## DIR

typedef struct DIR DIR

Definition at line 214 of file dirent_windows.h.

## dirent

typedef struct dirent dirent

Definition at line 208 of file dirent_windows.h.

## Function Documentation

## _wclosedir()

static int _wclosedir | ( | _WDIR * | dirp | ) |

static

Definition at line 407 of file dirent_windows.h.

{
int ok;
if (dirp) {
/* Release search handle */
if (dirp->handle != INVALID_HANDLE_VALUE) {
FindClose (dirp->handle);
dirp->handle = INVALID_HANDLE_VALUE;
}
/* Release search pattern */
if (dirp->patt) {
free (dirp->patt);
dirp->patt = NULL;
}
/* Release directory structure */
free (dirp);
ok = /*success*/0;
} else {
/* Invalid directory stream */
dirent_set_errno (EBADF);
ok = /*failure*/-1;
}
return ok;
}
dirent_set_errno
static void dirent_set_errno(int error)
Definition dirent_windows.h:817
_WDIR::handle
HANDLE handle
Definition dirent_windows.h:180
_WDIR::patt
wchar_t * patt
Definition dirent_windows.h:181

References dirent_set_errno(), _WDIR::handle, and _WDIR::patt.

Referenced by _wopendir(), and closedir().

## _wopendir()

static _WDIR * _wopendir | ( | const wchar_t * | dirname | ) |

static

Definition at line 248 of file dirent_windows.h.

{
_WDIR *dirp = NULL;
int error;
/* Must have directory name */
if (dirname == NULL || dirname[0] == '\0') {
dirent_set_errno (ENOENT);
return NULL;
}
/* Allocate new _WDIR structure */
dirp = (_WDIR*) malloc (sizeof (struct _WDIR));
if (dirp != NULL) {
DWORD n;
/* Reset _WDIR structure */
dirp->handle = INVALID_HANDLE_VALUE;
dirp->patt = NULL;
dirp->cached = 0;
/* Compute the length of full path plus zero terminator */
n = GetFullPathNameW (dirname, 0, NULL, NULL);
/* Allocate room for absolute directory name and search pattern */
dirp->patt = (wchar_t*) malloc (sizeof (wchar_t) * n + 16);
if (dirp->patt) {
/*
* Convert relative directory name to an absolute one. This
* allows rewinddir() to function correctly even when current
* working directory is changed between opendir() and rewinddir().
*/
n = GetFullPathNameW (dirname, n, dirp->patt, NULL);
if (n > 0) {
wchar_t *p;
/* Append search pattern \* to the directory name */
p = dirp->patt + n;
if (dirp->patt < p) {
switch (p[-1]) {
case '\\':
case '/':
case ':':
/* Directory ends in path separator, e.g. c:\temp\ */
/*NOP*/;
break;
default:
/* Directory name doesn't end in path separator */
*p++ = '\\';
}
}
*p++ = '*';
*p = '\0';
/* Open directory stream and retrieve the first entry */
if (dirent_first (dirp)) {
/* Directory stream opened successfully */
error = 0;
} else {
/* Cannot retrieve first entry */
error = 1;
dirent_set_errno (ENOENT);
}
} else {
/* Cannot retrieve full path name */
dirent_set_errno (ENOENT);
error = 1;
}
} else {
/* Cannot allocate memory for search pattern */
error = 1;
}
} else {
/* Cannot allocate _WDIR structure */
error = 1;
}
/* Clean up in case of error */
if (error && dirp) {
_wclosedir (dirp);
dirp = NULL;
}
return dirp;
}
dirent_first
static WIN32_FIND_DATAW * dirent_first(_WDIR *dirp)
Definition dirent_windows.h:458
_wclosedir
static int _wclosedir(_WDIR *dirp)
Definition dirent_windows.h:407
_WDIR
Definition dirent_windows.h:176
_WDIR::cached
int cached
Definition dirent_windows.h:179

References _wclosedir(), _WDIR::cached, dirent_first(), dirent_set_errno(), _WDIR::handle, and _WDIR::patt.

Referenced by opendir().

## _wreaddir()

static struct _wdirent * _wreaddir | ( | _WDIR * | dirp | ) |

static

Definition at line 347 of file dirent_windows.h.

{
WIN32_FIND_DATAW *datap;
struct _wdirent *entp;
/* Read next directory entry */
datap = dirent_next (dirp);
if (datap) {
size_t n;
DWORD attr;
/* Pointer to directory entry to return */
entp = &dirp->ent;
/*
* Copy file name as wide-character string. If the file name is too
* long to fit in to the destination buffer, then truncate file name
* to PATH_MAX characters and zero-terminate the buffer.
*/
n = 0;
while (n + 1 < PATH_MAX && datap->cFileName[n] != 0) {
entp->d_name[n] = datap->cFileName[n];
n++;
}
dirp->ent.d_name[n] = 0;
/* Length of file name excluding zero terminator */
entp->d_namlen = n;
/* File type */
attr = datap->dwFileAttributes;
if ((attr & FILE_ATTRIBUTE_DEVICE) != 0) {
entp->d_type = DT_CHR;
} else if ((attr & FILE_ATTRIBUTE_DIRECTORY) != 0) {
entp->d_type = DT_DIR;
} else {
entp->d_type = DT_REG;
}
/* Reset dummy fields */
entp->d_ino = 0;
entp->d_reclen = sizeof (struct _wdirent);
} else {
/* Last directory entry read */
entp = NULL;
}
return entp;
}
DT_DIR
#define DT_DIR
Definition dirent_windows.h:129
DT_CHR
#define DT_CHR
Definition dirent_windows.h:132
dirent_next
static WIN32_FIND_DATAW * dirent_next(_WDIR *dirp)
Definition dirent_windows.h:483
DT_REG
#define DT_REG
Definition dirent_windows.h:128
FILE_ATTRIBUTE_DEVICE
#define FILE_ATTRIBUTE_DEVICE
Definition dirent_windows.h:62
PATH_MAX
#define PATH_MAX
Definition dirent_windows.h:117
_WDIR::ent
struct _wdirent ent
Definition dirent_windows.h:177
_wdirent
Definition dirent_windows.h:167
_wdirent::d_namlen
size_t d_namlen
Definition dirent_windows.h:170
_wdirent::d_name
wchar_t d_name[PATH_MAX]
Definition dirent_windows.h:172
_wdirent::d_type
int d_type
Definition dirent_windows.h:171
_wdirent::d_ino
long d_ino
Definition dirent_windows.h:168
_wdirent::d_reclen
unsigned short d_reclen
Definition dirent_windows.h:169

References _wdirent::d_ino, _wdirent::d_name, _wdirent::d_namlen, _wdirent::d_reclen, _wdirent::d_type, dirent_next(), DT_CHR, DT_DIR, DT_REG, _WDIR::ent, FILE_ATTRIBUTE_DEVICE, and PATH_MAX.

## _wrewinddir()

static void _wrewinddir | ( | _WDIR * | dirp | ) |

static

Definition at line 442 of file dirent_windows.h.

{
if (dirp) {
/* Release existing search handle */
if (dirp->handle != INVALID_HANDLE_VALUE) {
FindClose (dirp->handle);
}
/* Open new search handle */
dirent_first (dirp);
}
}

References dirent_first(), and _WDIR::handle.

Referenced by rewinddir().

## closedir()

static int closedir | ( | DIR * | dirp | ) |

static

Definition at line 675 of file dirent_windows.h.

{
int ok;
if (dirp) {
/* Close wide-character directory stream */
ok = _wclosedir (dirp->wdirp);
dirp->wdirp = NULL;
/* Release multi-byte character version */
free (dirp);
} else {
/* Invalid directory stream */
dirent_set_errno (EBADF);
ok = /*failure*/-1;
}
return ok;
}
DIR::wdirp
struct _WDIR * wdirp
Definition dirent_windows.h:212

References _wclosedir(), dirent_set_errno(), and DIR::wdirp.

## dirent_first()

static WIN32_FIND_DATAW * dirent_first | ( | _WDIR * | dirp | ) |

static

Definition at line 458 of file dirent_windows.h.

{
WIN32_FIND_DATAW *datap;
/* Open directory and retrieve the first entry */
dirp->handle = FindFirstFileW (dirp->patt, &dirp->data);
if (dirp->handle != INVALID_HANDLE_VALUE) {
/* a directory entry is now waiting in memory */
datap = &dirp->data;
dirp->cached = 1;
} else {
/* Failed to re-open directory: no directory entry in memory */
dirp->cached = 0;
datap = NULL;
}
return datap;
}
_WDIR::data
WIN32_FIND_DATAW data
Definition dirent_windows.h:178

References _WDIR::cached, _WDIR::data, _WDIR::handle, and _WDIR::patt.

Referenced by _wopendir(), and _wrewinddir().

## dirent_mbstowcs_s()

static int dirent_mbstowcs_s | ( | size_t * | pReturnValue,
|  | wchar_t * | wcstr,
|  | size_t | sizeInWords,
|  | const char * | mbstr,
|  | size_t | count
| ) |  |

static

Definition at line 711 of file dirent_windows.h.

{
int error;
#if defined(_MSC_VER) && _MSC_VER >= 1400
/* Microsoft Visual Studio 2005 or later */
error = mbstowcs_s (pReturnValue, wcstr, sizeInWords, mbstr, count);
#else
/* Older Visual Studio or non-Microsoft compiler */
size_t n;
/* Convert to wide-character string (or count characters) */
n = mbstowcs (wcstr, mbstr, sizeInWords);
if (!wcstr || n < count) {
/* Zero-terminate output buffer */
if (wcstr && sizeInWords) {
if (n >= sizeInWords) {
n = sizeInWords - 1;
}
wcstr[n] = 0;
}
/* Length of resuting multi-byte string WITH zero terminator */
if (pReturnValue) {
*pReturnValue = n + 1;
}
/* Success */
error = 0;
} else {
/* Could not convert string */
error = 1;
}
#endif
return error;
}

Referenced by opendir().

## dirent_next()

static WIN32_FIND_DATAW * dirent_next | ( | _WDIR * | dirp | ) |

static

Definition at line 483 of file dirent_windows.h.

{
WIN32_FIND_DATAW *p;
/* Get next directory entry */
if (dirp->cached != 0) {
/* A valid directory entry already in memory */
p = &dirp->data;
dirp->cached = 0;
} else if (dirp->handle != INVALID_HANDLE_VALUE) {
/* Get the next directory entry from stream */
if (FindNextFileW (dirp->handle, &dirp->data) != FALSE) {
/* Got a file */
p = &dirp->data;
} else {
/* The very last entry has been processed or an error occured */
FindClose (dirp->handle);
dirp->handle = INVALID_HANDLE_VALUE;
p = NULL;
}
} else {
/* End of directory stream reached */
p = NULL;
}
return p;
}

References _WDIR::cached, _WDIR::data, and _WDIR::handle.

Referenced by _wreaddir(), and readdir().

## dirent_set_errno()

static void dirent_set_errno | ( | int | error | ) |

static

Definition at line 817 of file dirent_windows.h.

{
#if defined(_MSC_VER) && _MSC_VER >= 1400
/* Microsoft Visual Studio 2005 and later */
_set_errno (error);
#else
/* Non-Microsoft compiler or older Microsoft compiler */
errno = error;
#endif
}

Referenced by _wclosedir(), _wopendir(), closedir(), and opendir().

## dirent_wcstombs_s()

static int dirent_wcstombs_s | ( | size_t * | pReturnValue,
|  | char * | mbstr,
|  | size_t | sizeInBytes,
|  | const wchar_t * | wcstr,
|  | size_t | count
| ) |  |

static

Definition at line 764 of file dirent_windows.h.

{
int error;
#if defined(_MSC_VER) && _MSC_VER >= 1400
/* Microsoft Visual Studio 2005 or later */
error = wcstombs_s (pReturnValue, mbstr, sizeInBytes, wcstr, count);
#else
/* Older Visual Studio or non-Microsoft compiler */
size_t n;
/* Convert to multi-byte string (or count the number of bytes needed) */
n = wcstombs (mbstr, wcstr, sizeInBytes);
if (!mbstr || n < count) {
/* Zero-terminate output buffer */
if (mbstr && sizeInBytes) {
if (n >= sizeInBytes) {
n = sizeInBytes - 1;
}
mbstr[n] = '\0';
}
/* Lenght of resulting multi-bytes string WITH zero-terminator */
if (pReturnValue) {
*pReturnValue = n + 1;
}
/* Success */
error = 0;
} else {
/* Cannot convert string */
error = 1;
}
#endif
return error;
}

Referenced by readdir().

## opendir()

static DIR * opendir | ( | const char * | dirname | ) |

static

Definition at line 522 of file dirent_windows.h.

{
struct DIR *dirp;
int error;
/* Must have directory name */
if (dirname == NULL || dirname[0] == '\0') {
dirent_set_errno (ENOENT);
return NULL;
}
/* Allocate memory for DIR structure */
dirp = (DIR*) malloc (sizeof (struct DIR));
if (dirp) {
wchar_t wname[PATH_MAX];
size_t n;
/* Convert directory name to wide-character string */
error = dirent_mbstowcs_s (&n, wname, PATH_MAX, dirname, PATH_MAX);
if (!error) {
/* Open directory stream using wide-character name */
dirp->wdirp = _wopendir (wname);
if (dirp->wdirp) {
/* Directory stream opened */
error = 0;
} else {
/* Failed to open directory stream */
error = 1;
}
} else {
/*
* Cannot convert file name to wide-character string. This
* occurs if the string contains invalid multi-byte sequences or
* the output buffer is too small to contain the resulting
* string.
*/
error = 1;
}
} else {
/* Cannot allocate DIR structure */
error = 1;
}
/* Clean up in case of error */
if (error && dirp) {
free (dirp);
dirp = NULL;
}
return dirp;
}
_wopendir
static _WDIR * _wopendir(const wchar_t *dirname)
Definition dirent_windows.h:248
dirent_mbstowcs_s
static int dirent_mbstowcs_s(size_t *pReturnValue, wchar_t *wcstr, size_t sizeInWords, const char *mbstr, size_t count)
Definition dirent_windows.h:711
DIR
Definition dirent_windows.h:210

References _wopendir(), dirent_mbstowcs_s(), dirent_set_errno(), PATH_MAX, and DIR::wdirp.

## readdir()

static struct dirent * readdir | ( | DIR * | dirp | ) |

static

Definition at line 592 of file dirent_windows.h.

{
WIN32_FIND_DATAW *datap;
struct dirent *entp;
/* Read next directory entry */
datap = dirent_next (dirp->wdirp);
if (datap) {
size_t n;
int error;
/* Attempt to convert file name to multi-byte string */
error = dirent_wcstombs_s(
&n, dirp->ent.d_name, PATH_MAX, datap->cFileName, PATH_MAX);
/*
* If the file name cannot be represented by a multi-byte string,
* then attempt to use old 8+3 file name. This allows traditional
* Unix-code to access some file names despite of unicode
* characters, although file names may seem unfamiliar to the user.
*
* Be ware that the code below cannot come up with a short file
* name unless the file system provides one. At least
* VirtualBox shared folders fail to do this.
*/
if (error && datap->cAlternateFileName[0] != '\0') {
error = dirent_wcstombs_s(
&n, dirp->ent.d_name, PATH_MAX,
datap->cAlternateFileName, PATH_MAX);
}
if (!error) {
DWORD attr;
/* Initialize directory entry for return */
entp = &dirp->ent;
/* Length of file name excluding zero terminator */
entp->d_namlen = n - 1;
/* File attributes */
attr = datap->dwFileAttributes;
if ((attr & FILE_ATTRIBUTE_DEVICE) != 0) {
entp->d_type = DT_CHR;
} else if ((attr & FILE_ATTRIBUTE_DIRECTORY) != 0) {
entp->d_type = DT_DIR;
} else {
entp->d_type = DT_REG;
}
/* Reset dummy fields */
entp->d_ino = 0;
entp->d_reclen = sizeof (struct dirent);
} else {
/*
* Cannot convert file name to multi-byte string so construct
* an errornous directory entry and return that. Note that
* we cannot return NULL as that would stop the processing
* of directory entries completely.
*/
entp = &dirp->ent;
entp->d_name[0] = '?';
entp->d_name[1] = '\0';
entp->d_namlen = 1;
entp->d_type = DT_UNKNOWN;
entp->d_ino = 0;
entp->d_reclen = 0;
}
} else {
/* No more directory entries */
entp = NULL;
}
return entp;
}
DT_UNKNOWN
#define DT_UNKNOWN
Definition dirent_windows.h:127
dirent_wcstombs_s
static int dirent_wcstombs_s(size_t *pReturnValue, char *mbstr, size_t sizeInBytes, const wchar_t *wcstr, size_t count)
Definition dirent_windows.h:764
DIR::ent
struct dirent ent
Definition dirent_windows.h:211
dirent
Definition dirent_windows.h:201
dirent::d_namlen
size_t d_namlen
Definition dirent_windows.h:204
dirent::d_name
char d_name[PATH_MAX]
Definition dirent_windows.h:206
dirent::d_reclen
unsigned short d_reclen
Definition dirent_windows.h:203
dirent::d_ino
long d_ino
Definition dirent_windows.h:202
dirent::d_type
int d_type
Definition dirent_windows.h:205

References dirent::d_ino, dirent::d_name, dirent::d_namlen, dirent::d_reclen, dirent::d_type, dirent_next(), dirent_wcstombs_s(), DT_CHR, DT_DIR, DT_REG, DT_UNKNOWN, DIR::ent, FILE_ATTRIBUTE_DEVICE, PATH_MAX, and DIR::wdirp.

## rewinddir()

static void rewinddir | ( | DIR * | dirp | ) |

static

Definition at line 702 of file dirent_windows.h.

{
/* Rewind wide-character string directory stream */
_wrewinddir (dirp->wdirp);
}
_wrewinddir
static void _wrewinddir(_WDIR *dirp)
Definition dirent_windows.h:442

References _wrewinddir(), and DIR::wdirp.