MEM: add ntru_calloc() function

This commit is contained in:
hasufell 2014-05-25 18:59:58 +02:00
parent 286c300890
commit fc1ac808a2
No known key found for this signature in database
GPG Key ID: 220CD1C5BDEED020
2 changed files with 25 additions and 0 deletions

View File

@ -53,3 +53,26 @@ void *ntru_malloc(size_t size)
return ptr;
}
/**
* Allocate memory of size and return
* a void pointer. The memory is zeroed.
*
* @param nmemb amount of blocks to allocate
* @param size of the memory blocks to allocate in bytes
* @return void pointer to the beginning of the allocated memory block
*/
void *ntru_calloc(size_t nmemb, size_t size)
{
void *ptr;
ptr = calloc(nmemb, size);
if (size)
if (!ptr) {
fprintf(stderr, "failed to allocate memory, aborting!");
abort();
}
return ptr;
}

View File

@ -31,5 +31,7 @@
#include <stdlib.h>
void *ntru_malloc(size_t size);
void *ntru_calloc(size_t nmemb, size_t size);
#endif /* NTRU_MEM_H */