]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
lib/string/sprintf/, tests/: xaprintf(): Reimplement in terms of exit_if_null()
authorAlejandro Colomar <alx@kernel.org>
Sun, 8 Dec 2024 11:21:06 +0000 (12:21 +0100)
committerIker Pedrosa <ikerpedrosam@gmail.com>
Mon, 27 Oct 2025 13:32:06 +0000 (14:32 +0100)
Signed-off-by: Alejandro Colomar <alx@kernel.org>
lib/string/sprintf/xaprintf.c
lib/string/sprintf/xaprintf.h
tests/unit/Makefile.am

index 81a3df2005e712849fe18036cc0a5d857db279cc..87617e768607a47617daddb56e7fe31924dfc216 100644 (file)
@@ -5,9 +5,3 @@
 #include "config.h"
 
 #include "string/sprintf/xaprintf.h"
-
-#include <stdarg.h>
-
-
-extern inline char *xaprintf(const char *restrict fmt, ...);
-extern inline char *xvaprintf(const char *restrict fmt, va_list ap);
index 71b262c9af178205953663ec13f078bc31750088..6b23385c276ffef58378cc37f09a756a1263b88c 100644 (file)
@@ -8,52 +8,12 @@
 
 #include "config.h"
 
-#include <stdarg.h>
-#include <stddef.h>
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "attr.h"
 #include "string/sprintf/aprintf.h"
-
-
-ATTR_MALLOC(free)
-format_attr(printf, 1, 2)
-inline char *xaprintf(const char *restrict fmt, ...);
-
-ATTR_MALLOC(free)
-format_attr(printf, 1, 0)
-inline char *xvaprintf(const char *restrict fmt, va_list ap);
+#include "exit_if_null.h"
 
 
 // exit-on-error allocate print formatted
-inline char *
-xaprintf(const char *restrict fmt, ...)
-{
-       char     *p;
-       va_list  ap;
-
-       va_start(ap, fmt);
-       p = xvaprintf(fmt, ap);
-       va_end(ap);
-
-       return p;
-}
-
-
-inline char *
-xvaprintf(const char *restrict fmt, va_list ap)
-{
-       char  *p;
-
-       p = vaprintf(fmt, ap);
-       if (p == NULL) {
-               perror("vaprintf");
-               exit(EXIT_FAILURE);
-       }
-
-       return p;
-}
+#define xaprintf(...)  exit_if_null(aprintf(__VA_ARGS__))
 
 
 #endif  // include guard
index 64470f46254f21d003ed412afc517214153823cb..8de0a0e0b0464a8d8a28c576a4077a17d2ba96d3 100644 (file)
@@ -130,6 +130,8 @@ test_typetraits_LDADD = \
     $(NULL)
 
 test_xaprintf_SOURCES = \
+    ../../lib/exit_if_null.c \
+    ../../lib/shadowlog.c \
     ../../lib/string/sprintf/aprintf.c \
     ../../lib/string/sprintf/xaprintf.c \
     ../../lib/string/strcmp/streq.c \