Merge pull request #15 from Antidote/msvc

Fixed variadic macros for MSVC
This commit is contained in:
Jack Andersen 2015-06-20 11:13:25 -07:00
commit 490c6d53f5
11 changed files with 83 additions and 53 deletions

View File

@ -51,15 +51,15 @@ unix {
} }
win32 { win32 {
isEmpty(PREFIX) { isEmpty(PREFIX) {
PREFIX = $$PWD/pkg PREFIX = $$PWD/pkg
} }
libFiles.path = $$PREFIX/lib libFiles.path = $$PREFIX/lib
libFiles.files = $$PWD/lib/* libFiles.files = $$PWD/lib/*
headerFiles.path = $$PREFIX/include/Athena headerFiles.path = $$PREFIX/include/Athena
headerFiles.files = $$PWD/include/* headerFiles.files = $$PWD/include/*
INSTALLS += libFiles headerFiles INSTALLS += libFiles headerFiles
} }

View File

@ -1,7 +1,7 @@
# PKGBUILD for libAthena # PKGBUILD for libAthena
_pkgname=libathena _pkgname=libathena
pkgname=$_pkgname-git pkgname=$_pkgname-git
pkgver=1.1.0.39.g2d8aeb7 pkgver=1.1.0.40.g687a7ee
pkgrel=1 pkgrel=1
pkgdesc="Basic cross platform IO library" pkgdesc="Basic cross platform IO library"
arch=('i686' 'x86_64') arch=('i686' 'x86_64')

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;

View File

@ -316,16 +316,16 @@ void FileWriter::writeString(const std::string& val, atInt32 fixedLen)
} }
else 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"); THROW_IO_EXCEPTION("Unable to write to stream");
} }
else else
{ {
if (fwrite(val.c_str(), 1, val.length(), m_fileHandle) != val.length()) if (fwrite(val.c_str(), 1, val.length(), m_fileHandle) != val.length())
THROW_IO_EXCEPTION("Unable to write to stream"); THROW_IO_EXCEPTION("Unable to write to stream");
for (atUint32 i=val.length() ; i<fixedLen ; ++i) for (atInt32 i=val.length() ; i<fixedLen ; ++i)
{ {
if (fwrite(&term, 1, 1, m_fileHandle) != 1) if (fwrite(&term, 1, 1, m_fileHandle) != 1)
THROW_IO_EXCEPTION("Unable to write to stream"); THROW_IO_EXCEPTION("Unable to write to stream");
@ -352,16 +352,16 @@ void FileWriter::writeWString(const std::wstring& val, atInt32 fixedLen)
} }
else else
{ {
if (val.length() >= 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"); THROW_IO_EXCEPTION("Unable to write to stream");
} }
else else
{ {
if (fwrite(val.c_str(), 2, val.length(), m_fileHandle) != val.length()) if (fwrite(val.c_str(), 2, val.length(), m_fileHandle) != val.length())
THROW_IO_EXCEPTION("Unable to write to stream"); THROW_IO_EXCEPTION("Unable to write to stream");
for (atUint32 i=val.length() ; i<fixedLen ; ++i) for (atInt32 i=val.length() ; i<fixedLen ; ++i)
{ {
if (fwrite(&term, 2, 1, m_fileHandle) != 1) if (fwrite(&term, 2, 1, m_fileHandle) != 1)
THROW_IO_EXCEPTION("Unable to write to stream"); THROW_IO_EXCEPTION("Unable to write to stream");