mirror of
https://github.com/Dr-Noob/cpufetch.git
synced 2026-03-24 23:40:39 +01:00
[v0.98] Use malloc/calloc wrapper that exits when alloc fails, as suggested by #90
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "global.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
@@ -68,3 +72,25 @@ void set_log_level(bool verbose) {
|
||||
int max(int a, int b) {
|
||||
return a > b ? a : b;
|
||||
}
|
||||
|
||||
void* emalloc(size_t size) {
|
||||
void* ptr = malloc(size);
|
||||
|
||||
if(ptr == NULL) {
|
||||
printErr("malloc failed: %s", strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void* ecalloc(size_t nmemb, size_t size) {
|
||||
void* ptr = calloc(nmemb, size);
|
||||
|
||||
if(ptr == NULL) {
|
||||
printErr("calloc failed: %s", strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
return ptr;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user