mirror of
https://github.com/riscv-software-src/opensbi.git
synced 2025-08-24 15:31:22 +01:00
lib: Add sbi_strncmp implementation
This commit add an implementation of sbi_strncmp. Signed-off-by: Abner Chang <abner.chang@hpe.com> Reviewed-by: Atish Patra <atish.patra@wdc.com> Reviewed-by: Anup Patel <anup.patel@wdc.com>
This commit is contained in:
@@ -12,8 +12,15 @@
|
||||
|
||||
#include <sbi/sbi_types.h>
|
||||
|
||||
/*
|
||||
Provides sbi_strcmp for the completeness of supporting string functions.
|
||||
it is not recommended to use sbi_strcmp() but use sbi_strncmp instead.
|
||||
*/
|
||||
|
||||
int sbi_strcmp(const char *a, const char *b);
|
||||
|
||||
int sbi_strncmp(const char *a, const char *b, size_t count);
|
||||
|
||||
size_t sbi_strlen(const char *str);
|
||||
|
||||
size_t sbi_strnlen(const char *str, size_t count);
|
||||
|
@@ -14,6 +14,10 @@
|
||||
|
||||
#include <sbi/sbi_string.h>
|
||||
|
||||
/*
|
||||
Provides sbi_strcmp for the completeness of supporting string functions.
|
||||
it is not recommended to use sbi_strcmp() but use sbi_strncmp instead.
|
||||
*/
|
||||
int sbi_strcmp(const char *a, const char *b)
|
||||
{
|
||||
/* search first diff or end of string */
|
||||
@@ -23,6 +27,15 @@ int sbi_strcmp(const char *a, const char *b)
|
||||
return *a - *b;
|
||||
}
|
||||
|
||||
int sbi_strncmp(const char *a, const char *b, size_t count)
|
||||
{
|
||||
/* search first diff or end of string */
|
||||
for (; count > 0 && *a == *b && *a != '\0'; a++, b++, count--)
|
||||
;
|
||||
|
||||
return *a - *b;
|
||||
}
|
||||
|
||||
size_t sbi_strlen(const char *str)
|
||||
{
|
||||
unsigned long ret = 0;
|
||||
|
Reference in New Issue
Block a user