#include "c.h"
-char **strv_free(char **l);
-void strv_clear(char **l);
-char **strv_copy(char * const *l);
-unsigned strv_length(char * const *l);
+char **ul_strv_free(char **l);
+char **ul_strv_copy(char * const *l);
+unsigned ul_strv_length(char * const *l);
-int strv_extend_strv(char ***a, char **b);
-int strv_extend_strv_concat(char ***a, char **b, const char *suffix);
-int strv_extend(char ***l, const char *value);
+int ul_strv_extend_strv(char ***a, char **b);
+int ul_strv_extend_strv_concat(char ***a, char **b, const char *suffix);
+int ul_strv_extend(char ***l, const char *value);
-int strv_extendv(char ***l, const char *format, va_list ap)
+int ul_strv_extendv(char ***l, const char *format, va_list ap)
__attribute__ ((__format__ (__printf__, 2, 0)));
-int strv_extendf(char ***l, const char *format, ...)
+int ul_strv_extendf(char ***l, const char *format, ...)
__attribute__ ((__format__ (__printf__, 2, 3)));
-int strv_push(char ***l, char *value);
-int strv_push_prepend(char ***l, char *value);
-int strv_consume(char ***l, char *value);
-int strv_consume_prepend(char ***l, char *value);
+int ul_strv_push(char ***l, char *value);
+int ul_strv_push_prepend(char ***l, char *value);
+int ul_strv_consume(char ***l, char *value);
+int ul_strv_consume_prepend(char ***l, char *value);
-char **strv_remove(char **l, const char *s);
+char **ul_strv_remove(char **l, const char *s);
-char **strv_new(const char *x, ...);
+char **ul_strv_new(const char *x, ...);
-static inline const char* STRV_IFNOTNULL(const char *x) {
+static inline const char* UL_STRV_IFNOTNULL(const char *x) {
return x ? x : (const char *) -1;
}
-static inline int strv_isempty(char * const *l) {
+static inline int ul_strv_isempty(char * const *l) {
return !l || !*l;
}
-char **strv_split(const char *s, const char *separator);
-char *strv_join(char **l, const char *separator);
+char **ul_strv_split(const char *s, const char *separator);
+char *ul_strv_join(char **l, const char *separator);
-#define STRV_FOREACH(s, l) \
+#define UL_STRV_FOREACH(s, l) \
for ((s) = (l); (s) && *(s); (s)++)
-#define STRV_FOREACH_BACKWARDS(s, l) \
- STRV_FOREACH(s, l) \
+#define UL_STRV_FOREACH_BACKWARDS(s, l) \
+ UL_STRV_FOREACH(s, l) \
; \
for ((s)--; (l) && ((s) >= (l)); (s)--)
-#define STRV_MAKE_EMPTY ((char*[1]) { NULL })
+#define UL_STRV_MAKE_EMPTY ((char*[1]) { NULL })
-char **strv_reverse(char **l);
+char **ul_strv_reverse(char **l);
#endif /* UTIL_LINUX_STRV */
if (!str)
return ls;
- all = strv_split(str, ",");
+ all = ul_strv_split(str, ",");
if (!all)
return ls;
- STRV_FOREACH(name, all)
+ UL_STRV_FOREACH(name, all)
ls = env_list_add_getenv(ls, *name, NULL);
- strv_free(all);
+ ul_strv_free(all);
return ls;
}
#include "strutils.h"
#include "strv.h"
-void strv_clear(char **l) {
+static void ul_strv_clear(char **l) {
char **k;
if (!l)
*l = NULL;
}
-char **strv_free(char **l) {
- strv_clear(l);
+char **ul_strv_free(char **l) {
+ ul_strv_clear(l);
free(l);
return NULL;
}
-char **strv_copy(char * const *l) {
+char **ul_strv_copy(char * const *l) {
char **r, **k;
- k = r = malloc(sizeof(char *) * (strv_length(l) + 1));
+ k = r = malloc(sizeof(char *) * (ul_strv_length(l) + 1));
if (!r)
return NULL;
for (; *l; k++, l++) {
*k = strdup(*l);
if (!*k) {
- strv_free(r);
+ ul_strv_free(r);
return NULL;
}
}
return r;
}
-unsigned strv_length(char * const *l) {
+unsigned ul_strv_length(char * const *l) {
unsigned n = 0;
if (!l)
return n;
}
-static char **strv_new_ap(const char *x, va_list ap) {
+static char **ul_strv_new_ap(const char *x, va_list ap) {
const char *s;
char **a;
unsigned n = 0, i = 0;
/* As a special trick we ignore all listed strings that equal
* (const char*) -1. This is supposed to be used with the
- * STRV_IFNOTNULL() macro to include possibly NULL strings in
+ * UL_STRV_IFNOTNULL() macro to include possibly NULL strings in
* the string list. */
if (x) {
return a;
fail:
- strv_free(a);
+ ul_strv_free(a);
return NULL;
}
-char **strv_new(const char *x, ...) {
+char **ul_strv_new(const char *x, ...) {
char **r;
va_list ap;
va_start(ap, x);
- r = strv_new_ap(x, ap);
+ r = ul_strv_new_ap(x, ap);
va_end(ap);
return r;
}
-int strv_extend_strv(char ***a, char **b) {
+int ul_strv_extend_strv(char ***a, char **b) {
int r;
char **s;
- STRV_FOREACH(s, b) {
- r = strv_extend(a, *s);
+ UL_STRV_FOREACH(s, b) {
+ r = ul_strv_extend(a, *s);
if (r < 0)
return r;
}
return 0;
}
-int strv_extend_strv_concat(char ***a, char **b, const char *suffix) {
+int ul_strv_extend_strv_concat(char ***a, char **b, const char *suffix) {
int r;
char **s;
- STRV_FOREACH(s, b) {
+ UL_STRV_FOREACH(s, b) {
char *v;
v = strconcat(*s, suffix);
if (!v)
return -ENOMEM;
- r = strv_push(a, v);
+ r = ul_strv_push(a, v);
if (r < 0) {
free(v);
return r;
_FOREACH_WORD(word, length, s, separator, false, state)
-char **strv_split(const char *s, const char *separator) {
+char **ul_strv_split(const char *s, const char *separator) {
const char *word, *state;
size_t l;
unsigned n, i;
FOREACH_WORD_SEPARATOR(word, l, s, separator, state) {
r[i] = strndup(word, l);
if (!r[i]) {
- strv_free(r);
+ ul_strv_free(r);
return NULL;
}
return r;
}
-char *strv_join(char **l, const char *separator) {
+char *ul_strv_join(char **l, const char *separator) {
char *r, *e;
char **s;
size_t n, k;
k = strlen(separator);
n = 0;
- STRV_FOREACH(s, l) {
+ UL_STRV_FOREACH(s, l) {
if (n != 0)
n += k;
n += strlen(*s);
return NULL;
e = r;
- STRV_FOREACH(s, l) {
+ UL_STRV_FOREACH(s, l) {
if (e != r)
e = stpcpy(e, separator);
return r;
}
-int strv_push(char ***l, char *value) {
+int ul_strv_push(char ***l, char *value) {
char **c;
unsigned n, m;
if (!value)
return 0;
- n = strv_length(*l);
+ n = ul_strv_length(*l);
/* Increase and check for overflow */
m = n + 2;
return 0;
}
-int strv_push_prepend(char ***l, char *value) {
+int ul_strv_push_prepend(char ***l, char *value) {
char **c;
unsigned n, m, i;
if (!value)
return 0;
- n = strv_length(*l);
+ n = ul_strv_length(*l);
/* increase and check for overflow */
m = n + 2;
return 0;
}
-int strv_consume(char ***l, char *value) {
+int ul_strv_consume(char ***l, char *value) {
int r;
- r = strv_push(l, value);
+ r = ul_strv_push(l, value);
if (r < 0)
free(value);
return r;
}
-int strv_consume_prepend(char ***l, char *value) {
+int ul_strv_consume_prepend(char ***l, char *value) {
int r;
- r = strv_push_prepend(l, value);
+ r = ul_strv_push_prepend(l, value);
if (r < 0)
free(value);
return r;
}
-int strv_extend(char ***l, const char *value) {
+int ul_strv_extend(char ***l, const char *value) {
char *v;
if (!value)
if (!v)
return -ENOMEM;
- return strv_consume(l, v);
+ return ul_strv_consume(l, v);
}
-char **strv_remove(char **l, const char *s) {
+char **ul_strv_remove(char **l, const char *s) {
char **f, **t;
if (!l)
return l;
}
-int strv_extendf(char ***l, const char *format, ...) {
+int ul_strv_extendf(char ***l, const char *format, ...) {
va_list ap;
char *x;
int r;
if (r < 0)
return -ENOMEM;
- return strv_consume(l, x);
+ return ul_strv_consume(l, x);
}
-int strv_extendv(char ***l, const char *format, va_list ap) {
+int ul_strv_extendv(char ***l, const char *format, va_list ap) {
char *x;
int r;
if (r < 0)
return -ENOMEM;
- return strv_consume(l, x);
+ return ul_strv_consume(l, x);
}
-char **strv_reverse(char **l) {
+char **ul_strv_reverse(char **l) {
unsigned n, i;
- n = strv_length(l);
+ n = ul_strv_length(l);
if (n <= 1)
return l;
void mnt_context_reset_mesgs(struct libmnt_context *cxt)
{
DBG(CXT, ul_debug("reset messages"));
- strv_free(cxt->mesgs);
+ ul_strv_free(cxt->mesgs);
cxt->mesgs = NULL;
}
if (msg) {
DBG(CXT, ul_debug("mesg: '%s'", msg));
}
- return strv_extend(&cxt->mesgs, msg);
+ return ul_strv_extend(&cxt->mesgs, msg);
}
int mnt_context_sprintf_mesg(struct libmnt_context *cxt, const char *msg, ...)
va_list ap;
va_start(ap, msg);
- rc = strv_extendv(&cxt->mesgs, msg, ap);
+ rc = ul_strv_extendv(&cxt->mesgs, msg, ap);
va_end(ap);
return rc;
if (!cxt || !cxt->mesgs)
return 0;
- n = strv_length(cxt->mesgs);
+ n = ul_strv_length(cxt->mesgs);
if (n && type) {
n = 0;
- STRV_FOREACH(s, cxt->mesgs) {
+ UL_STRV_FOREACH(s, cxt->mesgs) {
if (*s && **s == type)
n++;
}
char **s;
int n = 0;
- if (!cxt || !buf || strv_isempty(cxt->mesgs))
+ if (!cxt || !buf || ul_strv_isempty(cxt->mesgs))
return;
- STRV_FOREACH(s, cxt->mesgs) {
+ UL_STRV_FOREACH(s, cxt->mesgs) {
size_t len;
if (!bufsz)
#include "pathnames.h"
#include "env.h"
#include "closestream.h"
-#include "strv.h"
#include "strutils.h"
#include "ttyutils.h"
#include "pwdutils.h"
sd = list_last_entry(ls, struct structured_data, sds);
- if (strv_extend(&sd->params, param))
+ if (ul_strv_extend(&sd->params, param))
err_oom();
}
sd = list_last_entry(ls, struct structured_data, sds);
va_start(ap, fmt);
- x = strv_extendv(&sd->params, fmt, ap);
+ x = ul_strv_extendv(&sd->params, fmt, ap);
va_end(ap);
if (x)
{
char *res, *tmp;
- if (strv_isempty(sd->params))
+ if (ul_strv_isempty(sd->params))
return NULL;
xasprintf(&res, "[%s %s]", sd->id,
- (tmp = strv_join(sd->params, " ")));
+ (tmp = ul_strv_join(sd->params, " ")));
free(tmp);
return res;
}
{
char **split;
- split = strv_split(param, "-");
- if (strv_length(split) > 2)
+ split = ul_strv_split(param, "-");
+ if (ul_strv_length(split) > 2)
errx(EXIT_FAILURE, _("Invalid parameter: %s"), param);
- if (strv_length(split) == 1)
+ if (ul_strv_length(split) == 1)
parse_single_param(desc, split[0]);
else
parse_range_param(desc, split[0], split[1]);
- strv_free(split);
+ ul_strv_free(split);
if (desc->start > desc->end)
errx(EXIT_FAILURE, _("Invalid range: %s"), param);
}
char **split;
size_t i;
- split = strv_split(ct->isa, "_");
+ split = ul_strv_split(ct->isa, "_");
/* Sort multi-letter extensions alphabetically */
- if (strv_length(split) > 1)
- qsort(&split[1], strv_length(split) - 1, sizeof(char *), riscv_cmp_func);
+ if (ul_strv_length(split) > 1)
+ qsort(&split[1], ul_strv_length(split) - 1, sizeof(char *), riscv_cmp_func);
/* Keep Base ISA and single-letter extensions at the start */
strcpy(ct->isa, split[0]);
- for (i = 1; i < strv_length(split); i++) {
+ for (i = 1; i < ul_strv_length(split); i++) {
strcat(ct->isa, " ");
strcat(ct->isa, split[i]);
}
- strv_free(split);
+ ul_strv_free(split);
}
}
/* Messages */
- STRV_FOREACH(s, mesgs) {
+ UL_STRV_FOREACH(s, mesgs) {
switch (type) {
case 'e':
if (!startswith(*s, "e "))
if (ss <= 0)
goto nothing;
buf[ss] = '\0';
- ctl->possible_modes = strv_split(buf, " \n");
+ ctl->possible_modes = ul_strv_split(buf, " \n");
close(fd);
}
return ctl->possible_modes;
size_t i;
char **modes = get_sys_power_states(ctl), **m;
- STRV_FOREACH(m, modes) {
+ UL_STRV_FOREACH(m, modes) {
if (strcmp(s, *m) == 0)
return SYSFS_MODE;
}
if (!modes)
errx(EXIT_FAILURE, _("could not read: %s"), SYS_POWER_STATE_PATH);
- STRV_FOREACH(m, modes)
+ UL_STRV_FOREACH(m, modes)
printf("%s ", *m);
for (i = 0; i < ARRAY_SIZE(rtcwake_mode_string); i++)
while ((sz = getline(&line, &dummy, f)) >= 0) {
if (rtrim_whitespace((unsigned char *) line) == 0)
continue;
- strv_consume(&wd->available_governors, line);
+ ul_strv_consume(&wd->available_governors, line);
dummy = 0;
line = NULL;
}
if (wd->governor)
printf(_("%-14s %s\n"), _("Pre-timeout governor:"), wd->governor);
if (wd->available_governors) {
- char *tmp = strv_join(wd->available_governors, " ");
+ char *tmp = ul_strv_join(wd->available_governors, " ");
if (tmp)
printf(_("%-14s %s\n"),
static void zram_reset_stat(struct zram *z)
{
if (z) {
- strv_free(z->mm_stat);
+ ul_strv_free(z->mm_stat);
z->mm_stat = NULL;
z->mm_stat_probed = 0;
}
if (!z->mm_stat && !z->mm_stat_probed) {
char *str = NULL;
if (ul_path_read_string(sysfs, &str, "mm_stat") > 0 && str) {
- z->mm_stat = strv_split(str, " ");
+ z->mm_stat = ul_strv_split(str, " ");
/* make sure kernel provides mm_stat as expected */
- if (strv_length(z->mm_stat) < ARRAY_SIZE(mm_stat_names)) {
- strv_free(z->mm_stat);
+ if (ul_strv_length(z->mm_stat) < ARRAY_SIZE(mm_stat_names)) {
+ ul_strv_free(z->mm_stat);
z->mm_stat = NULL;
}
}
errtryhelp(EXIT_FAILURE);
}
- ctl.command = strv_join(argv, " ");
+ ctl.command = ul_strv_join(argv, " ");
if (!ctl.command)
errx(EXIT_FAILURE, _("failed to concatenate arguments"));
{
char **str;
- STRV_FOREACH(str, ttys) {
+ UL_STRV_FOREACH(str, ttys) {
if (strcmp(*str, name) == 0)
return 1;
}
}
if (!(group_buf && !is_gr_member(name, group_buf))
&& sd_session_get_tty(sessions_list[i], &tty) >= 0
- && strv_consume(&ttys, tty) < 0)
+ && ul_strv_consume(&ttys, tty) < 0)
err(EXIT_FAILURE, _("failed to allocate lines list"));
free(name);
mem2strcpy(line, utmpptr->ut_line, sizeof(utmpptr->ut_line), sizeof(line));
if (has_tty(ttys, line))
continue;
- if (strv_extend(&ttys, line) < 0)
+ if (ul_strv_extend(&ttys, line) < 0)
err(EXIT_FAILURE, _("failed to allocate lines list"));
}
endutxent();
}
- STRV_FOREACH(str, ttys) {
+ UL_STRV_FOREACH(str, ttys) {
char *er = ttymsg(&iov, 1, *str, timeout);
if (er)
warnx("%s", er);
}
- strv_free(ttys);
+ ul_strv_free(ttys);
free(mbuf);
free_group_workspace(group_buf);
exit(EXIT_SUCCESS);
while (fgets(buf, sizeof(buf), stdin)) {
/* strip LF, CR, CRLF, LFCR */
rtrim_whitespace((unsigned char *)buf);
- if (strv_push(&stdin_lines, xstrdup(buf)) < 0)
+ if (ul_strv_push(&stdin_lines, xstrdup(buf)) < 0)
errx(EXIT_FAILURE, _("cannot allocate memory"));
}
- argc = strv_length(stdin_lines);
+ argc = ul_strv_length(stdin_lines);
argv = stdin_lines;
}
for (; argc > 0; argc--, argv++)
parse_mask_or_list(*argv, bits, width);
- strv_free(stdin_lines);
+ ul_strv_free(stdin_lines);
print_bits(bits, width, mode);
static char **split_or_error(const char *str, const char *errmsg)
{
- char **res = strv_split(str, ",");
+ char **res = ul_strv_split(str, ",");
if (!res) {
if (errno == ENOMEM)
err_oom();
if (ctl->tab_columns) {
char **opts;
- STRV_FOREACH(opts, ctl->tab_columns) {
+ UL_STRV_FOREACH(opts, ctl->tab_columns) {
struct libscols_column *cl;
cl = scols_table_new_column(ctl->tab, NULL, 0, 0);
} else if (ctl->tab_colnames) {
char **name;
- STRV_FOREACH(name, ctl->tab_colnames)
+ UL_STRV_FOREACH(name, ctl->tab_colnames)
scols_table_new_column(ctl->tab, *name, 0, 0);
} else
scols_table_enable_noheadings(ctl->tab, 1);
all = split_or_error(list, NULL);
if (all) {
- STRV_FOREACH(one, all) {
+ UL_STRV_FOREACH(one, all) {
if (strcmp(*one, "-") == 0) {
rc = 1;
break;
}
}
- strv_free(all);
+ ul_strv_free(all);
}
return rc;
all = split_or_error(list, errmsg);
/* apply to columns specified by name */
- STRV_FOREACH(one, all) {
+ UL_STRV_FOREACH(one, all) {
int low = 0, up = 0;
if (strcmp(*one, "-") == 0) {
if (cl)
column_set_flag(cl, flag);
}
- strv_free(all);
+ ul_strv_free(all);
/* apply flag to all columns without name */
if (unnamed) {
wanted = xcalloc(ncols, sizeof(struct libscols_column *));
- STRV_FOREACH(one, order) {
+ UL_STRV_FOREACH(one, order) {
struct libscols_column *cl = string_to_column(ctl, *one);
if (cl)
wanted[count++] = cl;
}
free(wanted);
- strv_free(order);
+ ul_strv_free(order);
}
static void create_tree(struct column_control *ctl)
switch(c) {
case 'C':
- if (strv_extend(&ctl.tab_columns, optarg))
+ if (ul_strv_extend(&ctl.tab_columns, optarg))
err_oom();
break;
case 'c':
scols_unref_table(ctl.tab);
if (ctl.tab_colnames)
- strv_free(ctl.tab_colnames);
+ ul_strv_free(ctl.tab_colnames);
if (ctl.tab_columns)
- strv_free(ctl.tab_columns);
+ ul_strv_free(ctl.tab_columns);
}
break;
case COLUMN_MODE_FILLCOLS: