Skip to content

Commit a746b32

Browse files
Replaced preprocessor macro WIN32 by _WIN32 (#85)
The underscore version of the preprocessor macro is the safer option to use
1 parent 4648cb0 commit a746b32

File tree

9 files changed

+105
-105
lines changed

9 files changed

+105
-105
lines changed

fineftp-server/src/filesystem.cpp

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
#include <sys/stat.h>
1818

19-
#ifdef WIN32
19+
#ifdef _WIN32
2020

2121
#ifndef NOMINMAX
2222
#define NOMINMAX
@@ -27,13 +27,13 @@
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

fineftp-server/src/filesystem.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ namespace fineftp
6262
private:
6363
std::string path_;
6464
bool is_ok_;
65-
#ifdef WIN32
65+
#ifdef _WIN32
6666
struct __stat64 file_status_;
67-
#else // WIN32
67+
#else // _WIN32
6868
struct stat file_status_;
6969
#endif
7070
};

fineftp-server/src/ftp_session.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
#include <sys/stat.h>
3131

32-
#ifdef WIN32
32+
#ifdef _WIN32
3333
#define WIN32_LEAN_AND_MEAN
3434
#ifndef NOMINMAX
3535
#define NOMINMAX
@@ -38,7 +38,7 @@
3838
#include "win_str_convert.h"
3939
#else
4040
#include <unistd.h>
41-
#endif // WIN32
41+
#endif // _WIN32
4242

4343

4444
namespace fineftp
@@ -535,7 +535,7 @@ namespace fineftp
535535

536536
const std::string local_path = toLocalPath(param);
537537

538-
#if defined(WIN32) && !defined(__GNUG__)
538+
#if defined(_WIN32) && !defined(__GNUG__)
539539
const auto file = ReadableFile::get(StrConvert::Utf8ToWide(local_path));
540540
#else
541541
const auto file = ReadableFile::get(local_path);
@@ -572,7 +572,7 @@ namespace fineftp
572572
std::ios::ate | (data_type_binary_ ? (std::ios::in | std::ios::binary) : (std::ios::in));
573573
std::fstream::pos_type file_size;
574574
{
575-
#if defined(WIN32) && !defined(__GNUG__)
575+
#if defined(_WIN32) && !defined(__GNUG__)
576576
std::ifstream file(StrConvert::Utf8ToWide(local_path), open_mode);
577577
#else
578578
std::ifstream file(local_path, open_mode);
@@ -648,11 +648,11 @@ namespace fineftp
648648

649649
if (!file->good())
650650
{
651-
#ifdef WIN32
651+
#ifdef _WIN32
652652
sendFtpMessage(FtpReplyCode::ACTION_ABORTED_LOCAL_ERROR, "Error opening file for transfer: " + GetLastErrorStr());
653653
#else
654654
sendFtpMessage(FtpReplyCode::ACTION_ABORTED_LOCAL_ERROR, "Error opening file for transfer");
655-
#endif // WIN32
655+
#endif // _WIN32
656656

657657
return;
658658
}
@@ -721,11 +721,11 @@ namespace fineftp
721721

722722
if (!file->good())
723723
{
724-
#ifdef WIN32
724+
#ifdef _WIN32
725725
sendFtpMessage(FtpReplyCode::ACTION_ABORTED_LOCAL_ERROR, "Error opening file for transfer: " + GetLastErrorStr());
726726
#else
727727
sendFtpMessage(FtpReplyCode::ACTION_ABORTED_LOCAL_ERROR, "Error opening file for transfer");
728-
#endif // WIN32
728+
#endif // _WIN32
729729
return;
730730
}
731731

@@ -803,7 +803,7 @@ namespace fineftp
803803
return;
804804
}
805805

806-
#ifdef WIN32
806+
#ifdef _WIN32
807807

808808
if (MoveFileW(StrConvert::Utf8ToWide(local_from_path).c_str(), StrConvert::Utf8ToWide(local_to_path).c_str()) != 0)
809809
{
@@ -815,7 +815,7 @@ namespace fineftp
815815
sendFtpMessage(FtpReplyCode::FILE_ACTION_NOT_TAKEN, "Error renaming file: " + GetLastErrorStr());
816816
return;
817817
}
818-
#else // WIN32
818+
#else // _WIN32
819819
if (rename(local_from_path.c_str(), local_to_path.c_str()) == 0)
820820
{
821821
sendFtpMessage(FtpReplyCode::FILE_ACTION_COMPLETED, "OK");
@@ -826,7 +826,7 @@ namespace fineftp
826826
sendFtpMessage(FtpReplyCode::FILE_ACTION_NOT_TAKEN, "Error renaming file");
827827
return;
828828
}
829-
#endif // WIN32
829+
#endif // _WIN32
830830
}
831831
else
832832
{
@@ -870,7 +870,7 @@ namespace fineftp
870870
}
871871
else
872872
{
873-
#ifdef WIN32
873+
#ifdef _WIN32
874874
if (DeleteFileW(StrConvert::Utf8ToWide(local_path).c_str()) != 0)
875875
{
876876
sendFtpMessage(FtpReplyCode::FILE_ACTION_COMPLETED, "Successfully deleted file");
@@ -912,7 +912,7 @@ namespace fineftp
912912

913913
const std::string local_path = toLocalPath(param);
914914

915-
#ifdef WIN32
915+
#ifdef _WIN32
916916
if (RemoveDirectoryW(StrConvert::Utf8ToWide(local_path).c_str()) != 0)
917917
{
918918
sendFtpMessage(FtpReplyCode::FILE_ACTION_COMPLETED, "Successfully removed directory");
@@ -959,7 +959,7 @@ namespace fineftp
959959

960960
auto local_path = toLocalPath(param);
961961

962-
#ifdef WIN32
962+
#ifdef _WIN32
963963
LPSECURITY_ATTRIBUTES security_attributes = nullptr; // => Default security attributes
964964
if (CreateDirectoryW(StrConvert::Utf8ToWide(local_path).c_str(), security_attributes) != 0)
965965
{
@@ -1621,7 +1621,7 @@ namespace fineftp
16211621
return FtpMessage(FtpReplyCode::FILE_ACTION_COMPLETED, "Working directory changed to " + ftp_working_directory_);
16221622
}
16231623

1624-
#ifdef WIN32
1624+
#ifdef _WIN32
16251625
std::string FtpSession::GetLastErrorStr()
16261626
{
16271627
const DWORD error = GetLastError();
@@ -1652,5 +1652,5 @@ namespace fineftp
16521652

16531653
return "";
16541654
}
1655-
#endif //WIN32
1655+
#endif //_WIN32
16561656
}

fineftp-server/src/ftp_session.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
#include "user_database.h"
1616
#include "ftp_user.h"
1717

18-
#ifdef WIN32
18+
#ifdef _WIN32
1919
#include "win_str_convert.h"
20-
#endif // WIN32
20+
#endif // _WIN32
2121

2222
namespace fineftp
2323
{
@@ -162,13 +162,13 @@ namespace fineftp
162162

163163
FtpMessage executeCWD(const std::string& param);
164164

165-
#ifdef WIN32
165+
#ifdef _WIN32
166166
/**
167167
* @brief Returns Windows' GetLastError() as human readable string
168168
* @return The message of the last error
169169
*/
170170
static std::string GetLastErrorStr();
171-
#endif // WIN32
171+
#endif // _WIN32
172172

173173
////////////////////////////////////////////////////////
174174
// Member variables

fineftp-server/src/win_str_convert.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
#include "win_str_convert.h" // IWYU pragma: associated
22

3-
#ifdef WIN32
3+
#ifdef _WIN32
44
#define WIN32_LEAN_AND_MEAN
55
#ifndef NOMINMAX
66
#define NOMINMAX
77
#endif
88
#include <windows.h> // IWYU pragma: keep
9-
#endif // WIN32
9+
#endif // _WIN32
1010

1111
#include <string>
1212

1313
namespace fineftp
1414
{
1515
namespace StrConvert
1616
{
17-
#ifdef WIN32
17+
#ifdef _WIN32
1818
std::string WideToAnsi(const std::wstring& wstr)
1919
{
2020
const int count = WideCharToMultiByte(CP_ACP, 0, wstr.c_str(), static_cast<int>(wstr.length()), nullptr, 0, nullptr, nullptr);

fineftp-server/src/win_str_convert.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ namespace fineftp
44
{
55
namespace StrConvert
66
{
7-
#ifdef WIN32
7+
#ifdef _WIN32
88
std::string WideToAnsi(const std::wstring& wstr);
99

1010
std::wstring AnsiToWide(const std::string& str);
@@ -16,6 +16,6 @@ namespace fineftp
1616
std::string AnsiToUtf8(const std::string& str);
1717

1818
std::string Utf8ToAnsi(const std::string& str);
19-
#endif // WIN32
19+
#endif // _WIN32
2020
}
2121
}

0 commit comments

Comments
 (0)