#if !DEBUG
# define MEM_ALLOC_FAIL() do { \
fprintf (stderr, "%s: memory allocation failure\n", program_name); \
- exit (2); \
+ exit (EXIT_FAILURE); \
} while (false)
#else
# define MEM_ALLOC_FAIL_DEBUG(file, line) do { \
fprintf (stderr, "Memory allocation failure in source file %s, line %u\n", file, line); \
- exit (2); \
+ exit (EXIT_FAILURE); \
} while (false)
#endif
void *p = malloc (size);
if (!p)
MEM_ALLOC_FAIL_DEBUG (file, line);
+ vfprintf_diag ("malloc'ed %lu bytes [source file %s, line %u]", (unsigned long)size, file, line);
return p;
}
void *p = calloc (nmemb, size);
if (!p)
MEM_ALLOC_FAIL_DEBUG (file, line);
+ vfprintf_diag ("calloc'ed %lu bytes [source file %s, line %u]", (unsigned long)(nmemb * size), file, line);
return p;
}
void *p = realloc (ptr, size);
if (!p)
MEM_ALLOC_FAIL_DEBUG (file, line);
+ vfprintf_diag ("realloc'ed %lu bytes [source file %s, line %u]", (unsigned long)size, file, line);
return p;
}
#endif /* !DEBUG */