3 void *malloc_chk(size_t size, const char *tag)
7 if((p = malloc(size)) == NULL) {
8 fprintf(stderr, "%s: cannot allocate memory\n", tag);
11 return memset(p, 0, size);
14 void *calloc_chk(size_t nmemb, size_t size, char *tag)
18 if((p = calloc(nmemb, size)) == NULL) {
19 fprintf(stderr, "%s: cannot allocate memory\n", tag);
25 char *strdup_chk(const char *s, char *tag)
30 t = malloc_chk(strlen(s) + 1, tag);
35 char *strndup_chk(const char *s, size_t len, char *tag)
40 t = malloc_chk(len + 1, tag);