xalloc impl...maybe. needs testing.
This commit is contained in:
@@ -13,7 +13,6 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
void* ni_xmalloc(size_t size);
|
||||
void ni_free(void* ptr);
|
||||
|
||||
void* ni_xcalloc(size_t nmemb,size_t size);
|
||||
void* ni_xrealloc(void* ptr, size_t size);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include <sys/types.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
@@ -8,25 +9,56 @@
|
||||
#include "nickel/xalloc.h"
|
||||
|
||||
void* ni_xmalloc(size_t size) {
|
||||
void* retptr = malloc(size);
|
||||
|
||||
if (retptr != NULL) {
|
||||
return retptr;
|
||||
} else {
|
||||
perror("xmalloc failed");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
void ni_free(void* ptr) {
|
||||
|
||||
}
|
||||
|
||||
void* ni_xcalloc(size_t nmemb,size_t size) {
|
||||
void* retptr = calloc(nmemb, size);
|
||||
|
||||
if (retptr != NULL) {
|
||||
return retptr;
|
||||
} else {
|
||||
perror("xcalloc failed");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
void* ni_xrealloc(void* ptr, size_t size) {
|
||||
void* retptr = realloc(ptr, size);
|
||||
|
||||
if (retptr != NULL) {
|
||||
return retptr;
|
||||
} else {
|
||||
perror("xrealloc failed");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
char* ni_xstrdup(const char *s) {
|
||||
void* dupstr = strdup(s);
|
||||
|
||||
if (dupstr != NULL) {
|
||||
return dupstr;
|
||||
} else {
|
||||
perror("xdupstr failed");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
char* ni_xstrndup(const char s[], size_t n) {
|
||||
void* dupstr = strndup(s, n);
|
||||
|
||||
if (dupstr != NULL) {
|
||||
return dupstr;
|
||||
} else {
|
||||
perror("xdupstr failed");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user