diff options
author | Christophe Fergeau <cfergeau@redhat.com> | 2015-02-02 14:35:22 +0100 |
---|---|---|
committer | Christophe Fergeau <cfergeau@redhat.com> | 2015-02-06 13:35:44 +0100 |
commit | 95d04aa1134b3bcbf79d2c8aa4102ec486c59b80 (patch) | |
tree | 3283f14971a91762e50f304595cba2b12e3e30bf /common/vdcommon.cpp | |
parent | ff7dc22e27aca54933eaec161a5ccd9225b70b7c (diff) |
Add strcat_s/strcpy_s fallbacks
These security functions are available when building with MSVC++. With
mingw, they can be used at build time, but their availability will
depend on the version of MSVCRT the user has installed on their system.
In particular, a default install of Windows XP will not have a new
enough MSVCRT version, causing runtime failures as the binary built with
mingw and using strcat_s will not be able to find the necessary entry
point in the MSVCRT runtime.
This commit adds some strcat_s/strcpy_s-like functions used with mingw
which will always be available.
Diffstat (limited to 'common/vdcommon.cpp')
-rw-r--r-- | common/vdcommon.cpp | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/common/vdcommon.cpp b/common/vdcommon.cpp index 4dc50b4..40c9e13 100644 --- a/common/vdcommon.cpp +++ b/common/vdcommon.cpp @@ -34,3 +34,39 @@ int supported_system_version() } return 0; } + +#ifndef HAVE_STRCAT_S +errno_t vdagent_strcat_s(char *strDestination, + size_t numberOfElements, + const char *strSource) +{ + if (strDestination == NULL) + return EINVAL; + strDestination[0] = '\0'; + if (strSource == NULL) + return EINVAL; + if (strlen(strDestination) + strlen(strSource) + 1 > numberOfElements) { + return ERANGE; + } + + return strcat(strDestination, strSource); +} +#endif + +#ifndef HAVE_STRCPY_S +errno_t vdagent_strcpy_s(char *strDestination, + size_t numberOfElements, + const char *strSource) +{ + if (strDestination == NULL) + return EINVAL; + strDestination[0] = '\0'; + if (strSource == NULL) + return EINVAL; + if (strlen(strSource) + 1 > numberOfElements) { + return ERANGE; + } + + return strcpy(strDestination, strSource); +} +#endif |