Classes | Macros | Typedefs | Functions
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 DIRopendir (const char *dirname)
 
static struct direntreaddir (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.

409 {
410  int ok;
411  if (dirp) {
412 
413  /* Release search handle */
414  if (dirp->handle != INVALID_HANDLE_VALUE) {
415  FindClose (dirp->handle);
416  dirp->handle = INVALID_HANDLE_VALUE;
417  }
418 
419  /* Release search pattern */
420  if (dirp->patt) {
421  free (dirp->patt);
422  dirp->patt = NULL;
423  }
424 
425  /* Release directory structure */
426  free (dirp);
427  ok = /*success*/0;
428 
429  } else {
430  /* Invalid directory stream */
431  dirent_set_errno (EBADF);
432  ok = /*failure*/-1;
433  }
434  return ok;
435 }

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.

250 {
251  _WDIR *dirp = NULL;
252  int error;
253 
254  /* Must have directory name */
255  if (dirname == NULL || dirname[0] == '\0') {
256  dirent_set_errno (ENOENT);
257  return NULL;
258  }
259 
260  /* Allocate new _WDIR structure */
261  dirp = (_WDIR*) malloc (sizeof (struct _WDIR));
262  if (dirp != NULL) {
263  DWORD n;
264 
265  /* Reset _WDIR structure */
266  dirp->handle = INVALID_HANDLE_VALUE;
267  dirp->patt = NULL;
268  dirp->cached = 0;
269 
270  /* Compute the length of full path plus zero terminator */
271  n = GetFullPathNameW (dirname, 0, NULL, NULL);
272 
273  /* Allocate room for absolute directory name and search pattern */
274  dirp->patt = (wchar_t*) malloc (sizeof (wchar_t) * n + 16);
275  if (dirp->patt) {
276 
277  /*
278  * Convert relative directory name to an absolute one. This
279  * allows rewinddir() to function correctly even when current
280  * working directory is changed between opendir() and rewinddir().
281  */
282  n = GetFullPathNameW (dirname, n, dirp->patt, NULL);
283  if (n > 0) {
284  wchar_t *p;
285 
286  /* Append search pattern \* to the directory name */
287  p = dirp->patt + n;
288  if (dirp->patt < p) {
289  switch (p[-1]) {
290  case '\\':
291  case '/':
292  case ':':
293  /* Directory ends in path separator, e.g. c:\temp\ */
294  /*NOP*/;
295  break;
296 
297  default:
298  /* Directory name doesn't end in path separator */
299  *p++ = '\\';
300  }
301  }
302  *p++ = '*';
303  *p = '\0';
304 
305  /* Open directory stream and retrieve the first entry */
306  if (dirent_first (dirp)) {
307  /* Directory stream opened successfully */
308  error = 0;
309  } else {
310  /* Cannot retrieve first entry */
311  error = 1;
312  dirent_set_errno (ENOENT);
313  }
314 
315  } else {
316  /* Cannot retrieve full path name */
317  dirent_set_errno (ENOENT);
318  error = 1;
319  }
320 
321  } else {
322  /* Cannot allocate memory for search pattern */
323  error = 1;
324  }
325 
326  } else {
327  /* Cannot allocate _WDIR structure */
328  error = 1;
329  }
330 
331  /* Clean up in case of error */
332  if (error && dirp) {
333  _wclosedir (dirp);
334  dirp = NULL;
335  }
336 
337  return dirp;
338 }

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.

349 {
350  WIN32_FIND_DATAW *datap;
351  struct _wdirent *entp;
352 
353  /* Read next directory entry */
354  datap = dirent_next (dirp);
355  if (datap) {
356  size_t n;
357  DWORD attr;
358 
359  /* Pointer to directory entry to return */
360  entp = &dirp->ent;
361 
362  /*
363  * Copy file name as wide-character string. If the file name is too
364  * long to fit in to the destination buffer, then truncate file name
365  * to PATH_MAX characters and zero-terminate the buffer.
366  */
367  n = 0;
368  while (n + 1 < PATH_MAX && datap->cFileName[n] != 0) {
369  entp->d_name[n] = datap->cFileName[n];
370  n++;
371  }
372  dirp->ent.d_name[n] = 0;
373 
374  /* Length of file name excluding zero terminator */
375  entp->d_namlen = n;
376 
377  /* File type */
378  attr = datap->dwFileAttributes;
379  if ((attr & FILE_ATTRIBUTE_DEVICE) != 0) {
380  entp->d_type = DT_CHR;
381  } else if ((attr & FILE_ATTRIBUTE_DIRECTORY) != 0) {
382  entp->d_type = DT_DIR;
383  } else {
384  entp->d_type = DT_REG;
385  }
386 
387  /* Reset dummy fields */
388  entp->d_ino = 0;
389  entp->d_reclen = sizeof (struct _wdirent);
390 
391  } else {
392 
393  /* Last directory entry read */
394  entp = NULL;
395 
396  }
397 
398  return entp;
399 }

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.

444 {
445  if (dirp) {
446  /* Release existing search handle */
447  if (dirp->handle != INVALID_HANDLE_VALUE) {
448  FindClose (dirp->handle);
449  }
450 
451  /* Open new search handle */
452  dirent_first (dirp);
453  }
454 }

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.

677 {
678  int ok;
679  if (dirp) {
680 
681  /* Close wide-character directory stream */
682  ok = _wclosedir (dirp->wdirp);
683  dirp->wdirp = NULL;
684 
685  /* Release multi-byte character version */
686  free (dirp);
687 
688  } else {
689 
690  /* Invalid directory stream */
691  dirent_set_errno (EBADF);
692  ok = /*failure*/-1;
693 
694  }
695  return ok;
696 }

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.

460 {
461  WIN32_FIND_DATAW *datap;
462 
463  /* Open directory and retrieve the first entry */
464  dirp->handle = FindFirstFileW (dirp->patt, &dirp->data);
465  if (dirp->handle != INVALID_HANDLE_VALUE) {
466 
467  /* a directory entry is now waiting in memory */
468  datap = &dirp->data;
469  dirp->cached = 1;
470 
471  } else {
472 
473  /* Failed to re-open directory: no directory entry in memory */
474  dirp->cached = 0;
475  datap = NULL;
476 
477  }
478  return datap;
479 }

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.

717 {
718  int error;
719 
720 #if defined(_MSC_VER) && _MSC_VER >= 1400
721 
722  /* Microsoft Visual Studio 2005 or later */
723  error = mbstowcs_s (pReturnValue, wcstr, sizeInWords, mbstr, count);
724 
725 #else
726 
727  /* Older Visual Studio or non-Microsoft compiler */
728  size_t n;
729 
730  /* Convert to wide-character string (or count characters) */
731  n = mbstowcs (wcstr, mbstr, sizeInWords);
732  if (!wcstr || n < count) {
733 
734  /* Zero-terminate output buffer */
735  if (wcstr && sizeInWords) {
736  if (n >= sizeInWords) {
737  n = sizeInWords - 1;
738  }
739  wcstr[n] = 0;
740  }
741 
742  /* Length of resuting multi-byte string WITH zero terminator */
743  if (pReturnValue) {
744  *pReturnValue = n + 1;
745  }
746 
747  /* Success */
748  error = 0;
749 
750  } else {
751 
752  /* Could not convert string */
753  error = 1;
754 
755  }
756 
757 #endif
758 
759  return error;
760 }

Referenced by opendir().

◆ dirent_next()

static WIN32_FIND_DATAW * dirent_next ( _WDIR dirp)
static

Definition at line 483 of file dirent_windows.h.

485 {
486  WIN32_FIND_DATAW *p;
487 
488  /* Get next directory entry */
489  if (dirp->cached != 0) {
490 
491  /* A valid directory entry already in memory */
492  p = &dirp->data;
493  dirp->cached = 0;
494 
495  } else if (dirp->handle != INVALID_HANDLE_VALUE) {
496 
497  /* Get the next directory entry from stream */
498  if (FindNextFileW (dirp->handle, &dirp->data) != FALSE) {
499  /* Got a file */
500  p = &dirp->data;
501  } else {
502  /* The very last entry has been processed or an error occured */
503  FindClose (dirp->handle);
504  dirp->handle = INVALID_HANDLE_VALUE;
505  p = NULL;
506  }
507 
508  } else {
509 
510  /* End of directory stream reached */
511  p = NULL;
512 
513  }
514 
515  return p;
516 }

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.

819 {
820 #if defined(_MSC_VER) && _MSC_VER >= 1400
821 
822  /* Microsoft Visual Studio 2005 and later */
823  _set_errno (error);
824 
825 #else
826 
827  /* Non-Microsoft compiler or older Microsoft compiler */
828  errno = error;
829 
830 #endif
831 }

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.

770 {
771  int error;
772 
773 #if defined(_MSC_VER) && _MSC_VER >= 1400
774 
775  /* Microsoft Visual Studio 2005 or later */
776  error = wcstombs_s (pReturnValue, mbstr, sizeInBytes, wcstr, count);
777 
778 #else
779 
780  /* Older Visual Studio or non-Microsoft compiler */
781  size_t n;
782 
783  /* Convert to multi-byte string (or count the number of bytes needed) */
784  n = wcstombs (mbstr, wcstr, sizeInBytes);
785  if (!mbstr || n < count) {
786 
787  /* Zero-terminate output buffer */
788  if (mbstr && sizeInBytes) {
789  if (n >= sizeInBytes) {
790  n = sizeInBytes - 1;
791  }
792  mbstr[n] = '\0';
793  }
794 
795  /* Lenght of resulting multi-bytes string WITH zero-terminator */
796  if (pReturnValue) {
797  *pReturnValue = n + 1;
798  }
799 
800  /* Success */
801  error = 0;
802 
803  } else {
804 
805  /* Cannot convert string */
806  error = 1;
807 
808  }
809 
810 #endif
811 
812  return error;
813 }

Referenced by readdir().

◆ opendir()

static DIR * opendir ( const char *  dirname)
static

Definition at line 522 of file dirent_windows.h.

524 {
525  struct DIR *dirp;
526  int error;
527 
528  /* Must have directory name */
529  if (dirname == NULL || dirname[0] == '\0') {
530  dirent_set_errno (ENOENT);
531  return NULL;
532  }
533 
534  /* Allocate memory for DIR structure */
535  dirp = (DIR*) malloc (sizeof (struct DIR));
536  if (dirp) {
537  wchar_t wname[PATH_MAX];
538  size_t n;
539 
540  /* Convert directory name to wide-character string */
541  error = dirent_mbstowcs_s (&n, wname, PATH_MAX, dirname, PATH_MAX);
542  if (!error) {
543 
544  /* Open directory stream using wide-character name */
545  dirp->wdirp = _wopendir (wname);
546  if (dirp->wdirp) {
547  /* Directory stream opened */
548  error = 0;
549  } else {
550  /* Failed to open directory stream */
551  error = 1;
552  }
553 
554  } else {
555  /*
556  * Cannot convert file name to wide-character string. This
557  * occurs if the string contains invalid multi-byte sequences or
558  * the output buffer is too small to contain the resulting
559  * string.
560  */
561  error = 1;
562  }
563 
564  } else {
565  /* Cannot allocate DIR structure */
566  error = 1;
567  }
568 
569  /* Clean up in case of error */
570  if (error && dirp) {
571  free (dirp);
572  dirp = NULL;
573  }
574 
575  return dirp;
576 }

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.

594 {
595  WIN32_FIND_DATAW *datap;
596  struct dirent *entp;
597 
598  /* Read next directory entry */
599  datap = dirent_next (dirp->wdirp);
600  if (datap) {
601  size_t n;
602  int error;
603 
604  /* Attempt to convert file name to multi-byte string */
605  error = dirent_wcstombs_s(
606  &n, dirp->ent.d_name, PATH_MAX, datap->cFileName, PATH_MAX);
607 
608  /*
609  * If the file name cannot be represented by a multi-byte string,
610  * then attempt to use old 8+3 file name. This allows traditional
611  * Unix-code to access some file names despite of unicode
612  * characters, although file names may seem unfamiliar to the user.
613  *
614  * Be ware that the code below cannot come up with a short file
615  * name unless the file system provides one. At least
616  * VirtualBox shared folders fail to do this.
617  */
618  if (error && datap->cAlternateFileName[0] != '\0') {
619  error = dirent_wcstombs_s(
620  &n, dirp->ent.d_name, PATH_MAX,
621  datap->cAlternateFileName, PATH_MAX);
622  }
623 
624  if (!error) {
625  DWORD attr;
626 
627  /* Initialize directory entry for return */
628  entp = &dirp->ent;
629 
630  /* Length of file name excluding zero terminator */
631  entp->d_namlen = n - 1;
632 
633  /* File attributes */
634  attr = datap->dwFileAttributes;
635  if ((attr & FILE_ATTRIBUTE_DEVICE) != 0) {
636  entp->d_type = DT_CHR;
637  } else if ((attr & FILE_ATTRIBUTE_DIRECTORY) != 0) {
638  entp->d_type = DT_DIR;
639  } else {
640  entp->d_type = DT_REG;
641  }
642 
643  /* Reset dummy fields */
644  entp->d_ino = 0;
645  entp->d_reclen = sizeof (struct dirent);
646 
647  } else {
648  /*
649  * Cannot convert file name to multi-byte string so construct
650  * an errornous directory entry and return that. Note that
651  * we cannot return NULL as that would stop the processing
652  * of directory entries completely.
653  */
654  entp = &dirp->ent;
655  entp->d_name[0] = '?';
656  entp->d_name[1] = '\0';
657  entp->d_namlen = 1;
658  entp->d_type = DT_UNKNOWN;
659  entp->d_ino = 0;
660  entp->d_reclen = 0;
661  }
662 
663  } else {
664  /* No more directory entries */
665  entp = NULL;
666  }
667 
668  return entp;
669 }

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.

704 {
705  /* Rewind wide-character string directory stream */
706  _wrewinddir (dirp->wdirp);
707 }

References _wrewinddir(), and DIR::wdirp.

_wdirent::d_namlen
size_t d_namlen
Definition: dirent_windows.h:170
_wdirent::d_ino
long d_ino
Definition: dirent_windows.h:168
DIR::ent
struct dirent ent
Definition: dirent_windows.h:211
_WDIR
Definition: dirent_windows.h:176
_wrewinddir
static void _wrewinddir(_WDIR *dirp)
Definition: dirent_windows.h:442
FILE_ATTRIBUTE_DEVICE
#define FILE_ATTRIBUTE_DEVICE
Definition: dirent_windows.h:62
DIR::wdirp
struct _WDIR * wdirp
Definition: dirent_windows.h:212
PATH_MAX
#define PATH_MAX
Definition: dirent_windows.h:117
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
DT_DIR
#define DT_DIR
Definition: dirent_windows.h:129
_WDIR::handle
HANDLE handle
Definition: dirent_windows.h:180
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
DT_REG
#define DT_REG
Definition: dirent_windows.h:128
dirent::d_reclen
unsigned short d_reclen
Definition: dirent_windows.h:203
_WDIR::cached
int cached
Definition: dirent_windows.h:179
_wdirent
Definition: dirent_windows.h:167
dirent
Definition: dirent_windows.h:201
_wopendir
static _WDIR * _wopendir(const wchar_t *dirname)
Definition: dirent_windows.h:248
_wdirent::d_reclen
unsigned short d_reclen
Definition: dirent_windows.h:169
_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
DT_UNKNOWN
#define DT_UNKNOWN
Definition: dirent_windows.h:127
dirent::d_ino
long d_ino
Definition: dirent_windows.h:202
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_next
static WIN32_FIND_DATAW * dirent_next(_WDIR *dirp)
Definition: dirent_windows.h:483
_WDIR::patt
wchar_t * patt
Definition: dirent_windows.h:181
DT_CHR
#define DT_CHR
Definition: dirent_windows.h:132
DIR
Definition: dirent_windows.h:210
dirent_set_errno
static void dirent_set_errno(int error)
Definition: dirent_windows.h:817
dirent::d_type
int d_type
Definition: dirent_windows.h:205
_WDIR::ent
struct _wdirent ent
Definition: dirent_windows.h:177
_wclosedir
static int _wclosedir(_WDIR *dirp)
Definition: dirent_windows.h:407
_WDIR::data
WIN32_FIND_DATAW data
Definition: dirent_windows.h:178
dirent_first
static WIN32_FIND_DATAW * dirent_first(_WDIR *dirp)
Definition: dirent_windows.h:458

Generated on Wed Apr 29 2020 19:41:30 for QuickFIX by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2001