util: move some raw memory functions from string-util.h → memory-util.h

This commit is contained in:
Lennart Poettering
2019-03-14 12:55:37 +01:00
parent cfb4a84942
commit 090a9c1eba
5 changed files with 47 additions and 46 deletions

View File

@@ -184,32 +184,6 @@ int split_pair(const char *s, const char *sep, char **l, char **r);
int free_and_strdup(char **p, const char *s);
int free_and_strndup(char **p, const char *s, size_t l);
/* Normal memmem() requires haystack to be nonnull, which is annoying for zero-length buffers */
static inline void *memmem_safe(const void *haystack, size_t haystacklen, const void *needle, size_t needlelen) {
if (needlelen <= 0)
return (void*) haystack;
if (haystacklen < needlelen)
return NULL;
assert(haystack);
assert(needle);
return memmem(haystack, haystacklen, needle, needlelen);
}
#if HAVE_EXPLICIT_BZERO
static inline void* explicit_bzero_safe(void *p, size_t l) {
if (l > 0)
explicit_bzero(p, l);
return p;
}
#else
void *explicit_bzero_safe(void *p, size_t l);
#endif
char *string_erase(char *x);
char *string_free_erase(char *s);