diff options
Diffstat (limited to 'lib/string/strncmp.c')
| -rw-r--r-- | lib/string/strncmp.c | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/string/strncmp.c b/lib/string/strncmp.c new file mode 100644 index 0000000..b98473b --- /dev/null +++ b/lib/string/strncmp.c @@ -0,0 +1,12 @@ +/* SPDX-License-Identifier: MIT */ +/* Derived from musl libc (Copyright © 2005-2020 Rich Felker, et al.) */ + +#include <string.h> + +int strncmp(const char *_l, const char *_r, size_t n) +{ + const unsigned char *l=(void *)_l, *r=(void *)_r; + if (!n--) return 0; + for (; *l && *r && n && *l == *r ; l++, r++, n--); + return *l - *r; +} |
