summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Hindoe Paaboel Andersen <phomes@gmail.com>2013-02-07 00:15:27 +0100
committerThomas Hindoe Paaboel Andersen <phomes@gmail.com>2013-02-07 00:38:09 +0100
commit7c2d80944afb4196f2eff614e8da1450dffcbeaa (patch)
tree5cdf18700cdfd9471eaee67e78661b286b9c98f2
parentfa3cd7394c227ad38c5c09b2bc2d035e7fb14a76 (diff)
strv: add strv_print
Clearer, and spares the temp variable.
-rw-r--r--src/locale/localectl.c9
-rw-r--r--src/shared/strv.c10
-rw-r--r--src/shared/strv.h1
-rw-r--r--src/test/test-env-replace.c12
-rw-r--r--src/timedate/timedatectl.c4
5 files changed, 17 insertions, 19 deletions
diff --git a/src/locale/localectl.c b/src/locale/localectl.c
index 290edcc103..8c3c8e3f0f 100644
--- a/src/locale/localectl.c
+++ b/src/locale/localectl.c
@@ -432,7 +432,6 @@ static int add_locales_from_libdir (Set *locales) {
static int list_locales(DBusConnection *bus, char **args, unsigned n) {
_cleanup_set_free_ Set *locales;
_cleanup_strv_free_ char **l = NULL;
- char **j;
int r;
locales = set_new(string_hash_func, string_compare_func);
@@ -455,8 +454,7 @@ static int list_locales(DBusConnection *bus, char **args, unsigned n) {
pager_open_if_enabled();
- STRV_FOREACH(j, l)
- puts(*j);
+ strv_print(l);
return 0;
}
@@ -539,7 +537,6 @@ static int nftw_cb(
static int list_vconsole_keymaps(DBusConnection *bus, char **args, unsigned n) {
char _cleanup_strv_free_ **l = NULL;
- char **i;
keymaps = set_new(string_hash_func, string_compare_func);
if (!keymaps)
@@ -566,9 +563,7 @@ static int list_vconsole_keymaps(DBusConnection *bus, char **args, unsigned n) {
pager_open_if_enabled();
- STRV_FOREACH(i, l)
- puts(*i);
-
+ strv_print(l);
return 0;
}
diff --git a/src/shared/strv.c b/src/shared/strv.c
index 2d556f4a07..fc6104ffea 100644
--- a/src/shared/strv.c
+++ b/src/shared/strv.c
@@ -774,3 +774,13 @@ char **strv_sort(char **l) {
qsort(l, strv_length(l), sizeof(char*), str_compare);
return l;
}
+
+void strv_print(char **l) {
+ char **s;
+
+ if (!l)
+ return;
+
+ STRV_FOREACH(s, l)
+ puts(*s);
+}
diff --git a/src/shared/strv.h b/src/shared/strv.h
index fd728eff81..33c752a313 100644
--- a/src/shared/strv.h
+++ b/src/shared/strv.h
@@ -87,3 +87,4 @@ bool strv_overlap(char **a, char **b);
char **strv_sort(char **l);
+void strv_print(char **l);
diff --git a/src/test/test-env-replace.c b/src/test/test-env-replace.c
index cd596a6e16..ad5c991608 100644
--- a/src/test/test-env-replace.c
+++ b/src/test/test-env-replace.c
@@ -58,10 +58,7 @@ int main(int argc, char *argv[]) {
strv_free(a);
r = replace_env_argv((char**) line, (char**) env);
-
- STRV_FOREACH(i, r)
- printf("%s\n", *i);
-
+ strv_print(r);
strv_free(r);
t = normalize_env_assignment("foo=bar");
@@ -127,16 +124,13 @@ int main(int argc, char *argv[]) {
strv_free(a);
strv_free(b);
- STRV_FOREACH(i, r)
- printf("%s\n", *i);
+ strv_print(r);
printf("CLEANED UP:\n");
r = strv_env_clean(r);
- STRV_FOREACH(i, r)
- printf("%s\n", *i);
-
+ strv_print(r);
strv_free(r);
return 0;
diff --git a/src/timedate/timedatectl.c b/src/timedate/timedatectl.c
index 281c0524da..f5b5f0ca84 100644
--- a/src/timedate/timedatectl.c
+++ b/src/timedate/timedatectl.c
@@ -425,7 +425,6 @@ static int list_timezones(DBusConnection *bus, char **args, unsigned n) {
_cleanup_fclose_ FILE *f = NULL;
_cleanup_strv_free_ char **zones = NULL;
size_t n_zones = 0;
- char **i;
assert(args);
assert(n == 1);
@@ -487,8 +486,7 @@ static int list_timezones(DBusConnection *bus, char **args, unsigned n) {
pager_open_if_enabled();
strv_sort(zones);
- STRV_FOREACH(i, zones)
- puts(*i);
+ strv_print(zones);
return 0;
}