1616
1717#include < sys/stat.h>
1818
19- #ifdef WIN32
19+ #ifdef _WIN32
2020
2121 #ifndef NOMINMAX
2222 #define NOMINMAX
2727 #include < windows.h>
2828 #include < win_str_convert.h>
2929
30- #else // WIN32
30+ #else // _WIN32
3131
3232#include < cerrno>
3333#include < cstring>
3434#include < dirent.h>
3535
36- #endif // WIN32
36+ #endif // _WIN32
3737
3838// //////////////////////////////////////////////////////////////////////////////
3939// / Filesystem
@@ -48,12 +48,12 @@ namespace Filesystem
4848 : path_(path)
4949 , file_status_{}
5050 {
51- #ifdef WIN32
51+ #ifdef _WIN32
5252 const std::wstring w_path_ = StrConvert::Utf8ToWide (path);
5353 const int error_code = _wstat64 (w_path_.c_str (), &file_status_);
54- #else // WIN32
54+ #else // _WIN32
5555 const int error_code = stat (path.c_str (), &file_status_);
56- #endif // WIN32
56+ #endif // _WIN32
5757 is_ok_ = (error_code == 0 );
5858 }
5959
@@ -71,12 +71,12 @@ namespace Filesystem
7171 case S_IFREG: return FileType::RegularFile;
7272 case S_IFDIR: return FileType::Dir;
7373 case S_IFCHR: return FileType::CharacterDevice;
74- #ifndef WIN32
74+ #ifndef _WIN32
7575 case S_IFBLK: return FileType::BlockDevice;
7676 case S_IFIFO: return FileType::Fifo;
7777 case S_IFLNK: return FileType::SymbolicLink;
7878 case S_IFSOCK: return FileType::Socket;
79- #endif // !WIN32
79+ #endif // !_WIN32
8080 default : return FileType::Unknown;
8181 }
8282
@@ -90,7 +90,7 @@ namespace Filesystem
9090 return file_status_.st_size ;
9191 }
9292
93- #ifdef WIN32
93+ #ifdef _WIN32
9494 bool FileStatus::permissionRootRead () const { return 0 != (file_status_.st_mode & S_IREAD); }
9595 bool FileStatus::permissionRootWrite () const { return 0 != (file_status_.st_mode & S_IWRITE); }
9696 bool FileStatus::permissionRootExecute () const { return 0 != (file_status_.st_mode & S_IEXEC); }
@@ -100,7 +100,7 @@ namespace Filesystem
100100 bool FileStatus::permissionOwnerRead () const { return 0 != (file_status_.st_mode & S_IREAD); }
101101 bool FileStatus::permissionOwnerWrite () const { return 0 != (file_status_.st_mode & S_IWRITE); }
102102 bool FileStatus::permissionOwnerExecute () const { return 0 != (file_status_.st_mode & S_IEXEC); }
103- #else // WIN32
103+ #else // _WIN32
104104 bool FileStatus::permissionRootRead () const { return 0 != (file_status_.st_mode & S_IRUSR); }
105105 bool FileStatus::permissionRootWrite () const { return 0 != (file_status_.st_mode & S_IWUSR); }
106106 bool FileStatus::permissionRootExecute () const { return 0 != (file_status_.st_mode & S_IXUSR); }
@@ -110,7 +110,7 @@ namespace Filesystem
110110 bool FileStatus::permissionOwnerRead () const { return 0 != (file_status_.st_mode & S_IROTH); }
111111 bool FileStatus::permissionOwnerWrite () const { return 0 != (file_status_.st_mode & S_IWOTH); }
112112 bool FileStatus::permissionOwnerExecute () const { return 0 != (file_status_.st_mode & S_IXOTH); }
113- #endif // WIN32
113+ #endif // _WIN32
114114
115115
116116 std::string FileStatus::permissionString () const
@@ -120,7 +120,7 @@ namespace Filesystem
120120 if (!is_ok_)
121121 return permission_string;
122122
123- #ifdef WIN32
123+ #ifdef _WIN32
124124 // Root
125125 permission_string[0 ] = ((file_status_.st_mode & S_IREAD) != 0 ) ? ' r' : ' -' ;
126126 permission_string[1 ] = ((file_status_.st_mode & S_IWRITE) != 0 ) ? ' w' : ' -' ;
@@ -133,7 +133,7 @@ namespace Filesystem
133133 permission_string[6 ] = ((file_status_.st_mode & S_IREAD) != 0 ) ? ' r' : ' -' ;
134134 permission_string[7 ] = ((file_status_.st_mode & S_IWRITE) != 0 ) ? ' w' : ' -' ;
135135 permission_string[8 ] = ((file_status_.st_mode & S_IEXEC) != 0 ) ? ' x' : ' -' ;
136- #else // WIN32
136+ #else // _WIN32
137137 // Root
138138 permission_string[0 ] = ((file_status_.st_mode & S_IRUSR) != 0 ) ? ' r' : ' -' ;
139139 permission_string[1 ] = ((file_status_.st_mode & S_IWUSR) != 0 ) ? ' w' : ' -' ;
@@ -146,7 +146,7 @@ namespace Filesystem
146146 permission_string[6 ] = ((file_status_.st_mode & S_IROTH) != 0 ) ? ' r' : ' -' ;
147147 permission_string[7 ] = ((file_status_.st_mode & S_IWOTH) != 0 ) ? ' w' : ' -' ;
148148 permission_string[8 ] = ((file_status_.st_mode & S_IXOTH) != 0 ) ? ' x' : ' -' ;
149- #endif // WIN32
149+ #endif // _WIN32
150150 return permission_string;
151151 }
152152
@@ -257,7 +257,7 @@ namespace Filesystem
257257 return false ;
258258
259259 bool can_open_dir (false );
260- #ifdef WIN32
260+ #ifdef _WIN32
261261 std::string find_file_path = path_ + " \\ *" ;
262262 std::replace (find_file_path.begin (), find_file_path.end (), ' /' , ' \\ ' );
263263
@@ -271,22 +271,22 @@ namespace Filesystem
271271 can_open_dir = true ;
272272 }
273273 FindClose (hFind);
274- #else // WIN32
274+ #else // _WIN32
275275 DIR *dp = opendir (path_.c_str ());
276276 if (dp != nullptr )
277277 {
278278 can_open_dir = true ;
279279 closedir (dp);
280280 }
281- #endif // WIN32
281+ #endif // _WIN32
282282
283283 return can_open_dir;
284284 }
285285
286286 std::map<std::string, FileStatus> dirContent (const std::string& path, std::ostream& error)
287287 {
288288 std::map<std::string, FileStatus> content;
289- #ifdef WIN32
289+ #ifdef _WIN32
290290 std::string find_file_path = path + " \\ *" ;
291291 std::replace (find_file_path.begin (), find_file_path.end (), ' /' , ' \\ ' );
292292
@@ -307,7 +307,7 @@ namespace Filesystem
307307 content.emplace (file_name, FileStatus (path + " \\ " + file_name));
308308 } while (FindNextFileW (hFind, &ffd) != 0 );
309309 FindClose (hFind);
310- #else // WIN32
310+ #else // _WIN32
311311 DIR *dp = opendir (path.c_str ());
312312 struct dirent *dirp = nullptr ;
313313 if (dp == nullptr )
@@ -322,7 +322,7 @@ namespace Filesystem
322322 }
323323 closedir (dp);
324324
325- #endif // WIN32
325+ #endif // _WIN32
326326 return content;
327327 }
328328
@@ -465,13 +465,13 @@ namespace Filesystem
465465
466466 std::string cleanPathNative (const std::string& path)
467467 {
468- #ifdef WIN32
468+ #ifdef _WIN32
469469 constexpr bool path_is_windows_path = true ;
470470 constexpr char separator = ' \\ ' ;
471- #else // WIN32
471+ #else // _WIN32
472472 constexpr bool path_is_windows_path = false ;
473473 constexpr char separator = ' /' ;
474- #endif // WIN32
474+ #endif // _WIN32
475475 return cleanPath (path, path_is_windows_path, separator);
476476 }
477477
0 commit comments