mirror of
https://github.com/labwc/labwc.git
synced 2025-10-29 05:40:24 -04:00
array: use die_if_null() from common/mem.c
This commit is contained in:
parent
a29bf5366f
commit
e9f17dc4a2
3 changed files with 10 additions and 7 deletions
|
|
@ -1,9 +1,9 @@
|
|||
/* 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
|
||||
|
|
@ -66,10 +66,7 @@ wl_array_len(struct wl_array *array)
|
|||
#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)
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,12 @@
|
|||
|
||||
#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.
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
static void
|
||||
void
|
||||
die_if_null(void *ptr)
|
||||
{
|
||||
if (!ptr) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue