]> git.ipfire.org Git - thirdparty/shadow.git/commit
lib/: exit_if_null(): Add macro to exit(3) on error
authorAlejandro Colomar <alx@kernel.org>
Tue, 5 Dec 2023 12:46:23 +0000 (13:46 +0100)
committerIker Pedrosa <ikerpedrosam@gmail.com>
Mon, 27 Oct 2025 13:32:06 +0000 (14:32 +0100)
commit90da3213e80a8033d8672715a8c2807540d4c7d6
treec59f805e69862c077b2720a839f36ad1f88f47e6
parent8f0fa6ddffcf60499aec34a9fc4a89c3ec9b0106
lib/: exit_if_null(): Add macro to exit(3) on error

Writing an x*() variant function of several functions is unnecessary.
It's simpler to write a generic exit_if_null() macro that can be chained
with any other calls.  With such a macro, the x*() variants can be
implemented as one-liner macros that are much easier to read:

For example:

#define xmalloc(size)  exit_if_null(malloc(size))

If an error is detected, log an error, and exit(13).  About why 13, I
don't really know.  It's just what was used previously in xmalloc().

Signed-off-by: Alejandro Colomar <alx@kernel.org>
lib/Makefile.am
lib/exit_if_null.c [new file with mode: 0644]
lib/exit_if_null.h [new file with mode: 0644]