diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/extlib.c | 18 | ||||
-rw-r--r-- | src/extlib.h | 6 |
2 files changed, 20 insertions, 4 deletions
diff --git a/src/extlib.c b/src/extlib.c index ee20d3e..151a74f 100644 --- a/src/extlib.c +++ b/src/extlib.c @@ -27,10 +27,11 @@ #undef malloc void -free_secure(void *__ptr, size_t ptrlen) +free_secure(void **__ptr, size_t ptrlen) { - memset (__ptr, 0, ptrlen); - free (__ptr); + memset (*__ptr, 0, ptrlen); + free (*__ptr); + *__ptr = NULL; return; } @@ -42,6 +43,16 @@ malloc_secure (size_t len) return mem; } +int +memvcmp (void *str, + char val, + size_t n) +{ + char str2[n]; + memset (str2, val, n); + return memcmp (str, str2, n); +} + void fcopy(FILE *f1, FILE *f2) { @@ -54,5 +65,6 @@ fcopy(FILE *f1, FILE *f2) fprintf (stderr, "Failed to copy data"); return; } + fflush (f2); } } diff --git a/src/extlib.h b/src/extlib.h index 1948352..15903c3 100644 --- a/src/extlib.h +++ b/src/extlib.h @@ -25,7 +25,7 @@ #define malloc(x) error - use malloc_secure /// Automatically zero out a pointer before freeing it -void free_secure (void *__ptr, size_t ptrlen); +void free_secure (void **__ptr, size_t ptrlen); /// Automatically initialise the allocated memory with zeros void *malloc_secure (size_t len); @@ -33,6 +33,10 @@ void *malloc_secure (size_t len); /// Copy the data of one filestream to another void fcopy(FILE *f1, FILE *f2); +/// Compare the first n bytes of a memory area str to the value val. +/// Returns 0 if the values the same, any other value if they are not the same. +int memvcmp (void *str, char val, size_t n); + /// Convert a string to lowercase char *strlwr(char *s); |