diff options
author | Ray Strode <rstrode@redhat.com> | 2016-08-09 10:20:22 -0400 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2017-02-20 23:32:53 -0500 |
commit | 4bed076c5f79ce26451ea3d73950d895f630f9a7 (patch) | |
tree | 2dfddadab7401f9ac55bc73cbe52d6fd5349677a /src/basic/env-util.c | |
parent | 51e76f7cd137bd57c035f96f447c08991226999d (diff) | |
download | systemd-4bed076c5f79ce26451ea3d73950d895f630f9a7.tar.gz |
basic: add replace_env_n function
It's like replace_env, but lets you pass in a substring.
Diffstat (limited to 'src/basic/env-util.c')
-rw-r--r-- | src/basic/env-util.c | 6 |
1 files changed, 4 insertions, 2 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; |