/* safe C library functions This upgrades unsafe C functions like "strcpy()" to safer equivalents, like "safe_strcpy()". NOTE: This is for maintaining a policy of "no unsafe functions" */ #include "util-safefunc.h" #include #include #include #include /** * Case-insensitive memcmp() */ #ifdef __GNUC__ int memcasecmp(const void *lhs, const void *rhs, size_t length) { int i; for (i=0; i= sizeof_dst) { dst[0] = 0; return; } else dst[i] = src[i]; } if (i >= sizeof_dst) { dst[0] = 0; return ; } else dst[i] = src[i]; return; } int safe_localtime(struct tm* _tm, const time_t *time) { struct tm *x; x = localtime(time); if (x == NULL) { memset(_tm, 0, sizeof(*_tm)); return -1; } memcpy(_tm, x, sizeof(*_tm)); return 0; } int safe_gmtime(struct tm* _tm, const time_t *time) { struct tm *x; x = gmtime(time); if (x == NULL) { memset(_tm, 0, sizeof(*_tm)); return -1; } memcpy(_tm, x, sizeof(*_tm)); return 0; }