diff options
author | dzwdz | 2021-09-18 11:07:42 +0200 |
---|---|---|
committer | dzwdz | 2021-09-18 11:07:42 +0200 |
commit | 9741233ac39a1510de5bf3177c5172b4dd315222 (patch) | |
tree | 1e31ec65a0b994900c0fe3aeded4ef26d1f3ad02 /src/init | |
parent | 3ef371d9183197bea81e6dd391860b19b1affbcf (diff) |
create `init/stdlib`
Diffstat (limited to 'src/init')
-rw-r--r-- | src/init/stdlib.c | 12 | ||||
-rw-r--r-- | src/init/stdlib.h | 7 | ||||
-rw-r--r-- | src/init/tar.c | 14 |
3 files changed, 20 insertions, 13 deletions
diff --git a/src/init/stdlib.c b/src/init/stdlib.c new file mode 100644 index 0000000..6ed5a0a --- /dev/null +++ b/src/init/stdlib.c @@ -0,0 +1,12 @@ +#include <init/stdlib.h> + +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; +} diff --git a/src/init/stdlib.h b/src/init/stdlib.h new file mode 100644 index 0000000..1cabc7a --- /dev/null +++ b/src/init/stdlib.h @@ -0,0 +1,7 @@ +#pragma once +#include <stddef.h> + +// TODO since this is shared with the kernel, maybe i could turn this into an +// stb-style header file + +int memcmp(const void *s1, const void *s2, size_t n); diff --git a/src/init/tar.c b/src/init/tar.c index 24adfce..a2b03df 100644 --- a/src/init/tar.c +++ b/src/init/tar.c @@ -1,11 +1,10 @@ +#include <init/stdlib.h> #include <shared/syscalls.h> #include <stdint.h> extern int tty_fd; static int oct_parse(char *str, size_t len); -int memcmp(const void *s1, const void *s2, size_t n); // TODO move to a dedicated file - void tar_driver(void *base) { // iterate over all sectors, printing filenames @@ -30,14 +29,3 @@ static int oct_parse(char *str, size_t len) { } return res; } - -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; -} |