diff options
author | dzwdz | 2021-08-03 18:44:54 +0200 |
---|---|---|
committer | dzwdz | 2021-08-03 18:44:54 +0200 |
commit | 5d5b1d775984fe0112c0e1f60500c7d8e9850337 (patch) | |
tree | 0c4e160b6559678d9f635ea6e76f9f60dfa34c3c /src/kernel/util.c | |
parent | 5b2bb4e025919d74090d23cbabadfeec3b1e9dc4 (diff) |
kernel: implement memcmp
Diffstat (limited to 'src/kernel/util.c')
-rw-r--r-- | src/kernel/util.c | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/kernel/util.c b/src/kernel/util.c index f4dc5e1..0977745 100644 --- a/src/kernel/util.c +++ b/src/kernel/util.c @@ -15,3 +15,14 @@ void *memset(void *s, int c, size_t n) { s2[i] = c; return s; } + +int memcmp(const void *s1, const void *s2, size_t n) { + const unsigned char *c1 = s1, *c2 = s2; + for (size_t i = 0; i < n; i++) { + if (c1[i] != c2[i]) { + if (c1[i] < c2[i]) return -1; + else return 1; + } + } + return 0; +} |