Using conditional compilation is not a very good solution to your problem: if you later compile with another compiler or on a different platform, you will need to add more and more special tests to handle these environments that may or may not support strncpy_s
. There is a standard way to request for these extended functions and to check whether they are available, but I strongly recommend you define your replacement function at all times, name it something else and use it unconditionally.
As you may be aware, strncpy
and strncpy_s
are not interchangeable, they have different semantics, beyond the extra argument for the size of the destination. strncpy
definitely should not be used, because it is error prone: even if you master its peculiar side effects, other programmers later reading or modifying your code will not. strncpy_s
has its own quirks: the behavior on constraint violation may not be what you expect.