1#ifndef OSLINK_OSDIR_HEADER_H_
2#define OSLINK_OSDIR_HEADER_H_
4#if defined(unix) || defined(__unix) || defined(__unix__)
5#define OSLINK_OSDIR_POSIX
7#define OSLINK_OSDIR_WINDOWS
9#define OSLINK_OSDIR_NOTSUPPORTED
14#if defined(OSLINK_OSDIR_NOTSUPPORTED)
22 operator void*()
const {
return (
void*)0; }
23 std::string
next() {
return ""; }
27#elif defined(OSLINK_OSDIR_POSIX)
38 : handle(opendir(aName.c_str())), willfail(false)
44 dirent* entry = readdir(handle);
46 current = entry->d_name;
56 operator void*()
const
58 return willfail ? (
void*)0:(void*)(-1);
62 std::string prev(current);
63 dirent* entry = readdir(handle);
65 current = entry->d_name;
77#elif defined(OSLINK_OSDIR_WINDOWS)
88 : handle(INVALID_HANDLE_VALUE), willfail(false)
92 DWORD attrs = GetFileAttributes(aName.c_str());
93 if ( (attrs == 0xFFFFFFFF) || ((attrs && FILE_ATTRIBUTE_DIRECTORY) == 0) )
98 std::string Full(aName);
100 if ( (Full.length() > 0) && (Full[Full.length()-1] !=
'\\') )
102 WIN32_FIND_DATA entry;
103 handle = FindFirstFile( (Full+
"*").c_str(), &entry);
104 if (handle == INVALID_HANDLE_VALUE)
107 current = entry.cFileName;
111 if (handle != INVALID_HANDLE_VALUE)
115 operator void*()
const
117 return willfail ? (
void*)0:(void*)(-1);
121 std::string prev = current;
122 WIN32_FIND_DATA entry;
123 int ok = FindNextFile(handle, &entry);
127 current = entry.cFileName;
directory(const std::string &)