diff options
author | Lennart Poettering <lennart@poettering.net> | 2023-04-14 12:48:14 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2023-04-14 16:56:15 +0200 |
commit | d791013ff529cbbb74d4cc5f1455f172befab1e6 (patch) | |
tree | a52a2742502f99537ba58cdae318336c89687aba /src/shared/edit-util.c | |
parent | bb7b1da8fedd9ba057809a8aca06594c56f0a409 (diff) | |
download | systemd-d791013ff529cbbb74d4cc5f1455f172befab1e6.tar.gz |
string-util: add strstrafter()
strstrafter() is like strstr() but returns a pointer to the first
character *after* the found substring, not on the substring itself.
Quite often this is what we actually want.
Inspired by #27267 I think it makes sense to add a helper for this,
to avoid the potentially fragile manual pointer increment afterwards.
Diffstat (limited to 'src/shared/edit-util.c')
-rw-r--r-- | src/shared/edit-util.c | 6 |
1 files changed, 2 insertions, 4 deletions
diff --git a/src/shared/edit-util.c b/src/shared/edit-util.c index 9fd74973aa..96ad721343 100644 --- a/src/shared/edit-util.c +++ b/src/shared/edit-util.c @@ -300,10 +300,8 @@ static int strip_edit_temp_file(EditFile *e) { assert(e->context->marker_end); - contents_start = strstr(old_contents, e->context->marker_start); - if (contents_start) - contents_start += strlen(e->context->marker_start); - else + contents_start = strstrafter(old_contents, e->context->marker_start); + if (!contents_start) contents_start = old_contents; contents_end = strstr(contents_start, e->context->marker_end); |