19#ifndef OSLINK_OSDIR_HEADER_H_
20#define OSLINK_OSDIR_HEADER_H_
24#if defined(unix) || defined(__unix) || defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
25#define OSLINK_OSDIR_POSIX
27#define OSLINK_OSDIR_WINDOWS
29#define OSLINK_OSDIR_NOTSUPPORTED
34#if defined(OSLINK_OSDIR_NOTSUPPORTED)
41 directory(
const std::string&) { }
42 operator void*()
const {
return (
void*)0; }
43 std::string next() {
return ""; }
47#elif defined(OSLINK_OSDIR_POSIX)
57 directory(
const std::string& aName)
58 : handle(opendir(aName.c_str())), willfail(false)
64 dirent* entry = readdir(handle);
66 current = entry->d_name;
76 operator void*()
const
78 return willfail ? (
void*)0:(
void*)(-1);
82 std::string prev(current);
83 dirent* entry = readdir(handle);
85 current = entry->d_name;
97#elif defined(OSLINK_OSDIR_WINDOWS)
107 directory(
const std::string& aName)
108 : handle(INVALID_HANDLE_VALUE), willfail(false)
112 DWORD attrs = GetFileAttributes(aName.c_str());
113 if ( (attrs == 0xFFFFFFFF) || ((attrs && FILE_ATTRIBUTE_DIRECTORY) == 0) )
118 std::string Full(aName);
120 if ( (Full.length() > 0) && (Full[Full.length()-1] !=
'\\') )
122 WIN32_FIND_DATA entry;
123 handle = FindFirstFile( (Full+
"*").c_str(), &entry);
124 if (handle == INVALID_HANDLE_VALUE)
127 current = entry.cFileName;
131 if (handle != INVALID_HANDLE_VALUE)
135 operator void*()
const
137 return willfail ? (
void*)0:(
void*)(-1);
141 std::string prev = current;
142 WIN32_FIND_DATA entry;
143 int ok = FindNextFile(handle, &entry);
147 current = entry.cFileName;