There's no need to have these as macros, so use functions, which are a lot safer: there's no need to worry about multiple evaluation of args, and there's also more type safety. Compiler warnings are also simpler, as they don't dump all the nested macros. Cc: Christian Göttsche <cgzones@googlemail.com> Cc: Serge Hallyn <serge@hallyn.com> Cc: Iker Pedrosa <ipedrosa@redhat.com> Signed-off-by: Alejandro Colomar <alx@kernel.org>
45 lines
808 B
C
45 lines
808 B
C
/*
|
|
* SPDX-FileCopyrightText: 2022-2023, Christian Göttsche <cgzones@googlemail.com>
|
|
* SPDX-FileCopyrightText: 2023, Alejandro Colomar <alx@kernel.org>
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
*/
|
|
|
|
|
|
#ifndef SHADOW_INCLUDE_LIBMISC_MEMZERO_H_
|
|
#define SHADOW_INCLUDE_LIBMISC_MEMZERO_H_
|
|
|
|
|
|
#include <config.h>
|
|
|
|
#include <stddef.h>
|
|
#include <string.h>
|
|
#include <strings.h>
|
|
|
|
|
|
inline void memzero(void *ptr, size_t size);
|
|
inline void strzero(char *s);
|
|
|
|
|
|
inline void
|
|
memzero(void *ptr, size_t size)
|
|
{
|
|
#if defined(HAVE_MEMSET_EXPLICIT)
|
|
memset_explicit(ptr, 0, size);
|
|
#elif defined(HAVE_EXPLICIT_BZERO)
|
|
explicit_bzero(ptr, size);
|
|
#else
|
|
ptr = memset(ptr, '\0', size);
|
|
__asm__ __volatile__ ("" : : "r"(ptr) : "memory");
|
|
#endif
|
|
}
|
|
|
|
|
|
inline void
|
|
strzero(char *s)
|
|
{
|
|
memzero(s, strlen(s));
|
|
}
|
|
|
|
|
|
#endif // include guard
|