Added wrapper implementation for opendir/readdir Other functions left stubbed out. It's a shame that crawl's "direct.h" conflicts with <direct.h>. Fixed up use of AppHdr.h in a couple places (it must be included first); changed project to use precompiled headers.
crawl now compiles cleanly but doesn't link.
git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@3573 c06c8d41-db1a-0410-9941-cceddc491573
L3DRKFURVDCV3EJKGG6GVVQX3D5MZPICTVOKNOD3LGM2PECBA7PQC
YED35BDFAUH7W5Q4YCXV4442GO6LYMWQ2YUPO2UYKG4M55Q2ALIQC
7RTFGPCYOVRGK72Z3MLJDAETJ3SJTQZ4XRJ5336OGAEBHEFCDXLQC
SAQ4HUMGLUR62UMG6Q5X36VPCBSTIAQRQAV6FUX4DYMWBMOPK65QC
AXAM3TX4CUCIPL6ILEJLGJ4D4SMCJYDXGLIB256PBQXXKBIKZ4QAC
DKRSOHZXL6EPSLKOKHF7GJXSZEJVY7CXGACSHWLM5B5FTRETWWCAC
7NDXS36TE7QVXTXJWMYSVG5UHCCLPIO4VL6NXFGTDK3ZNKE3A2IAC
ESWIM76FGJL4QFLSHU6AC4D74PT7OPLQ7ZCJYWLZS5UCBAJDXYHAC
77H4BWWPPGLM3PLZH4QTAJRXIZTSDVNCOKZE223I437FN2UJ34RQC
XRZPPYWPWUOM4SFNI6BHKH2UKJQNLKOV6Y7XIEPEZXE5QYRT26PAC
IIN7AVA6JYRBXH6ZYRR7BY7TV6PW7ANAQ2A3PD55FKBKKQFEEF2AC
25CH7HH4LKXFIZ75YNMXS3TSXO6O27DYSOPLOD45K4OCNFWLS4LQC
3PY3L3A4QRW3Z5Y7SHO4TMVOOP2VNCO27X2MX4DTOP2SADLBQUOAC
K2CS6TCX2NDVL2ASEHGP4J4K4IJ6FP3ANNKTSIWVG43HPYSBX6ZQC
7KWDC7XFNMBLSUO2HISIROBINZBX5T67LJEEXTAORXW2YZ7VWFGAC
DK362IHKSDADMUPD35NOTKM4WESQM37KG2PNOJRV2FGELDWULYPQC
RPOZZWKG5GLPHVZZ7ZKMKS64ZMV2LDCQSARBJFJ6FZOTOKCQO7FAC
KFULGQQOHWUTXOM3BXCCYPGGVGGY4Z6265XUFRCBPNLTZAEHJZSQC
WOCMC6GT5BURRQW66YQ4ZQ53URFXPUZ3TCLYDAM7FLAGKS5VNNFAC
UB73UGG2GEG6AL4T76UILFLTELH4Z5WN54UROLJD6RDR3JG77CXAC
NEECVIIAOBP72T6O44DWAA6HFSDY3KSWYCFMKAEMDMVOI7XASD7QC
GCIZIUXO5TYROKDUYB3HAY7H7MRDTJNM7HR7DGSH7KXDIZC2LCDAC
5V47S4NNTHWTSAHV3YLO2VGH7JTUIYJ3GBPDN5ZM4UQALT2ZEXDQC
SDLKLUNFGVKDS55DDJZCBAVIB7NL3RRYPTACAY65SCUQKV6APFSAC
OTHTO2GQ6S7DWMZ5BT7CB2OEK54XLL4NMH4G4DNCHEBGGCY6Y2XQC
RBAGQ2PB7V5YAM5KSHSZR2E3MLKDSRVM5XYGI2TIXP5QMVBOQHDQC
CCMBDS5S4KEI4LJTVBFDDEGWRTWM4GQB2GLEUUT7TMQRXFLZ4HXQC
UZ6N6HOUPGVSPC5NQROEEDWMEGJA5XUWUY2AKH5QG65AZ25PVXDAC
// struct vs class XXX: fix these some day!
#pragma warning( disable : 4099 )
// truncating conversions XXX: fix these too!
#pragma warning( disable : 4244 )
// ----------------------------------------------------------------------
// dirent.h replacement
// ----------------------------------------------------------------------
#define DT_DIR 4
#define DT_REG 8
struct DIR;
struct dirent
{
// ino_t d_ino;
unsigned short d_reclen;
unsigned char d_type;
unsigned short d_namlen;
char d_name[255];
};
DIR* opendir(const char* path);
dirent* readdir(DIR*);
int closedir(DIR*);
int ftruncate(int fp, int size);
#endif /* defined(_MSC_VER) */
#if _MSC_VER
struct DIR
{
public:
DIR()
: hFind(INVALID_HANDLE_VALUE),
wfd_valid(false)
{
memset(&wfd, 0, sizeof(wfd));
memset(&entry, 0, sizeof(entry));
}
~DIR()
{
if (hFind != INVALID_HANDLE_VALUE)
{
FindClose(hFind);
}
}
bool init(const char* szFind)
{
// Check that it's a directory, first
{
const DWORD dwAttr = GetFileAttributes(szFind);
if (dwAttr == INVALID_FILE_ATTRIBUTES)
return false;
if ((dwAttr & FILE_ATTRIBUTE_DIRECTORY) == 0)
return false;
}
find = szFind;
find += "\\*";
hFind = FindFirstFileA(find.c_str(), &wfd);
wfd_valid = (hFind != INVALID_HANDLE_VALUE);
return true;
}
dirent* readdir()
{
if (! wfd_valid) return 0;
_convert_wfd_to_dirent();
wfd_valid = (bool) FindNextFileA(hFind, &wfd);
return &entry;
}
private:
void _convert_wfd_to_dirent()
{
entry.d_reclen = sizeof(dirent);
entry.d_namlen = strlen(entry.d_name);
entry.d_type = (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
? DT_DIR : DT_REG;
strncpy(entry.d_name, wfd.cFileName, sizeof(entry.d_name));
entry.d_name[sizeof(entry.d_name)-1] = 0;
}
private:
HANDLE hFind;
bool wfd_valid;
WIN32_FIND_DATA wfd;
std::string find;
dirent entry;
// since opendir calls FindFirstFile, we need a means of telling the
// first call to readdir that we already have a file.
// that's the case iff this is == 0; we use a counter rather than a
// flag because that allows keeping statistics.
int num_entries_scanned;
};
DIR* opendir(char* path)
{
DIR* d = new DIR();
if (d->init(path))
{
return d;
}
else
{
delete d;
return 0;
}
}
dirent* readdir(DIR* d)
{
return d->readdir();
}
int closedir(DIR* d)
{
delete d;
return 0;
}
int ftruncate(int fp, int size)
{
ASSERT(false); // unimplemented
return 0;
}
#endif /* #if _MSC_VER */