summaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/path-lookup.c9
-rw-r--r--src/shared/strv.c25
-rw-r--r--src/shared/strv.h1
3 files changed, 33 insertions, 2 deletions
diff --git a/src/shared/path-lookup.c b/src/shared/path-lookup.c
index fa4995ceea..ffdc5367cb 100644
--- a/src/shared/path-lookup.c
+++ b/src/shared/path-lookup.c
@@ -41,21 +41,26 @@ DEFINE_STRING_TABLE_LOOKUP(systemd_running_as, SystemdRunningAs);
int user_config_home(char **config_home) {
const char *e;
+ char *r;
e = getenv("XDG_CONFIG_HOME");
if (e) {
- if (asprintf(config_home, "%s/systemd/user", e) < 0)
+ r = strappend(e, "/systemd/user");
+ if (!r)
return -ENOMEM;
+ *config_home = r;
return 1;
} else {
const char *home;
home = getenv("HOME");
if (home) {
- if (asprintf(config_home, "%s/.config/systemd/user", home) < 0)
+ r = strappend(home, "/.config/systemd/user");
+ if (!r)
return -ENOMEM;
+ *config_home = r;
return 1;
}
}
diff --git a/src/shared/strv.c b/src/shared/strv.c
index ec25755289..60c4762572 100644
--- a/src/shared/strv.c
+++ b/src/shared/strv.c
@@ -305,6 +305,31 @@ char **strv_split_quoted(const char *s) {
return r;
}
+char **strv_split_newlines(const char *s) {
+ char **l;
+ unsigned n;
+
+ assert(s);
+
+ /* Special version of strv_split() that splits on newlines and
+ * suppresses an empty string at the end */
+
+ l = strv_split(s, NEWLINE);
+ if (!l)
+ return NULL;
+
+ n = strv_length(l);
+ if (n <= 0)
+ return l;
+
+ if (isempty(l[n-1])) {
+ free(l[n-1]);
+ l[n-1] = NULL;
+ }
+
+ return l;
+}
+
char *strv_join(char **l, const char *separator) {
char *r, *e;
char **s;
diff --git a/src/shared/strv.h b/src/shared/strv.h
index b3802a7a3f..623f10216d 100644
--- a/src/shared/strv.h
+++ b/src/shared/strv.h
@@ -58,6 +58,7 @@ static inline bool strv_isempty(char **l) {
char **strv_split(const char *s, const char *separator) _malloc_;
char **strv_split_quoted(const char *s) _malloc_;
+char **strv_split_newlines(const char *s) _malloc_;
char *strv_join(char **l, const char *separator) _malloc_;