mem/tests/03_calloc.c
2025-07-19 13:46:13 -05:00

29 lines
590 B
C

#define DEBUG
#include "../include/except.h"
#include "../include/mem.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#define BUFSZ 100
static bool isZeroed(void *memory, unsigned int size)
{
unsigned char *mm = (unsigned char*)memory;
// early out for empty size
if (size == 0) return true;
return (*mm == 0) && memcmp(mm, mm + 1, size - 1) == 0;
}
int main(void){
char *buf = CALLOC(BUFSZ, sizeof(char *), 0);
ASSERTED(buf != NULL);
ASSERTED(isZeroed(buf, BUFSZ) == true);
FREE(buf);
return EXIT_SUCCESS;
}