From bac02200267495741e85db90607186ce4e0593b3 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Wed, 29 Jun 2016 21:17:43 +0300 Subject: Port to MSVC --- butl/filesystem.cxx | 40 ++++++++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 8 deletions(-) (limited to 'butl/filesystem.cxx') diff --git a/butl/filesystem.cxx b/butl/filesystem.cxx index c3d21cd..0ff0e28 100644 --- a/butl/filesystem.cxx +++ b/butl/filesystem.cxx @@ -5,34 +5,45 @@ #include #ifndef _WIN32 -# include // struct dirent, *dir() -# include // symlink(), link() +# include // struct dirent, *dir() +# include // symlink(), link(), stat(), rmdir(), unlink() +# include // stat +# include // stat(), lstat(), S_IS*, mkdir() #else # include -# include // _find*() -# include // _mkdir() +# include // _find*(), _unlink() +# include // _mkdir(), _rmdir() +# include // _stat +# include // _stat(), S_IF* # include #endif -#include // errno, E* -#include // stat, rmdir(), unlink() -#include // stat -#include // stat(), lstat(), S_IS*, mkdir() +#include // errno, E* #include // unique_ptr #include using namespace std; +#ifdef _MSC_VER // Unlikely to be fixed in newer versions. +# define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) +# define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) +#endif + namespace butl { bool dir_exists (const path& p) { +#ifndef _WIN32 struct stat s; if (stat (p.string ().c_str (), &s) != 0) +#else + struct _stat s; + if (_stat (p.string ().c_str (), &s) != 0) +#endif { if (errno == ENOENT || errno == ENOTDIR) return false; @@ -46,8 +57,13 @@ namespace butl bool file_exists (const path& p) { +#ifndef _WIN32 struct stat s; if (stat (p.string ().c_str (), &s) != 0) +#else + struct _stat s; + if (_stat (p.string ().c_str (), &s) != 0) +#endif { if (errno == ENOENT || errno == ENOTDIR) return false; @@ -102,7 +118,11 @@ namespace butl { rmdir_status r (rmdir_status::success); +#ifndef _WIN32 if (rmdir (p.string ().c_str ()) != 0) +#else + if (_rmdir (p.string ().c_str ()) != 0) +#endif { if (errno == ENOENT) r = rmdir_status::not_exist; @@ -146,7 +166,11 @@ namespace butl { rmfile_status r (rmfile_status::success); +#ifndef _WIN32 if (unlink (p.string ().c_str ()) != 0) +#else + if (_unlink (p.string ().c_str ()) != 0) +#endif { if (errno == ENOENT || errno == ENOTDIR) r = rmfile_status::not_exist; -- cgit v1.1