mirror of
https://github.com/labwc/labwc.git
synced 2025-10-31 22:25:34 -04:00
common: Add znew/znew_n() macros
This commit is contained in:
parent
da57483961
commit
a54d378e6c
26 changed files with 47 additions and 47 deletions
|
|
@ -11,6 +11,17 @@
|
|||
*/
|
||||
void *xzalloc(size_t size);
|
||||
|
||||
/*
|
||||
* Type-safe macros in the style of C++ new/new[].
|
||||
* <expr> may be either a type name or value expression.
|
||||
*
|
||||
* Examples:
|
||||
* struct wlr_box *box = znew(*box);
|
||||
* char *buf = znew_n(char, 80);
|
||||
*/
|
||||
#define znew(expr) ((__typeof__(expr) *)xzalloc(sizeof(expr)))
|
||||
#define znew_n(expr, n) ((__typeof__(expr) *)xzalloc((n) * sizeof(expr)))
|
||||
|
||||
/*
|
||||
* As defined in FreeBSD.
|
||||
* Like realloc(), but calls exit() on error.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue