Skip to content
Permalink
e6ed782914
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
33 lines (27 sloc) 724 Bytes
#ifndef _XMALLOC_H
#define _XMALLOC_H 1
#include <stdio.h>
#include <stdlib.h>
__attribute__ ((noreturn, unused)) static void out_of_memory(void) {
fprintf(stderr,"out of memory\n");
abort();
}
__attribute__ ((unused)) static void *xmalloc(size_t size) {
void *ptr = malloc(size);
if (ptr == NULL)
out_of_memory();
return(ptr);
}
__attribute__ ((unused)) static void *xrealloc(void *ptr, size_t size) {
void *outptr = realloc(ptr, size);
if (outptr == NULL)
out_of_memory();
return(outptr);
}
__attribute__ ((unused)) static char *xstrndup(const char *s, size_t n) {
char *ptr = strndup(s, n);
if (ptr == NULL)
out_of_memory();
return(ptr);
}
#endif