summaryrefslogtreecommitdiff
path: root/source/utilities
diff options
context:
space:
mode:
Diffstat (limited to 'source/utilities')
-rw-r--r--source/utilities/Logger.h2
-rw-r--r--source/utilities/String_s.cpp34
-rw-r--r--source/utilities/String_s.h80
3 files changed, 115 insertions, 1 deletions
diff --git a/source/utilities/Logger.h b/source/utilities/Logger.h
index 2388bb4..ec1f0a9 100644
--- a/source/utilities/Logger.h
+++ b/source/utilities/Logger.h
@@ -30,4 +30,4 @@ private:
MessageCallback_t messageCallback_;
};
-#endif // _LOGGER_H_ \ No newline at end of file
+#endif // _LOGGER_H_
diff --git a/source/utilities/String_s.cpp b/source/utilities/String_s.cpp
new file mode 100644
index 0000000..c204ec8
--- /dev/null
+++ b/source/utilities/String_s.cpp
@@ -0,0 +1,34 @@
+/*******************************************************************************
+ * Copyright (C) ST-Ericsson SA 2012
+ * License terms: 3-clause BSD license
+ ******************************************************************************/
+#include "String_s.h"
+
+char *strcpy_s(char *dst, size_t _Size, const char *src)
+{
+ return strncpy(dst, src, _Size);
+}
+
+int sprintf_s(char *dst, size_t _Size, const char *format, ...)
+{
+ va_list l;
+ int ReturnValue;
+
+ va_start(l, format);
+ ReturnValue = vsnprintf(dst, _Size, format, l);
+ va_end(l);
+
+ return ReturnValue;
+}
+
+char *strncpy_s(char *dst, const char *src, size_t _Size)
+{
+ return strncpy(dst, src, _Size);
+}
+
+#ifndef __MINGW32__
+int _stricmp(const char *s1, const char *s2)
+{
+ return strcasecmp(s1, s2);
+}
+#endif
diff --git a/source/utilities/String_s.h b/source/utilities/String_s.h
new file mode 100644
index 0000000..88179e8
--- /dev/null
+++ b/source/utilities/String_s.h
@@ -0,0 +1,80 @@
+/*******************************************************************************
+ * Copyright (C) ST-Ericsson SA 2012
+ * License terms: 3-clause BSD license
+ ******************************************************************************/
+#include <stdio.h>
+#include <stdarg.h>
+#include <string.h>
+#include <strings.h>
+
+#define MAX(a, b) ((a) > (b) ? (a) : (b))
+
+/*
+ * str manipulation functions used in windows build
+ */
+
+char *strcpy_s(char *dst, size_t _Size, const char *src);
+char *strncpy_s(char *dst, const char *src, size_t _Size);
+#ifndef __MINGW32__
+int _stricmp(const char *s1, const char *s2);
+#endif
+int sprintf_s(char *dst, size_t _Size, const char *format, ...);
+
+#define _snprintf snprintf
+
+template <size_t _Size>
+char *strcpy_s(char(&dst)[_Size], const char src[])
+{
+ return strncpy(dst, src, _Size);
+}
+
+template<size_t _Size>
+int sprintf_s(char(&dst)[_Size], const char *format, ...)
+{
+ int ReturnValue;
+ va_list l;
+ va_start(l, format);
+ ReturnValue = vsnprintf(dst, _Size, format, l);
+ va_end(l);
+ return ReturnValue;
+}
+
+template <size_t _Size>
+char *strcat_s(char(&dst)[_Size], const char src[])
+{
+ return strncat(dst, src, _Size);
+}
+
+template <size_t _Size>
+int _ultoa_s(unsigned long value, char(&str)[_Size], int radix)
+{
+ switch (radix) {
+ case 10:
+ return sprintf_s(str, "%ul", value);
+
+ case 16:
+ return sprintf_s(str, "%ulX", value);
+
+ default:
+ return -1;
+ }
+}
+
+template<size_t _Size>
+int _snprintf_s(char(&dst)[_Size], size_t _MaxCount, const char *format, ...)
+{
+ int ReturnValue;
+ va_list l;
+ va_start(l, format);
+ ReturnValue = vsnprintf(dst, MAX(_MaxCount, _Size), format, l);
+ va_end(l);
+ return ReturnValue;
+}
+
+template<size_t _Size>
+int vsprintf_s(char(&dst)[_Size], const char *format, va_list l)
+{
+ return vsnprintf(dst, _Size, format, l);
+}
+
+