Split Sutbstitutes into cpp and header to make it possible to use unity build

This commit is contained in:
Magne Sjaastad 2020-11-16 14:55:29 +01:00
parent 99742e8062
commit be23df1398
3 changed files with 39 additions and 26 deletions

View File

@ -63,6 +63,10 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
endif()
endif()
if(MSVC)
list(APPEND opm-common_SOURCES opm-common/cross-platform/windows/Substitutes.cpp )
endif(MSVC)
add_library(${PROJECT_NAME}
STATIC
${opm_parser_source_files_long_path}

View File

@ -0,0 +1,31 @@
#ifdef _WIN32
#include "Substitutes.hpp"
int
fnmatch(const char* pattern, const char* string, int flags)
{
if (flags != 0) {
std::cerr << __FUNCTION__ << "Warning: flags other than 0 are not supported in Windows.";
}
wchar_t pszFile[1024];
wchar_t pszSpec[1024];
size_t outsize;
mbstowcs_s(&outsize, pszFile, string, strlen(string) + 1);
mbstowcs_s(&outsize, pszSpec, pattern, strlen(pattern) + 1);
return (!PathMatchSpecW(pszFile, pszSpec));
}
struct tm*
gmtime_r(const time_t* timer, struct tm* buf)
{
if (gmtime_s(buf, timer) == 0) {
return nullptr;
} else {
return buf;
}
}
#endif

View File

@ -1,11 +1,12 @@
#pragma once
#ifdef _WIN32
#include <Shlwapi.h>
#define NOMINMAX
#include <windows.h>
#undef NOMINMAX
// IGNORE is used in InputErrorAction.hpp, as an enum value,
// IGNORE is used in InputErrorAction.hpp, as an enum value,
// but is defined as a #def in WinBase.h which is included by Shlwapi.h.
// It is not required here, so we can undefine it.
#undef IGNORE
@ -15,31 +16,8 @@
#include <stddef.h>
#include <time.h>
int fnmatch(const char* pattern, const char* string, int flags)
{
if (flags != 0) {
std::cerr << __FUNCTION__ << "Warning: flags other than 0 are not supported in Windows.";
}
wchar_t pszFile[1024];
wchar_t pszSpec[1024];
int fnmatch(const char* pattern, const char* string, int flags);
size_t outsize;
mbstowcs_s(&outsize, pszFile, string, strlen(string) + 1);
mbstowcs_s(&outsize, pszSpec, pattern, strlen(pattern) + 1);
return (!PathMatchSpecW(pszFile, pszSpec));
}
struct tm* gmtime_r(const time_t* timer, struct tm* buf)
{
if (gmtime_s(buf, timer) == 0)
{
return nullptr;
}
else
{
return buf;
}
}
struct tm* gmtime_r(const time_t* timer, struct tm* buf);
#endif