diff options
| author | Richard Qin <richard.qin.x@gmail.com> | 2025-12-28 00:48:24 +0800 |
|---|---|---|
| committer | Richard Qin <richard.qin.x@gmail.com> | 2025-12-28 00:48:24 +0800 |
| commit | a82ab8ad6d277ededc128678aebabf5fbdb01c45 (patch) | |
| tree | 71d1d333d45e7272ba79a1868942dc710f673ff3 /src/lib | |
| parent | 7ececbe2818510a8acaa2a2e513085c768b14d15 (diff) | |
| download | lume-a82ab8ad6d277ededc128678aebabf5fbdb01c45.tar.gz lume-a82ab8ad6d277ededc128678aebabf5fbdb01c45.tar.xz | |
feat(syscall): Implement syscall dispatch and process lifecycle (exit/wait/sleep)
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/string.cc | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/src/lib/string.cc b/src/lib/string.cc new file mode 100644 index 0000000..bbd079d --- /dev/null +++ b/src/lib/string.cc @@ -0,0 +1,71 @@ +#include "lib/string.h" + +void *memset(void *dst, int c, uint n) +{ + char *cdst = (char *)dst; + for (uint i = 0; i < n; i++) + cdst[i] = c; + return dst; +} + +int memcmp(const void *v1, const void *v2, uint n) +{ + const uchar *s1 = (const uchar *)v1; + const uchar *s2 = (const uchar *)v2; + while (n-- > 0) + { + if (*s1 != *s2) + return *s1 - *s2; + s1++, s2++; + } + return 0; +} + +void *memmove(void *dst, const void *src, uint n) +{ + const char *s = (const char *)src; + char *d = (char *)dst; + if (s < d && s + n > d) + { + s += n; + d += n; + while (n-- > 0) + *--d = *--s; + } + else + { + while (n-- > 0) + *d++ = *s++; + } + return dst; +} + +void *memcpy(void *dst, const void *src, uint n) +{ + return memmove(dst, src, n); +} + +void strcpy(char *dst, const char *src) +{ + while (*src) + *dst++ = *src++; + *dst = 0; +} + +int strlen(const char *s) +{ + int n = 0; + while (s[n]) + n++; + return n; +} + +int strcmp(const char *s1, const char *s2) +{ + while (*s1 && (*s1 == *s2)) + { + s1++; + s2++; + } + return *(const unsigned char *)s1 - *(const unsigned char *)s2; +} |
