From 4bed076c5f79ce26451ea3d73950d895f630f9a7 Mon Sep 17 00:00:00 2001 From: Ray Strode Date: Tue, 9 Aug 2016 10:20:22 -0400 Subject: basic: add replace_env_n function It's like replace_env, but lets you pass in a substring. --- src/basic/env-util.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/basic/env-util.c') 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; -- cgit v1.2.3-54-g00ecf