lib/: Move memzero.[ch] under lib/string/memset/
Signed-off-by: Alejandro Colomar <alx@kernel.org>
This commit is contained in:
committed by
Serge Hallyn
parent
5c0b99c77e
commit
87a5145719
15
lib/string/memset/memzero.c
Normal file
15
lib/string/memset/memzero.c
Normal file
@@ -0,0 +1,15 @@
|
||||
// SPDX-FileCopyrightText: 2023, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#ident "$Id$"
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include "string/memset/memzero.h"
|
||||
|
||||
|
||||
extern inline void memzero(void *ptr, size_t size);
|
||||
extern inline void strzero(char *s);
|
||||
47
lib/string/memset/memzero.h
Normal file
47
lib/string/memset/memzero.h
Normal file
@@ -0,0 +1,47 @@
|
||||
// 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_LIB_STRING_MEMSET_MEMZERO_H_
|
||||
#define SHADOW_INCLUDE_LIB_STRING_MEMSET_MEMZERO_H_
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
#include <strings.h>
|
||||
|
||||
#include "sizeof.h"
|
||||
|
||||
|
||||
#define MEMZERO(arr) memzero(arr, SIZEOF_ARRAY(arr))
|
||||
|
||||
|
||||
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
|
||||
bzero(ptr, size);
|
||||
__asm__ __volatile__ ("" : : "r"(ptr) : "memory");
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
inline void
|
||||
strzero(char *s)
|
||||
{
|
||||
memzero(s, strlen(s));
|
||||
}
|
||||
|
||||
|
||||
#endif // include guard
|
||||
Reference in New Issue
Block a user