summaryrefslogtreecommitdiff
path: root/bittorrent/epoll_server/utils/xalloc.c
diff options
context:
space:
mode:
authorMartial Simon <msimon_fr@hotmail.com>2025-09-15 01:07:58 +0200
committerMartial Simon <msimon_fr@hotmail.com>2025-09-15 01:07:58 +0200
commit967be9e750221ab2ab783f95df79bb26d290a45e (patch)
tree6802900a5e975f9f68b169f0f503f040056d6952 /bittorrent/epoll_server/utils/xalloc.c
add: added projectsHEADmain
Diffstat (limited to 'bittorrent/epoll_server/utils/xalloc.c')
-rw-r--r--bittorrent/epoll_server/utils/xalloc.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/bittorrent/epoll_server/utils/xalloc.c b/bittorrent/epoll_server/utils/xalloc.c
new file mode 100644
index 0000000..e4dc6b8
--- /dev/null
+++ b/bittorrent/epoll_server/utils/xalloc.c
@@ -0,0 +1,31 @@
+#include "xalloc.h"
+
+#include <err.h>
+#include <stdlib.h>
+
+void *xmalloc(size_t size)
+{
+ void *res = malloc(size);
+ if (!res)
+ err(EXIT_FAILURE, "Impossible to malloc");
+
+ return res;
+}
+
+void *xcalloc(size_t nmemb, size_t size)
+{
+ void *res = calloc(nmemb, size);
+ if (!res)
+ err(EXIT_FAILURE, "Impossible to calloc");
+
+ return res;
+}
+
+void *xrealloc(void *ptr, size_t size)
+{
+ void *res = realloc(ptr, size);
+ if (!res)
+ err(EXIT_FAILURE, "Impossible to realloc");
+
+ return res;
+}