diff options
author | 2023-05-07 10:44:11 +0530 | |
---|---|---|
committer | 2023-05-07 10:44:11 +0530 | |
commit | 97a91843ffac0bb3aa42540c6e5d3ddea75af489 (patch) | |
tree | 7a26514bef692fd1162f091ff490d456308334a0 /src/mem/memcmp.c | |
parent | Updated Readme to include build instructions (diff) | |
download | cart-main.tar cart-main.tar.gz cart-main.tar.bz2 cart-main.tar.lz cart-main.tar.xz cart-main.tar.zst cart-main.zip |
Added Basic Error codes, Tests and de-inliningmain
Error codes needs to be ingrated with the alloc module
Tests now have great coverage in the mem module (>75%).
Signed-off-by: Marc Pervaz Boocha <mboocha@sudomsg.xyz>
On branch main
Your branch is up to date with 'origin/main'.
Changes to be committed:
modified: include/alloc.h
new file: include/err.h
modified: include/mem.h
modified: include/meson.build
modified: readme.md
modified: src/alloc/free.c
modified: src/alloc/malloc.c
new file: src/err/errstr.c
new file: src/err/meson.build
new file: src/err/set_err.c
modified: src/mem/memccpy.c
modified: src/mem/memchr.c
modified: src/mem/memcmp.c
modified: src/mem/memcpy.c
modified: src/mem/memlen.c
modified: src/mem/memmem.c
modified: src/mem/memmove.c
modified: src/mem/memrchr.c
modified: src/mem/memrev.c
modified: src/mem/memset.c
modified: src/mem/memswap.c
modified: src/mem/memzero.c
modified: src/meson.build
new file: test/alloc/memdup.c
modified: test/alloc/meson.build
new file: test/mem/memccpy_nullnull.c
new file: test/mem/memchr.c
new file: test/mem/memchr_notfound.c
new file: test/mem/memcmp_diff.c
new file: test/mem/memcmp_prefix.c
new file: test/mem/memcmp_same.c
new file: test/mem/memcmp_samenull.c
new file: test/mem/memcmp_sing.c
new file: test/mem/memcpy_null_prefix.c
new file: test/mem/memcpy_null_same.c
new file: test/mem/memcpy_nullnull.c
new file: test/mem/memcpy_prefix.c
new file: test/mem/memcpy_same.c
new file: test/mem/memlen.c
new file: test/mem/memlen_overflow.c
new file: test/mem/memmove_backward.c
new file: test/mem/memmove_null_backward.c
new file: test/mem/memmove_null_overlap.c
new file: test/mem/memmove_null_prefix.c
new file: test/mem/memmove_null_same.c
new file: test/mem/memmove_null_sing.c
new file: test/mem/memmove_nullnull.c
new file: test/mem/memmove_overlap.c
new file: test/mem/memmove_prefix.c
new file: test/mem/memmove_same.c
new file: test/mem/memmove_sing.c
new file: test/mem/memrchr.c
new file: test/mem/memrchr_notfound.c
new file: test/mem/memrev.c
new file: test/mem/memset_null.c
new file: test/mem/memset_nullnull.c
new file: test/mem/memswap.c
new file: test/mem/memswap_null.c
new file: test/mem/memswap_same.c
new file: test/mem/memzero_null.c
new file: test/mem/memzero_nullnull.c
modified: test/mem/meson.build
modified: test/meson.build
Diffstat (limited to 'src/mem/memcmp.c')
-rw-r--r-- | src/mem/memcmp.c | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/src/mem/memcmp.c b/src/mem/memcmp.c index bcb2fb5..70419be 100644 --- a/src/mem/memcmp.c +++ b/src/mem/memcmp.c @@ -11,5 +11,22 @@ */ #include <mem.h> -extern inline int calt_memcmp(void const *ptr1, void const *ptr2, size_t count); +int calt_memcmp(const void *ptr1, const void *ptr2, size_t count) { + if(ptr1 == ptr2){ + return 0; + } + + const unsigned char *p1 = ptr1; + const unsigned char *p2 = ptr2; + + while (count-- > 0) { + if (*p1 != *p2) { + return (*p1 < *p2) ? -1 : 1; + } + p1++; + p2++; + } + + return 0; +} |