From e6918187568dbd01842d8d1d2c808ce16a894239 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 21 Apr 2024 13:54:28 +0200 Subject: Adding upstream version 18.2.2. Signed-off-by: Daniel Baumann --- src/libkmip/kmip_memset.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 src/libkmip/kmip_memset.c (limited to 'src/libkmip/kmip_memset.c') diff --git a/src/libkmip/kmip_memset.c b/src/libkmip/kmip_memset.c new file mode 100644 index 000000000..5c59e0876 --- /dev/null +++ b/src/libkmip/kmip_memset.c @@ -0,0 +1,59 @@ +/* Copyright (c) 2018 The Johns Hopkins University/Applied Physics Laboratory +* All Rights Reserved. + * + * This file is dual licensed under the terms of the Apache 2.0 License and + * the BSD 3-Clause License. See the LICENSE file in the root of this + * repository for more information. + */ + +#include "kmip_memset.h" + +#if defined __STDC_LIB_EXT1__ + +#define __STDC_WANT_LIB_EXT1__ 1 +#include + +void * +kmip_memset(void *ptr, int value, size_t size) +{ + if(ptr == NULL) + { + return(ptr); + } + + memset_s(ptr, size, value, size); + return(ptr); +} + +#else + +void * +kmip_base_memset(void *ptr, int value, size_t size) +{ + if(ptr != NULL) + { + unsigned char *index = (unsigned char*)ptr; + for(size_t i = 0; i < size; i++) + { + *index++ = (unsigned char)value; + } + } + + return(ptr); +} + +static void * +(* volatile kmip_indirect_memset)(void *, int, size_t) = kmip_base_memset; + +void * +kmip_memset(void *ptr, int value, size_t size) +{ + if(ptr != NULL) + { + kmip_indirect_memset(ptr, value, size); + } + + return(ptr); +} + +#endif -- cgit v1.2.3