summaryrefslogtreecommitdiff
path: root/MdePkg/Library/CompilerIntrinsicsLib/memset.c
blob: 1fcfaf9fee19a0cda7c0e0b30edfaa4d0bd31624 (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
// ------------------------------------------------------------------------------
//
// Copyright (c) 2016, Linaro Ltd. All rights reserved.<BR>
// Copyright (c) 2021, Arm Limited. All rights reserved.<BR>
//
// SPDX-License-Identifier: BSD-2-Clause-Patent
//
// ------------------------------------------------------------------------------

typedef __SIZE_TYPE__ size_t;

static __attribute__ ((__used__))
void *
__memset (
  void    *s,
  int     c,
  size_t  n
  )
{
  unsigned char  *d;

  d = s;

  while (n-- != 0) {
    *d++ = c;
  }

  return s;
}

//
// Other modules (such as CryptoPkg/IntrinsicLib) may provide another
// implementation of memset(), which may conflict with this one if this
// object was pulled into the link due to the definitions below. So make
// our memset() 'weak' to let the other implementation take precedence.
// PE targets (i.e. building with CLANGPDB) have different name mangling
// and as such don't recognize __memset here, so we provide a weak alias
// that simply calls the internal __memset implementation.
//
__attribute__ ((__weak__))
void *
memset (
  void    *dest,
  int     c,
  size_t  n
  )
{
  return __memset (dest, c, n);
}