summaryrefslogtreecommitdiff
path: root/src/basic/memory-util.h
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2021-08-10 14:37:00 +0200
committerLennart Poettering <lennart@poettering.net>2021-08-10 14:55:50 +0200
commitd8782cc5c22d83f4a4305f40d85a84f47c89f314 (patch)
tree2d012faf17df919ae3db288fe8ecd96b4250b438 /src/basic/memory-util.h
parentb2efed520b51f71484e45289f9f34b611838cd4a (diff)
downloadsystemd-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.h10
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)