MSVC build fixes

This commit is contained in:
Jack Andersen 2015-06-19 21:40:15 -07:00
parent 687a7eef64
commit 5a0f2e8ed4
8 changed files with 69 additions and 39 deletions

View File

@ -62,6 +62,13 @@ struct DNA
void read(Athena::io::IStreamReader&); \ void read(Athena::io::IStreamReader&); \
void write(Athena::io::IStreamWriter&) const; \ 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
} }
} }

View File

@ -4,6 +4,10 @@
#include "Athena/FileInfo.hpp" #include "Athena/FileInfo.hpp"
#include <stdio.h> #include <stdio.h>
#if _WIN32
typedef int mode_t;
#endif
namespace Athena namespace Athena
{ {
class Dir class Dir

View File

@ -7,6 +7,21 @@
#ifdef _MSC_VER #ifdef _MSC_VER
#pragma warning(disable : 4996) #pragma warning(disable : 4996)
#include <sys/stat.h>
#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 #endif
#ifndef AT_PRETTY_FUNCTION #ifndef AT_PRETTY_FUNCTION
@ -30,6 +45,8 @@
#include "gekko_support.h" #include "gekko_support.h"
typedef struct stat stat64_t; typedef struct stat stat64_t;
#define stat64 stat #define stat64 stat
#elif _WIN32
typedef struct _stat64 stat64_t;
#else #else
typedef struct stat64 stat64_t; typedef struct stat64 stat64_t;
#endif #endif

View File

@ -37,14 +37,11 @@ public:
#ifdef _MSC_VER #ifdef _MSC_VER
#define THROW_IO_EXCEPTION(args, ...) \ #define THROW_IO_EXCEPTION(args, ...) \
do { \ 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 { } else { \
std::string msg = Athena::utility::sprintf(args, __VA_ARGS__); std::string msg = Athena::utility::sprintf(args, __VA_ARGS__); \
\ throw Athena::error::IOException(std::string("IOException: ") + msg, __FILE__, AT_PRETTY_FUNCTION, __LINE__); \
throw Athena::error::IOException(std::string("IOException: ") + msg, __FILE__, AT_PRETTY_FUNCTION, __LINE__);
\
} \ } \
} while (0) } while (0)
#elif defined(__GNUC__) #elif defined(__GNUC__)
#define THROW_IO_EXCEPTION(args...) \ #define THROW_IO_EXCEPTION(args...) \
@ -59,15 +56,11 @@ throw Athena::error::IOException(std::string("IOException: ") + msg, __FILE__, A
#ifdef _MSC_VER #ifdef _MSC_VER
#define THROW_IO_EXCEPTION_RETURN(ret, args, ...) \ #define THROW_IO_EXCEPTION_RETURN(ret, args, ...) \
do { \ do { \
if (atGetExceptionHandler()) {atGetExceptionHandler()(__FILE__, AT_PRETTY_FUNCTION, __LINE__, __VA_ARGS__); return ret; \ if (atGetExceptionHandler()) {atGetExceptionHandler()(__FILE__, AT_PRETTY_FUNCTION, __LINE__, args, __VA_ARGS__); return ret; \
} else { } else { \
std::string msg = Athena::utility::sprintf(args, __VA_ARGS__); std::string msg = Athena::utility::sprintf(args, __VA_ARGS__); \
throw Athena::error::IOException(std::string("IOException: ") + msg, __FILE__, AT_PRETTY_FUNCTION, __LINE__); \
\
throw Athena::error::IOException(std::string("IOException: ") + msg, __FILE__, AT_PRETTY_FUNCTION, __LINE__);
\
} \ } \
} while (0) } while (0)
#elif defined(__GNUC__) #elif defined(__GNUC__)
#define THROW_IO_EXCEPTION_RETURN(ret, args...) \ #define THROW_IO_EXCEPTION_RETURN(ret, args...) \

View File

@ -32,7 +32,7 @@ public:
#ifdef _MSC_VER #ifdef _MSC_VER
#define THROW_INVALID_DATA_EXCEPTION(args, ...) \ #define THROW_INVALID_DATA_EXCEPTION(args, ...) \
do { \ 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__); \ else { std::string msg = Athena::utility::sprintf(args, __VA_ARGS__); \
throw Athena::error::InvalidDataException(msg, __FILE__, AT_PRETTY_FUNCTION, __LINE__); \ throw Athena::error::InvalidDataException(msg, __FILE__, AT_PRETTY_FUNCTION, __LINE__); \
} \ } \
@ -47,9 +47,9 @@ public:
#endif #endif
#ifdef _MSC_VER #ifdef _MSC_VER
#define THROW_INVALID_DATA_EXCEPTION(args, ...) \ #define THROW_INVALID_DATA_EXCEPTION_RETURN(ret, args, ...) \
do { \ 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__); \ else { std::string msg = Athena::utility::sprintf(args, __VA_ARGS__); \
throw Athena::error::InvalidDataException(msg, __FILE__, AT_PRETTY_FUNCTION, __LINE__); \ throw Athena::error::InvalidDataException(msg, __FILE__, AT_PRETTY_FUNCTION, __LINE__); \
} \ } \

View File

@ -36,14 +36,13 @@ public:
#ifdef _MSC_VER #ifdef _MSC_VER
#define THROW_INVALID_OPERATION_EXCEPTION(args, ...) \ #define THROW_INVALID_OPERATION_EXCEPTION(args, ...) \
do { \ 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 { } else { \
std::string msg = Athena::utility::sprintf(args, __VA_ARGS__); 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) } while (0)
#elif defined (__GNUC__) #elif defined (__GNUC__)
#define THROW_INVALID_OPERATION_EXCEPTION(args...) \ #define THROW_INVALID_OPERATION_EXCEPTION(args...) \
@ -56,17 +55,14 @@ throw Athena::error::InvalidOperationException(std::string("InvalidOperationExce
#endif #endif
#ifdef _MSC_VER #ifdef _MSC_VER
#define THROW_INVALID_OPERATION_EXCEPTIONRETURN(ret, args, ...) \ #define THROW_INVALID_OPERATION_EXCEPTION_RETURN(ret, args, ...) \
do { \ do { \
if (atGetExceptionHandler()) {atGetExceptionHandler()(__FILE__, AT_PRETTY_FUNCTION, __LINE__, __VA_ARGS__); return ret; \ if (atGetExceptionHandler()) {atGetExceptionHandler()(__FILE__, AT_PRETTY_FUNCTION, __LINE__, args, __VA_ARGS__); return ret; \
} else { } else { \
std::string msg = Athena::utility::sprintf(args, __VA_ARGS__); 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) } while (0)
#elif defined(__GNUC__) #elif defined(__GNUC__)
#define THROW_INVALID_OPERATION_EXCEPTION_RETURN(ret, args...) \ #define THROW_INVALID_OPERATION_EXCEPTION_RETURN(ret, args...) \

View File

@ -1,12 +1,18 @@
#include "Athena/Dir.hpp" #include "Athena/Dir.hpp"
#include <dirent.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <unistd.h>
#include <stdlib.h> #include <stdlib.h>
#include <limits.h> #include <limits.h>
#define __STDC_FORMAT_MACROS #define __STDC_FORMAT_MACROS
#include <inttypes.h> #include <inttypes.h>
#ifndef _WIN32
#include <dirent.h>
#include <unistd.h>
#else
#include <time.h>
#include <direct.h>
#endif
#ifdef _MSC_VER #ifdef _MSC_VER
#define stat64 __stat64 #define stat64 __stat64
#define realpath(__name, __resolved) _fullpath((__name), (__resolved), 4096) #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) 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); return !(::mkdir(dir.c_str(), mode) < 0);
#endif
} }
bool Dir::mkpath(const std::string& path, mode_t mode) bool Dir::mkpath(const std::string& path, mode_t mode)

View File

@ -2,15 +2,18 @@
#include "Athena/Utility.hpp" #include "Athena/Utility.hpp"
#include "Athena/FileWriter.hpp" #include "Athena/FileWriter.hpp"
#include "Athena/FileReader.hpp" #include "Athena/FileReader.hpp"
#include <sys/time.h>
#include <time.h> #include <time.h>
#include <stdio.h> #include <stdio.h>
#include <dirent.h>
#include <sys/stat.h>
#include <unistd.h>
#include <limits.h> #include <limits.h>
#include <stdlib.h> #include <stdlib.h>
#ifndef _WIN32
#include <sys/time.h>
#include <sys/stat.h>
#include <unistd.h>
#include <dirent.h>
#endif
#if !(defined(HW_DOL) || defined(HW_RVL) || defined(_WIN32)) #if !(defined(HW_DOL) || defined(HW_RVL) || defined(_WIN32))
#include <fcntl.h> #include <fcntl.h>
#endif #endif
@ -24,7 +27,7 @@
#include <functional> #include <functional>
#include <locale> #include <locale>
#define stat64 __stat64 #define stat64 __stat64
#define realpath(__name, __resolved) _fullpath((__name), (__resolved), 4096) #define realpath(__name, __resolved) _fullpath((__resolved), (__name), 4096)
#endif #endif
namespace Athena namespace Athena
@ -126,7 +129,7 @@ bool FileInfo::touch() const
HANDLE fh; HANDLE fh;
wchar_t date[80], time[80]; 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) if (fh == INVALID_HANDLE_VALUE)
return false; return false;