diff options
author | Lizzy Fleckenstein <lizzy@vlhl.dev> | 2023-12-15 16:10:22 +0100 |
---|---|---|
committer | Lizzy Fleckenstein <lizzy@vlhl.dev> | 2023-12-15 16:11:38 +0100 |
commit | 2298d17186cb0e58a96d285384de431902da9b1e (patch) | |
tree | 635d642931d9f55e701639ee3b3707e0e28a805e /stage3/string.c | |
parent | 8a25a2935a60e65fcb3e2b715bada858f5fcd6a2 (diff) | |
download | cuddles-2298d17186cb0e58a96d285384de431902da9b1e.tar.xz |
big chungus
* fix a heap corruption bug
* add qemu support
* add an ATA driver
* add an USTAR read-only file system
* boot from disk instead of floppy
* font rendering
* image rendering
* PCI enumeration
* init script
Diffstat (limited to 'stage3/string.c')
-rw-r--r-- | stage3/string.c | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/stage3/string.c b/stage3/string.c new file mode 100644 index 0000000..ff4bfc3 --- /dev/null +++ b/stage3/string.c @@ -0,0 +1,56 @@ +#include "string.h" + +usize find_char(const char *str, char chr) +{ + usize ret = 0; + while (*str != chr && *str != '\0') + str++, ret++; + return ret; +} + +u64 parse_num(u8 **str, u8 base, isize size) +{ + u64 x = 0; + + while (size-- != 0) { + u8 c = **str; + + u64 d; + if (c >= '0' && c <= '9') + d = c - '0'; + else if (c >= 'a' && c <= 'z') + d = c - 'a'; + else if (c >= 'A' && c <= 'z') + d = c - 'A'; + else + return x; + + if (d >= base) + return x; + + (*str)++; + x = x * base + d; + } + + return x; +} + +usize strlen(const char *str) +{ + return find_char(str, '\0'); +} + +int strcmp(const char *p1, const char *p2) +{ + while (*p1 == *p2 && *p1 != '\0') + p1++, p2++; + return *p1 - *p2; +} + +int strncmp(const char *p1, const char *p2, usize size) +{ + for (usize i = 0; i < size; i++) + if (p1[i] != p2[i]) + return p1[i]-p2[i]; + return 0; +} |