summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/basic/env-util.c6
-rw-r--r--src/basic/env-util.h6
2 files changed, 9 insertions, 3 deletions
diff --git a/src/basic/env-util.c b/src/basic/env-util.c
index f370854673..1b955ff1d5 100644
--- a/src/basic/env-util.c
+++ b/src/basic/env-util.c
@@ -519,7 +519,7 @@ char **strv_env_clean_with_callback(char **e, void (*invalid_callback)(const cha
return e;
}
-char *replace_env(const char *format, char **env, unsigned flags) {
+char *replace_env_n(const char *format, size_t n, char **env, unsigned flags) {
enum {
WORD,
CURLY,
@@ -530,10 +530,11 @@ char *replace_env(const char *format, char **env, unsigned flags) {
const char *e, *word = format;
char *k;
_cleanup_free_ char *r = NULL;
+ size_t i;
assert(format);
- for (e = format; *e; e ++) {
+ for (e = format, i = 0; *e && i < n; e ++, i ++) {
switch (state) {
@@ -614,6 +615,7 @@ char *replace_env(const char *format, char **env, unsigned flags) {
r = k;
word = e--;
+ i--;
state = WORD;
}
break;
diff --git a/src/basic/env-util.h b/src/basic/env-util.h
index 03bbc6af00..43a1371f5e 100644
--- a/src/basic/env-util.h
+++ b/src/basic/env-util.h
@@ -34,9 +34,13 @@ enum {
REPLACE_ENV_ALLOW_BRACELESS = 2u,
};
-char *replace_env(const char *format, char **env, unsigned flags);
+char *replace_env_n(const char *format, size_t n, char **env, unsigned flags);
char **replace_env_argv(char **argv, char **env);
+static inline char *replace_env(const char *format, char **env, unsigned flags) {
+ return replace_env_n(format, strlen(format), env, flags);
+}
+
bool strv_env_is_valid(char **e);
#define strv_env_clean(l) strv_env_clean_with_callback(l, NULL, NULL)
char **strv_env_clean_with_callback(char **l, void (*invalid_callback)(const char *p, void *userdata), void *userdata);