I have been asked to build an existing set of classes that use the functions like strcat_s, itoa_s, sprintf_s extensively and I cannot find a way for the compiler to find them. I set the -std=c++11 compiler switch and include <string.h> in the file and I still get the error that they cannot be found.
Is there something else I need to do?
Does your compiler find these without -std=c++11 ?
According to http://stackoverflow.com/questions/4570147/safe-string-functions-in-mac-os-x-and-linux, the safe versions of string functions are not available on linux.
However, it should not be difficult to write such functions that would perform these checks before calling original non-safe functions, such as :
inline char* strcat_s(char* dest, size_t size, const char* src)
{
if(strlen(dest) + strlen(src) + 1 > size) //+1 for ending
inline char* strcat_s(char* dest, size_t size, const char* src)
{
if(strlen(dest) + strlen(src) + 1 > size) //+1 for ending \0
return strcat(dest, src);
}
<Do some error code>
return strcat(dest, src);
}