This name better reflects that it handles arrays, and doesn't shout.
This case is slightly different, as this macro does a little bit more
than just enforcing arrays. It changes the return value too. However,
that is related-enough to the handling of arrays that I'm inclined to
accept it as a minor inconsistency.
Signed-off-by: Alejandro Colomar <alx@kernel.org>
stpsep(buf, "\n");
- if (STRSEP2ARR(buf, ":", fields) == -1)
+ if (strsep2arr_a(buf, ":", fields) == -1)
goto next;
/*
stpsep(dup, "\n");
- if (STRSEP2ARR(dup, ":", fields) == -1)
+ if (strsep2arr_a(dup, ":", fields) == -1)
return NULL;
if (streq(fields[2], ""))
stpsep(dup, "\n");
- if (STRSEP2ARR(dup, ":", fields) == -1)
+ if (strsep2arr_a(dup, ":", fields) == -1)
return NULL;
sgroup.sg_namp = fields[0];
stpsep(dup, "\n");
- if (STRSEP2ARR(dup, ":", fields) == -1)
+ if (strsep2arr_a(dup, ":", fields) == -1)
return NULL;
/*
Loop around strsep(3) to fill an array of buffers with all
the delimited strings that have been split.
Useful when the number of delimiter-separated fields is known.
- STRSEP2ARR()
+ strsep2arr_a()
Like strsep2arr(), but take an array, and simplify error checks.
strsep2ls()
#include "sizeof.h"
-#define STRSEP2ARR(s, delim, a) \
+// strsep2arr_a - string separate to array-of-strings array
+#define strsep2arr_a(s, delim, a) \
( \
strsep2arr(s, delim, countof(a), a) == countof(a) ? 0 : -1 \
)
size_t n, char *a[restrict n]);
-// string separate to array-of-strings
-// strsep(3) a string into an array of strings.
-// Return the number of fields in the string, or -1 on error.
+// strsep2arr - string separate to array-of-strings
inline ssize_t
strsep2arr(char *s, const char *restrict delim, size_t n, char *a[restrict n])
{
return NULL; /* fail if too long */
strcpy (rangebuf, line);
- if (STRSEP2ARR(rangebuf, ":", fields) == -1)
+ if (strsep2arr_a(rangebuf, ":", fields) == -1)
return NULL;
if (streq(fields[0], ""))
fail_exit (EXIT_FAILURE, process_selinux);
}
- if (STRSEP2ARR(buf, ":", fields) == -1) {
+ if (strsep2arr_a(buf, ":", fields) == -1) {
fprintf (stderr, _("%s: line %jd: invalid line\n"),
Prog, line);
fail_exit (EXIT_FAILURE, process_selinux);