xiaohu.huang | bf62d7b | 2023-07-18 18:02:43 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2021-2022 Amlogic, Inc. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: MIT |
| 5 | */ |
| 6 | |
| 7 | #include "aml_strncmp.h" |
| 8 | |
| 9 | int strncmp(const char *s1, const char *s2, size_t n) |
| 10 | { |
| 11 | unsigned char value1; |
| 12 | unsigned char value2; |
| 13 | int ret; |
| 14 | |
| 15 | ret = 0; |
| 16 | for (; n > 0; n--) { |
| 17 | if ((*s1 != *s2) || (*s1 == '\0')) { |
| 18 | value1 = *((const unsigned char *)s1); |
| 19 | value2 = *((const unsigned char *)s2); |
| 20 | |
| 21 | ret = (value1 - value2); |
| 22 | break; |
| 23 | } |
| 24 | s1++; |
| 25 | s2++; |
| 26 | } |
| 27 | |
| 28 | return ret; |
| 29 | } |