First of all, you could just redefine them like #define snprintf snprintf_s
. Their signatures are equal.
If you just want to generate a compiler error, the easiest way would be to always include a header with redefinitions of all functions you would like to block.
Theses redefinitions can generate a syntax error and also give the user the reason for the error:
#include <stdio.h>
#define snprintf {"Unsafe! Use snprintf_s instead!"}
#define sscanf {"Unsafe! Use sscanf_s instead!"}
#define strncat {"Unsafe! Use strncat_s instead!"}
You can create such a header (let's call it force_safe.h
) and include it in the beginning of every source file. In GCC you can also do this in the compiler flags (eg. gcc -iforce_safe.h ...
).