/* SPDX-License-Identifier: GPL-2.0-only */
#ifndef LABWC_ARRAY_H
#define LABWC_ARRAY_H
-#include <stdio.h>
-#include <stdlib.h>
+
#include <wayland-server-core.h>
+#include "common/mem.h"
/*
* Wayland's wl_array API is a bit sparse consisting only of
#define array_add(_arr, _val) do { \
__typeof__(_val) *_entry = wl_array_add( \
(_arr), sizeof(__typeof__(_val))); \
- if (!_entry) { \
- perror("Failed to allocate memory"); \
- exit(EXIT_FAILURE); \
- } \
+ die_if_null(_entry); \
*_entry = (_val); \
} while (0)
#include <stdlib.h>
+/*
+ * If ptr is NULL, prints an error (based on errno) and exits.
+ * Suitable for checking the return value of malloc() etc.
+ */
+void die_if_null(void *ptr);
+
/*
* As defined in busybox, weston, etc.
* Allocates zero-filled memory; calls exit() on error.