1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
|
/* $Id: ntdir.h 3005 2016-11-06 00:07:37Z bird $ */
/** @file
* MSC + NT opendir, readdir, closedir and friends.
*/
/*
* Copyright (c) 2005-2013 knut st. osmundsen <bird-kBuild-spamx@anduin.net>
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*
* Alternatively, the content of this file may be used under the terms of the
* GPL version 2 or later, or LGPL version 2.1 or later.
*/
#ifndef ___nt_ntdir_h
#define ___nt_ntdir_h
#include "nttypes.h"
#include "ntstat.h"
typedef struct dirent
{
/** Optional stat information.
* Only provided if using birdDirOpenExtraInfo(). */
BirdStat_T d_stat;
/** The record length. */
unsigned __int16 d_reclen;
/** The name length. */
unsigned __int16 d_namlen;
/** The name type. */
unsigned char d_type;
/** The name. */
char d_name[512 - sizeof(BirdStat_T) - 2 - 2 - 1];
} BirdDirEntry_T;
typedef struct direntw
{
/** Optional stat information.
* Only provided if using birdDirOpenExtraInfo(). */
BirdStat_T d_stat;
/** The record length. */
unsigned __int16 d_reclen;
/** The name length (in wchar_t). */
unsigned __int16 d_namlen;
/** The name type. */
unsigned char d_type;
/** The name. */
wchar_t d_name[512 - sizeof(BirdStat_T) - 2 - 2 - 1];
} BirdDirEntryW_T;
#define d_ino d_stat.st_ino;
/** @name d_type values.
* @{ */
#define DT_UNKNOWN 0
#define DT_FIFO 1
#define DT_CHR 2
#define DT_DIR 4
#define DT_BLK 6
#define DT_REG 8
#define DT_LNK 10
#define DT_SOCK 12
#define DT_WHT 14
/** @} */
/** @name BIRDDIR_F_XXX - birdDirOpenFromHandle & BirdDir_T::fFlags
* @{ */
/** birdDirClose should also close pvHandle. */
#define BIRDDIR_F_CLOSE_HANDLE 1U
/** birdDirClose should not close the handle. */
#define BIRDDIR_F_KEEP_HANDLE 0U
/** Provide extra info (stat). */
#define BIRDDIR_F_EXTRA_INFO 2U
/** Whether to restart the scan. */
#define BIRDDIR_F_RESTART_SCAN 4U
/** Set if the BirdDir_T structure is statically allocated. */
#define BIRDDIR_F_STATIC_ALLOC 8U
/** @} */
typedef struct BirdDir
{
/** Magic value. */
unsigned uMagic;
/** Flags. */
unsigned fFlags;
/** The directory handle. */
void *pvHandle;
/** The device number (st_dev). */
unsigned __int64 uDev;
/** The current position. */
long offPos;
/** Set if we haven't yet read anything. */
int fFirst;
/** Set if we have data in the buffer. */
int fHaveData;
/** The info type we're querying. */
int iInfoClass;
/** The current buffer position. */
unsigned offBuf;
/** The number of bytes allocated for pabBuf. */
unsigned cbBuf;
/** Buffer of size cbBuf. */
unsigned char *pabBuf;
/** Static directory entry. */
union
{
BirdDirEntry_T DirEntry;
BirdDirEntryW_T DirEntryW;
} u;
} BirdDir_T;
/** Magic value for BirdDir. */
#define BIRD_DIR_MAGIC 0x19731120
BirdDir_T *birdDirOpen(const char *pszPath);
BirdDir_T *birdDirOpenExtraInfo(const char *pszPath);
BirdDir_T *birdDirOpenExW(void *hRoot, const wchar_t *pwszPath, const wchar_t *pwszFilter, unsigned fFlags);
BirdDir_T *birdDirOpenFromHandle(void *hDir, const void *pvReserved, unsigned fFlags);
BirdDir_T *birdDirOpenFromHandleWithReuse(BirdDir_T *pDir, void *pvHandle, const void *pvReserved, unsigned fFlags);
BirdDirEntry_T *birdDirRead(BirdDir_T *pDir);
BirdDirEntryW_T *birdDirReadW(BirdDir_T *pDir);
long birdDirTell(BirdDir_T *pDir);
void birdDirSeek(BirdDir_T *pDir, long offDir);
int birdDirClose(BirdDir_T *pDir);
#define opendir birdDirOpen
#define readdir birdDirRead
#define telldir birdDirTell
#define seekdir birdDirSeek
#define rewinddir(a_pDir, a_offDir) birdDirSeek(a_pDir, 0)
#define closedir birdDirClose
#define _D_NAMLEN(a_pEnt) ((a_pEnt)->d_namlen)
typedef BirdDir_T DIR;
#endif
|