Fix getenv work correct on non-windows

This commit is contained in:
Unknown 2019-02-22 14:06:39 +01:00
parent abd91ab507
commit 9398ef4137
2 changed files with 7 additions and 9 deletions

View File

@ -1,6 +1,6 @@
#include "porting.h"
#include <cstdio> // fopen
#include <cstdio> // fopen
#include <cstdlib> // getenv
#include <cstring>
@ -14,7 +14,7 @@ inline void sleepMs(int time)
FILE *porting::fopen(const char *filename, const char *mode)
{
FILE *file = nullptr;
#ifdef _WIN32
#ifdef _WIN32
fopen_s(&file, filename, mode);
#else
file = ::fopen(filename, mode);
@ -25,19 +25,18 @@ FILE *porting::fopen(const char *filename, const char *mode)
std::string porting::getenv(const char *name)
{
std::string env;
char *buf = nullptr;
#ifdef _WIN32
std::size_t len;
_dupenv_s(&buf, &len, name);
#else
env = ::getenv(name);
buf = ::getenv(name);
#endif // _WIN32
return buf == nullptr ? std::string() : std::string(buf);
}
std::string porting::strerror(int errnum)
std::string porting::strerror(int errnum)
{
#ifdef _WIN32
const std::size_t len = 100;

View File

@ -6,7 +6,7 @@
#include <thread>
#ifdef _MSC_VER
#ifndef strcasecmp
#ifndef strcasecmp
#define strcasecmp(a, b) _stricmp(a, b)
#endif
#endif
@ -20,7 +20,7 @@ namespace porting {
it is also much faster the the deprecated fopen (~50 ms!)
On other systems it does still use the original fopen
*/
FILE* fopen(const char *filename, const char *mode);
FILE *fopen(const char *filename, const char *mode);
/*
Wrapper for getenv_s on Windows.
@ -30,5 +30,4 @@ namespace porting {
std::string strerror(int errnum);
} // namespace porting
} // namespace porting