From 5a0f2e8ed45d996b5f966d77608823d8d82fdea8 Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Fri, 19 Jun 2015 21:40:15 -0700 Subject: [PATCH] MSVC build fixes --- include/Athena/DNA.hpp | 7 ++++++ include/Athena/Dir.hpp | 4 ++++ include/Athena/Global.hpp | 17 +++++++++++++++ include/Athena/IOException.hpp | 23 +++++++------------- include/Athena/InvalidDataException.hpp | 6 ++--- include/Athena/InvalidOperationException.hpp | 22 ++++++++----------- src/Athena/Dir.cpp | 14 ++++++++++-- src/Athena/FileInfo.cpp | 15 ++++++++----- 8 files changed, 69 insertions(+), 39 deletions(-) diff --git a/include/Athena/DNA.hpp b/include/Athena/DNA.hpp index 1a62c89..12dea27 100644 --- a/include/Athena/DNA.hpp +++ b/include/Athena/DNA.hpp @@ -62,6 +62,13 @@ struct DNA void read(Athena::io::IStreamReader&); \ void write(Athena::io::IStreamWriter&) const; \ +/** Macro to supply count variable to atdna and mute it for other compilers */ +#ifdef __clang__ +#define DNA_COUNT(cnt) sizeof(cnt) +#else +#define DNA_COUNT(cnt) 0 +#endif + } } diff --git a/include/Athena/Dir.hpp b/include/Athena/Dir.hpp index 63ad582..9e9a5a3 100644 --- a/include/Athena/Dir.hpp +++ b/include/Athena/Dir.hpp @@ -4,6 +4,10 @@ #include "Athena/FileInfo.hpp" #include +#if _WIN32 +typedef int mode_t; +#endif + namespace Athena { class Dir diff --git a/include/Athena/Global.hpp b/include/Athena/Global.hpp index 4ac92c1..0fb83d0 100644 --- a/include/Athena/Global.hpp +++ b/include/Athena/Global.hpp @@ -7,6 +7,21 @@ #ifdef _MSC_VER #pragma warning(disable : 4996) + +#include + +#if !defined(S_ISREG) && defined(S_IFMT) && defined(S_IFREG) +#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) +#endif + +#if !defined(S_ISDIR) && defined(S_IFMT) && defined(S_IFDIR) +#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) +#endif + +#if !defined(S_ISLNK) +#define S_ISLNK(m) 0 +#endif + #endif #ifndef AT_PRETTY_FUNCTION @@ -30,6 +45,8 @@ #include "gekko_support.h" typedef struct stat stat64_t; #define stat64 stat +#elif _WIN32 +typedef struct _stat64 stat64_t; #else typedef struct stat64 stat64_t; #endif diff --git a/include/Athena/IOException.hpp b/include/Athena/IOException.hpp index 1e8d396..ec70713 100644 --- a/include/Athena/IOException.hpp +++ b/include/Athena/IOException.hpp @@ -37,14 +37,11 @@ public: #ifdef _MSC_VER #define THROW_IO_EXCEPTION(args, ...) \ do { \ - if (atGetExceptionHandler()) {atGetExceptionHandler()(__FILE__, AT_PRETTY_FUNCTION, __LINE__, __VA_ARGS__); return; \ - } else { -std::string msg = Athena::utility::sprintf(args, __VA_ARGS__); -\ -throw Athena::error::IOException(std::string("IOException: ") + msg, __FILE__, AT_PRETTY_FUNCTION, __LINE__); -\ + if (atGetExceptionHandler()) {atGetExceptionHandler()(__FILE__, AT_PRETTY_FUNCTION, __LINE__, args, __VA_ARGS__); return; \ + } else { \ +std::string msg = Athena::utility::sprintf(args, __VA_ARGS__); \ +throw Athena::error::IOException(std::string("IOException: ") + msg, __FILE__, AT_PRETTY_FUNCTION, __LINE__); \ } \ - } while (0) #elif defined(__GNUC__) #define THROW_IO_EXCEPTION(args...) \ @@ -59,15 +56,11 @@ throw Athena::error::IOException(std::string("IOException: ") + msg, __FILE__, A #ifdef _MSC_VER #define THROW_IO_EXCEPTION_RETURN(ret, args, ...) \ do { \ - if (atGetExceptionHandler()) {atGetExceptionHandler()(__FILE__, AT_PRETTY_FUNCTION, __LINE__, __VA_ARGS__); return ret; \ - } else { - std::string msg = Athena::utility::sprintf(args, __VA_ARGS__); - -\ -throw Athena::error::IOException(std::string("IOException: ") + msg, __FILE__, AT_PRETTY_FUNCTION, __LINE__); -\ + if (atGetExceptionHandler()) {atGetExceptionHandler()(__FILE__, AT_PRETTY_FUNCTION, __LINE__, args, __VA_ARGS__); return ret; \ + } else { \ + std::string msg = Athena::utility::sprintf(args, __VA_ARGS__); \ +throw Athena::error::IOException(std::string("IOException: ") + msg, __FILE__, AT_PRETTY_FUNCTION, __LINE__); \ } \ - } while (0) #elif defined(__GNUC__) #define THROW_IO_EXCEPTION_RETURN(ret, args...) \ diff --git a/include/Athena/InvalidDataException.hpp b/include/Athena/InvalidDataException.hpp index 2444fbc..5d9cd8a 100644 --- a/include/Athena/InvalidDataException.hpp +++ b/include/Athena/InvalidDataException.hpp @@ -32,7 +32,7 @@ public: #ifdef _MSC_VER #define THROW_INVALID_DATA_EXCEPTION(args, ...) \ do { \ - if (atGetExceptionHandler()) {atGetExceptionHandler()(__FILE__, AT_PRETTY_FUNCTION, __LINE__, __VA_ARGS__); return; } \ + if (atGetExceptionHandler()) {atGetExceptionHandler()(__FILE__, AT_PRETTY_FUNCTION, __LINE__, args, __VA_ARGS__); return; } \ else { std::string msg = Athena::utility::sprintf(args, __VA_ARGS__); \ throw Athena::error::InvalidDataException(msg, __FILE__, AT_PRETTY_FUNCTION, __LINE__); \ } \ @@ -47,9 +47,9 @@ public: #endif #ifdef _MSC_VER -#define THROW_INVALID_DATA_EXCEPTION(args, ...) \ +#define THROW_INVALID_DATA_EXCEPTION_RETURN(ret, args, ...) \ do { \ - if (atGetExceptionHandler()) {atGetExceptionHandler()(__FILE__, AT_PRETTY_FUNCTION, __LINE__, __VA_ARGS__); return; } \ + if (atGetExceptionHandler()) {atGetExceptionHandler()(__FILE__, AT_PRETTY_FUNCTION, __LINE__, args, __VA_ARGS__); return ret; } \ else { std::string msg = Athena::utility::sprintf(args, __VA_ARGS__); \ throw Athena::error::InvalidDataException(msg, __FILE__, AT_PRETTY_FUNCTION, __LINE__); \ } \ diff --git a/include/Athena/InvalidOperationException.hpp b/include/Athena/InvalidOperationException.hpp index fd6210d..dfe2b11 100644 --- a/include/Athena/InvalidOperationException.hpp +++ b/include/Athena/InvalidOperationException.hpp @@ -36,14 +36,13 @@ public: #ifdef _MSC_VER #define THROW_INVALID_OPERATION_EXCEPTION(args, ...) \ do { \ - if (atGetExceptionHandler()) {atGetExceptionHandler()(__FILE__, AT_PRETTY_FUNCTION, __LINE__, __VA_ARGS__); return; \ - } else { -std::string msg = Athena::utility::sprintf(args, __VA_ARGS__); + if (atGetExceptionHandler()) {atGetExceptionHandler()(__FILE__, AT_PRETTY_FUNCTION, __LINE__, args, __VA_ARGS__); return; \ + } else { \ +std::string msg = Athena::utility::sprintf(args , __VA_ARGS__); \ \ -throw Athena::error::InvalidOperationException(std::string("InvalidOperationException: ") + msg, __FILE__, AT_PRETTY_FUNCTION, __LINE__); +throw Athena::error::InvalidOperationException(std::string("InvalidOperationException: ") + msg, __FILE__, AT_PRETTY_FUNCTION, __LINE__); \ \ } \ - } while (0) #elif defined (__GNUC__) #define THROW_INVALID_OPERATION_EXCEPTION(args...) \ @@ -56,17 +55,14 @@ throw Athena::error::InvalidOperationException(std::string("InvalidOperationExce #endif #ifdef _MSC_VER -#define THROW_INVALID_OPERATION_EXCEPTIONRETURN(ret, args, ...) \ +#define THROW_INVALID_OPERATION_EXCEPTION_RETURN(ret, args, ...) \ do { \ - if (atGetExceptionHandler()) {atGetExceptionHandler()(__FILE__, AT_PRETTY_FUNCTION, __LINE__, __VA_ARGS__); return ret; \ - } else { - std::string msg = Athena::utility::sprintf(args, __VA_ARGS__); - -\ -throw Athena::error::InvalidOperationException(std::string("InvalidOperationException: ") + msg, __FILE__, AT_PRETTY_FUNCTION, __LINE__); + if (atGetExceptionHandler()) {atGetExceptionHandler()(__FILE__, AT_PRETTY_FUNCTION, __LINE__, args, __VA_ARGS__); return ret; \ + } else { \ + std::string msg = Athena::utility::sprintf(args, __VA_ARGS__); \ \ +throw Athena::error::InvalidOperationException(std::string("InvalidOperationException: ") + msg, __FILE__, AT_PRETTY_FUNCTION, __LINE__); \ } \ - } while (0) #elif defined(__GNUC__) #define THROW_INVALID_OPERATION_EXCEPTION_RETURN(ret, args...) \ diff --git a/src/Athena/Dir.cpp b/src/Athena/Dir.cpp index af15983..e9a77f1 100644 --- a/src/Athena/Dir.cpp +++ b/src/Athena/Dir.cpp @@ -1,12 +1,18 @@ #include "Athena/Dir.hpp" -#include #include -#include #include #include #define __STDC_FORMAT_MACROS #include +#ifndef _WIN32 +#include +#include +#else +#include +#include +#endif + #ifdef _MSC_VER #define stat64 __stat64 #define realpath(__name, __resolved) _fullpath((__name), (__resolved), 4096) @@ -64,7 +70,11 @@ bool Dir::touch() bool Dir::mkdir(const std::string& dir, mode_t mode) { +#if _WIN32 + return !(::_mkdir(dir.c_str()) < 0); +#else return !(::mkdir(dir.c_str(), mode) < 0); +#endif } bool Dir::mkpath(const std::string& path, mode_t mode) diff --git a/src/Athena/FileInfo.cpp b/src/Athena/FileInfo.cpp index 7d1d4db..10999ed 100644 --- a/src/Athena/FileInfo.cpp +++ b/src/Athena/FileInfo.cpp @@ -2,15 +2,18 @@ #include "Athena/Utility.hpp" #include "Athena/FileWriter.hpp" #include "Athena/FileReader.hpp" -#include #include #include -#include -#include -#include #include #include +#ifndef _WIN32 +#include +#include +#include +#include +#endif + #if !(defined(HW_DOL) || defined(HW_RVL) || defined(_WIN32)) #include #endif @@ -24,7 +27,7 @@ #include #include #define stat64 __stat64 -#define realpath(__name, __resolved) _fullpath((__name), (__resolved), 4096) +#define realpath(__name, __resolved) _fullpath((__resolved), (__name), 4096) #endif namespace Athena @@ -126,7 +129,7 @@ bool FileInfo::touch() const HANDLE fh; wchar_t date[80], time[80]; - fh = CreateFileW(path, GENERIC_READ | FILE_WRITE_ATTRIBUTES, 0, NULL, CREATE_NEW, 0, NULL); + fh = CreateFileA(m_path.c_str(), GENERIC_READ | FILE_WRITE_ATTRIBUTES, 0, NULL, CREATE_NEW, 0, NULL); if (fh == INVALID_HANDLE_VALUE) return false;