summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common/vdcommon.cpp36
-rw-r--r--common/vdcommon.h21
2 files changed, 57 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
diff --git a/common/vdcommon.h b/common/vdcommon.h
index af270db..01bbbc8 100644
--- a/common/vdcommon.h
+++ b/common/vdcommon.h
@@ -69,6 +69,27 @@ typedef CRITICAL_SECTION mutex_t;
#endif /* OLDMSVCRT */
#ifdef _MSC_VER // compiling with Visual Studio
+#define HAVE_STRCAT_S 1
+#define HAVE_STRCPY_S 1
+#endif
+
+#ifdef HAVE_STRCAT_S
+#define vdagent_strcat_s
+#else
+errno_t vdagent_strcat_s(char *strDestination,
+ size_t numberOfElements,
+ const char *strSource)
+#endif
+
+#ifdef HAVE_STRCPY_S
+#define vdagent_strcpy_s
+#else
+errno_t vdagent_strcpy_s(char *strDestination,
+ size_t numberOfElements,
+ const char *strSource)
+#endif
+
+#ifdef _MSC_VER // compiling with Visual Studio
#define snprintf sprintf_s
#define strncpy(d,s,n) strcpy_s(s, __min(n+1, sizeof(d)), s)
#define strcat(d,s) strcat_s(d, sizeof(d), s)