[misc] do not declare _CRT_SECURE_NO_WARNINGS and use secure functions

* From NickPapagiorgio/rufus@c144d76852
This commit is contained in:
Johannes Holzhäuer 2015-08-26 14:49:35 +02:00 committed by Pete Batard
parent 16d178e720
commit 387b1fbce7
6 changed files with 38 additions and 22 deletions

View file

@ -28,6 +28,8 @@
#include <shlwapi.h>
#include <setupapi.h>
#include <direct.h>
#include <share.h>
#include <fcntl.h>
#include <io.h>
#pragma once
@ -771,7 +773,7 @@ static __inline FILE* fopenU(const char* filename, const char* mode)
FILE* ret = NULL;
wconvert(filename);
wconvert(mode);
ret = _wfopen(wfilename, wmode);
_wfopen_s(&ret, wfilename, wmode);
wfree(filename);
wfree(mode);
return ret;
@ -780,8 +782,14 @@ static __inline FILE* fopenU(const char* filename, const char* mode)
static __inline int _openU(const char *filename, int oflag , int pmode)
{
int ret = -1;
int shflag = _SH_DENYNO;
wconvert(filename);
ret = _wopen(wfilename, oflag, pmode);
// Try to match the share flag to the oflag
if (oflag & _O_RDONLY)
shflag = _SH_DENYWR;
else if (oflag & _O_WRONLY)
shflag = _SH_DENYRD;
_wsopen_s(&ret, wfilename, oflag, shflag, pmode);
wfree(filename);
return ret;
}
@ -790,8 +798,12 @@ static __inline int _openU(const char *filename, int oflag , int pmode)
static __inline char* getenvU(const char* varname)
{
wconvert(varname);
char* ret;
ret = wchar_to_utf8(_wgetenv(wvarname));
char *ret;
wchar_t value[256];
size_t value_size;
// MinGW and WDK don't know wdupenv_s, so we use wgetenv_s
_wgetenv_s(&value_size, value, sizeof(value), wvarname);
ret = wchar_to_utf8(value);
wfree(varname);
return ret;
}