summaryrefslogtreecommitdiffstats
path: root/src/libkmip/kmip_memset.c
blob: 5c59e0876a013d5ba35999e7d15e64115b08d331 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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 <string.h>

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