mirror of
https://github.com/systemd/systemd.git
synced 2026-08-08 17:10:55 +00:00
util: move some raw memory functions from string-util.h → memory-util.h
This commit is contained in:
@@ -37,3 +37,21 @@ bool memeqzero(const void *data, size_t length) {
|
||||
/* Now we know first 16 bytes are NUL, memcmp with self. */
|
||||
return memcmp(data, p + i, length) == 0;
|
||||
}
|
||||
|
||||
#if !HAVE_EXPLICIT_BZERO
|
||||
/*
|
||||
* The pointer to memset() is volatile so that compiler must de-reference the pointer and can't assume that
|
||||
* it points to any function in particular (such as memset(), which it then might further "optimize"). This
|
||||
* approach is inspired by openssl's crypto/mem_clr.c.
|
||||
*/
|
||||
typedef void *(*memset_t)(void *,int,size_t);
|
||||
|
||||
static volatile memset_t memset_func = memset;
|
||||
|
||||
void* explicit_bzero_safe(void *p, size_t l) {
|
||||
if (l > 0)
|
||||
memset_func(p, '\0', l);
|
||||
|
||||
return p;
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user