/*****************************************************************************
 * $LastChangedDate: 2010-01-24 16:20:06 -0500 (Sun, 24 Jan 2010) $
 * @file
 * @author  Jim E. Brooks  http://www.palomino3d.org
 * @brief   Emulates POSIX directory readin functions: opendir(), readdir(), etc in Win32.
 * @remarks Directory stream type.
 *          The miscellaneous Unix readdir implementations read directory data
 *          into a buffer and return "struct dirent *" pointers into it.
 *//*
 * LEGAL:   COPYRIGHT (C) 2007 JIM E. BROOKS
 *          THIS SOURCE CODE IS RELEASED UNDER THE TERMS
 *          OF THE GNU GENERAL PUBLIC LICENSE VERSION 2 (GPL 2).
 *------------------------------------------------------------------------------
 * Copyright (C) 2001, 2006 Free Software Foundation, Inc.
 * GNU Lesser General Public License 2.1.
 *****************************************************************************/

#ifdef OS_WINDOWS
#ifndef BASE_DIRENT_HH
#define BASE_DIRENT_HH

#include <sys/types.h>
#include <windows.h>
#include <direct.h>

namespace base {

struct dirstream
{
    int     fd;         /* File descriptor.  */
    char*   data;       /* Directory block.  */
    size_t  allocation; /* Space allocated for the block.  */
    size_t  size;       /* Total valid data in the block.  */
    size_t  offset;     /* Current offset into the block.  */
    off_t   filepos;    /* Position of next entry to read.  */
    char*   mask;       /* Initial file mask. */
};

struct dirent
{
  long                  d_ino;
  off_t                 d_off;
  unsigned short int    d_reclen;
  unsigned char         d_type;
  char                  d_name[256];
};

#define d_fileno d_ino /* backwards compatibility */

/* This is the data type of directory stream objects.
   The actual structure is opaque to users.  */

typedef struct dirstream DIR;

DIR * opendir (const char * name);
struct dirent * readdir (DIR * dir);
int closedir (DIR * dir);
void rewinddir (DIR * dir);
void seekdir (DIR * dir, off_t offset);
off_t telldir (DIR * dir);
int dirfd (DIR * dir);

} // namespace base

#endif // BASE_DIRENT_HH
#endif // OS_WINDOWS
