as I know, memcpy is not 'safe'
That's not true as-is. In contrast with some really unsafe stdlib functions, it is only "not safe" if you can't use it. memcpy()
takes a buffer length as its third argument, so you don't risk buffer overflows; you can also check for the source and target pointers in order to avoid dereferencing NULL
, etc.
memcpy_s()
is a Microsoft extension, and a such, it's only available on Windows (fortunately). If you need memcpy()
, then use it, and don't try to replace standard functions with vendor-specific stuff (especially not if that vendor is Microsoft).