diff options
author | Lennart Poettering <lennart@poettering.net> | 2021-08-10 14:37:00 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2021-08-10 14:55:50 +0200 |
commit | d8782cc5c22d83f4a4305f40d85a84f47c89f314 (patch) | |
tree | 2d012faf17df919ae3db288fe8ecd96b4250b438 /src/basic/memory-util.h | |
parent | b2efed520b51f71484e45289f9f34b611838cd4a (diff) | |
download | systemd-d8782cc5c22d83f4a4305f40d85a84f47c89f314.tar.gz |
memory-util: add mempmem_safe()
This is like memmem_safe() but returns a pointer after the needle,
instead to the beginning of the needle.
This is then used at one place. Not much, but it makes me sleep safer at
night, as it avoids the manual counting done so far.
Diffstat (limited to 'src/basic/memory-util.h')
-rw-r--r-- | src/basic/memory-util.h | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/basic/memory-util.h b/src/basic/memory-util.h index 0b04278ab4..e2b543cb8f 100644 --- a/src/basic/memory-util.h +++ b/src/basic/memory-util.h @@ -71,6 +71,16 @@ static inline void *memmem_safe(const void *haystack, size_t haystacklen, const return memmem(haystack, haystacklen, needle, needlelen); } +static inline void *mempmem_safe(const void *haystack, size_t haystacklen, const void *needle, size_t needlelen) { + const uint8_t *p; + + p = memmem_safe(haystack, haystacklen, needle, needlelen); + if (!p) + return NULL; + + return (uint8_t*) p + needlelen; +} + #if HAVE_EXPLICIT_BZERO static inline void* explicit_bzero_safe(void *p, size_t l) { if (l > 0) |