blob: 0370ff0f56855ff6ee95eb2051f40cb161bc6512 [file] [log] [blame]
Shawn Shanb47ba8b2019-07-12 16:15:44 +08001/*
Summer Qinf24dbb52020-07-23 14:53:54 +08002 * Copyright (c) 2019-2020, Arm Limited. All rights reserved.
Shawn Shanb47ba8b2019-07-12 16:15:44 +08003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 */
7
8#include <stddef.h>
9#include <stdint.h>
10
Summer Qinf24dbb52020-07-23 14:53:54 +080011int memcmp(const void *s1, const void *s2, size_t n)
Shawn Shanb47ba8b2019-07-12 16:15:44 +080012{
13 int result = 0;
14 const uint8_t *p1 = (const uint8_t *)s1;
15 const uint8_t *p2 = (const uint8_t *)s2;
16 while (n--) {
17 if ((*p1 != *p2) && (result == 0)) {
18 result = *p1 - *p2;
19 } else {
20 p1++;
21 p2++;
22 }
23 }
24 return result;
25}