This name better reflects that it handles arrays, and doesn't shout.
Signed-off-by: Alejandro Colomar <alx@kernel.org>
strndupa_a()
Like strndupa(3), but takes an array.
- STRNDUP()
+ strndup_a()
Like strndup(3), but takes an array.
m/
#include "exit_if_null.h"
-// Similar to strndup(3), but ensure that 's' is an array.
-#define STRNDUP(s) strndup(s, countof(s))
+// strndup_a - nonstring duplicate-into-string array
+#define strndup_a(s) strndup(s, countof(s))
-// exit-on-error nonstring duplicate-into-string
-#define XSTRNDUP(s) exit_if_null(STRNDUP(s))
+// xstrndup_a - exit-on-error nonstring duplicate-into-string array
+#define xstrndup_a(s) exit_if_null(strndup_a(s))
#endif // include guard
#if defined(HAVE_STRUCT_UTMPX_UT_HOST)
if ((ut != NULL) && !STRNEQ(ut->ut_host, "")) {
- *out = XSTRNDUP(ut->ut_host);
+ *out = xstrndup_a(ut->ut_host);
} else {
*out = NULL;
ret = -2;
hostname = xstrdup(host);
#if defined(HAVE_STRUCT_UTMPX_UT_HOST)
else if (NULL != ut && !STRNEQ(ut->ut_host, ""))
- hostname = XSTRNDUP(ut->ut_host);
+ hostname = xstrndup_a(ut->ut_host);
#endif
line = strprefix(line, "/dev/") ?: line;