Merge pull request #9131 from poettering/memory-startswith

add new memory_startswith() helper and make use of it everywhere
This commit is contained in:
Lennart Poettering
2018-05-31 11:21:43 +02:00
committed by GitHub
8 changed files with 49 additions and 39 deletions
+2 -6
View File
@@ -1037,13 +1037,9 @@ int log_struct_iovec_internal(
return -error;
}
for (i = 0; i < n_input_iovec; i++) {
if (input_iovec[i].iov_len < STRLEN("MESSAGE="))
continue;
if (memcmp(input_iovec[i].iov_base, "MESSAGE=", STRLEN("MESSAGE=")) == 0)
for (i = 0; i < n_input_iovec; i++)
if (memory_startswith(input_iovec[i].iov_base, input_iovec[i].iov_len, "MESSAGE="))
break;
}
if (_unlikely_(i >= n_input_iovec)) /* Couldn't find MESSAGE=? */
return -error;
+18
View File
@@ -209,3 +209,21 @@ static inline size_t strlen_ptr(const char *s) {
return strlen(s);
}
/* Like startswith(), but operates on arbitrary memory blocks */
static inline void *memory_startswith(const void *p, size_t sz, const char *token) {
size_t n;
assert(token);
n = strlen(token);
if (sz < n)
return NULL;
assert(p);
if (memcmp(p, token, n) != 0)
return NULL;
return (uint8_t*) p + n;
}