Changeset View
Changeset View
Standalone View
Standalone View
source/third_party/tinygettext/src/unix_file_system.cpp
Show All 15 Lines | |||||
// 2. Altered source versions must be plainly marked as such, and must not be | // 2. Altered source versions must be plainly marked as such, and must not be | ||||
// misrepresented as being the original software. | // misrepresented as being the original software. | ||||
// 3. This notice may not be removed or altered from any source distribution. | // 3. This notice may not be removed or altered from any source distribution. | ||||
#include "precompiled.h" | #include "precompiled.h" | ||||
#include "tinygettext/unix_file_system.hpp" | #include "tinygettext/unix_file_system.hpp" | ||||
#include <sys/types.h> | #if defined(__APPLE__) && __clang__major__ < 11 | ||||
#include <fstream> | #include <experimental/filesystem> | ||||
#ifdef _MSC_VER | |||||
// MSVC doesn't include dirent.h, so we use this emulated win32 version | |||||
# include "win32/dirent.h" | |||||
#else | #else | ||||
# include <dirent.h> | #include <filesystem> | ||||
#endif | #endif | ||||
#include <fstream> | |||||
#include <stdlib.h> | #include <stdlib.h> | ||||
#include <string.h> | |||||
namespace tinygettext { | namespace tinygettext { | ||||
UnixFileSystem::UnixFileSystem() | UnixFileSystem::UnixFileSystem() | ||||
{ | { | ||||
} | } | ||||
std::vector<std::string> | std::vector<std::string> | ||||
UnixFileSystem::open_directory(const std::string& pathname) | UnixFileSystem::open_directory(const std::string& pathname) | ||||
{ | { | ||||
DIR* dir = opendir(pathname.c_str()); | |||||
if (!dir) | |||||
{ | |||||
// FIXME: error handling | |||||
return std::vector<std::string>(); | |||||
} | |||||
else | |||||
{ | |||||
std::vector<std::string> files; | std::vector<std::string> files; | ||||
for(auto const& p : std::filesystem::directory_iterator(pathname)) | |||||
struct dirent* dp; | |||||
while((dp = readdir(dir)) != 0) | |||||
{ | { | ||||
files.push_back(dp->d_name); | files.push_back(p.path().filename().string()); | ||||
} | } | ||||
closedir(dir); | |||||
return files; | return files; | ||||
} | } | ||||
} | |||||
std::unique_ptr<std::istream> | std::unique_ptr<std::istream> | ||||
UnixFileSystem::open_file(const std::string& filename) | UnixFileSystem::open_file(const std::string& filename) | ||||
{ | { | ||||
return std::unique_ptr<std::istream>(new std::ifstream(filename.c_str())); | return std::unique_ptr<std::istream>(new std::ifstream(filename)); | ||||
} | } | ||||
} // namespace tinygettext | } // namespace tinygettext | ||||
/* EOF */ | /* EOF */ |
Wildfire Games · Phabricator