summaryrefslogtreecommitdiff
path: root/memory.c
blob: 1afa475b9a0b5760960947c7ea2c38b2284261b1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <stdio.h>
#include "memory.h"

#undef memdup

void* memdup(void *buf, size_t num){
	if(buf == NULL) return NULL;
	char *buf2 = malloc(num, char);
	memcpy(buf2, buf, num);
	return (void*)buf2;
}

void* check_after_allocation(const char *funcname, void *ptr){
	if(ptr == NULL){
		perror(funcname);
		exit(1);
	}
	return ptr;
}