From 5a0f2e8ed45d996b5f966d77608823d8d82fdea8 Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Fri, 19 Jun 2015 21:40:15 -0700 Subject: [PATCH 1/2] 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; From a0f0690719baa9814708d2b3ada44b6dcfa8f926 Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Sat, 20 Jun 2015 08:07:11 -1000 Subject: [PATCH 2/2] confirmed linux build working; solved signing warnings --- Athena.pro | 14 +++++++------- PKGBUILD | 2 +- src/Athena/FileWriter.cpp | 12 ++++++------ 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/Athena.pro b/Athena.pro index e2e2f85..6291329 100644 --- a/Athena.pro +++ b/Athena.pro @@ -51,15 +51,15 @@ unix { } win32 { - isEmpty(PREFIX) { + isEmpty(PREFIX) { PREFIX = $$PWD/pkg - } + } - libFiles.path = $$PREFIX/lib - libFiles.files = $$PWD/lib/* - headerFiles.path = $$PREFIX/include/Athena - headerFiles.files = $$PWD/include/* - INSTALLS += libFiles headerFiles + libFiles.path = $$PREFIX/lib + libFiles.files = $$PWD/lib/* + headerFiles.path = $$PREFIX/include/Athena + headerFiles.files = $$PWD/include/* + INSTALLS += libFiles headerFiles } diff --git a/PKGBUILD b/PKGBUILD index 635508e..6b9924a 100644 --- a/PKGBUILD +++ b/PKGBUILD @@ -1,7 +1,7 @@ # PKGBUILD for libAthena _pkgname=libathena pkgname=$_pkgname-git -pkgver=1.1.0.39.g2d8aeb7 +pkgver=1.1.0.40.g687a7ee pkgrel=1 pkgdesc="Basic cross platform IO library" arch=('i686' 'x86_64') diff --git a/src/Athena/FileWriter.cpp b/src/Athena/FileWriter.cpp index 21ce629..b8a03af 100644 --- a/src/Athena/FileWriter.cpp +++ b/src/Athena/FileWriter.cpp @@ -316,16 +316,16 @@ void FileWriter::writeString(const std::string& val, atInt32 fixedLen) } else { - if (val.length() >= fixedLen) + if ((atInt32)val.length() >= fixedLen) { - if (fwrite(val.c_str(), 1, fixedLen, m_fileHandle) != fixedLen) + if ((atInt32)fwrite(val.c_str(), 1, fixedLen, m_fileHandle) != fixedLen) THROW_IO_EXCEPTION("Unable to write to stream"); } else { if (fwrite(val.c_str(), 1, val.length(), m_fileHandle) != val.length()) THROW_IO_EXCEPTION("Unable to write to stream"); - for (atUint32 i=val.length() ; i= fixedLen) + if ((atInt32)val.length() >= fixedLen) { - if (fwrite(val.c_str(), 2, fixedLen, m_fileHandle) != fixedLen) + if ((atInt32)fwrite(val.c_str(), 2, fixedLen, m_fileHandle) != fixedLen) THROW_IO_EXCEPTION("Unable to write to stream"); } else { if (fwrite(val.c_str(), 2, val.length(), m_fileHandle) != val.length()) THROW_IO_EXCEPTION("Unable to write to stream"); - for (atUint32 i=val.length() ; i