Files
mem/tests/02_calloc.c

31 lines
752 B
C
Raw Normal View History

2026-02-15 11:54:20 -06:00
#define DEBUG
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include "../include/mem.h"
int mem_is_zero(const void *ptr, size_t nbytes) {
assert(ptr);
assert(nbytes > 0);
static const unsigned char zero_block[1024] = {0};
while (nbytes >= sizeof(zero_block)) {
if (memcmp(ptr, zero_block, sizeof(zero_block)) != 0)
return 0;
ptr = (const unsigned char *)ptr + sizeof(zero_block);
nbytes -= sizeof(zero_block);
}
if (nbytes > 0 && memcmp(ptr, zero_block, nbytes) != 0)
return 0;
return 1;
}
int main(void){
size_t nbytes = 20;
void *ptr = ALLOC(NOZERO, nbytes);
assert(ptr != NULL);
assert( !mem_is_zero(ptr, nbytes));
return EXIT_SUCCESS;
}