/******************************************************************************* * Copyright (C) ST-Ericsson SA 2012 * License terms: 3-clause BSD license ******************************************************************************/ #include #include #include #include #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 char *strcpy_s(char(&dst)[_Size], const char src[]) { return strncpy(dst, src, _Size); } template 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 char *strcat_s(char(&dst)[_Size], const char src[]) { return strncat(dst, src, _Size); } template 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 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 int vsprintf_s(char(&dst)[_Size], const char *format, va_list l) { return vsnprintf(dst, _Size, format, l); }