|
#pragma once
#include "windows.h"
#include "errno.h"
#define DECL_PROLOG inline errno_t __fastcall
DECL_PROLOG strcpy_s
(
char *strDestination,
size_t numberOfElements,
const char *strSource
)
{
if ( numberOfElements == 0 )
return ERANGE;
if ( !strDestination || !strSource )
return EINVAL;
::strcpy( strDestination, strSource );
return 0;
}
DECL_PROLOG wcscat_s
(
wchar_t * strDestination,
size_t numberOfElements,
const wchar_t *strSource
)
{
if ( numberOfElements == 0 )
return ERANGE;
if ( !strDestination || !strSource )
return EINVAL;
::wcscat( strDestination, strSource );
return 0;
}
DECL_PROLOG strcat_s
(
char * strDestination,
size_t numberOfElements,
const char *strSource
)
{
if ( numberOfElements == 0 )
return ERANGE;
if ( !strDestination || !strSource )
return EINVAL;
::strcat( strDestination, strSource );
return 0;
}
DECL_PROLOG wcscpy_s
(
wchar_t * strDestination,
size_t numberOfElements,
const wchar_t *strSource
)
{
if ( numberOfElements == 0 )
return ERANGE;
if ( !strDestination || !strSource )
return EINVAL;
::wcscpy( strDestination, strSource );
return 0;
}
DECL_PROLOG strncpy_s
(
char * strDestination,
size_t numberOfElements,
const char *strSource,
size_t count
)
{
if ( numberOfElements < count )
return ERANGE;
if ( !strDestination || !strSource )
return EINVAL;
::strncpy( strDestination, strSource, count );
return 0;
}
DECL_PROLOG wcsncpy_s
(
wchar_t * strDestination,
size_t numberOfElements,
const wchar_t * strSource,
size_t count
)
{
if ( numberOfElements < count )
return ERANGE;
if ( !strDestination || !strSource )
return EINVAL;
::wcsncpy( strDestination, strSource, count );
return 0;
}
inline int __fastcall vsprintf_s
(
char *buffer,
size_t numberOfElements,
const char *format,
va_list argptr
)
{
if ( numberOfElements > 1024 )
return -1;
return ::wvsprintfA( buffer, format, argptr );
}
inline int __fastcall vswprintf_s
(
wchar_t *buffer,
size_t numberOfElements,
const wchar_t *format,
va_list argptr
)
{
if ( numberOfElements > 1024 )
return -1;
return ::wvsprintfW( buffer, format, argptr );
}
#define wstrcpy_s(dest, destsize, source) ::wstrcpy((dest), (source))
#define wstrncpy_s(dest, destsize, source) ::wstrncpy((dest), (source))
#define swprintf_s _snwprintf
#define sprintf_s _snprintf
//#define _vsnprintf_s _vsnprintf
#undef DECL_PROLOG
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.