summaryrefslogtreecommitdiff
path: root/src/kernel/libc.c
diff options
context:
space:
mode:
authorBrett Weiland <brett_weiland@bpcspace.com>2021-03-24 15:42:20 -0500
committerBrett Weiland <brett_weiland@bpcspace.com>2021-03-24 15:42:20 -0500
commitf90c075d5061b3a89316d6bf3d5b190d49049ccd (patch)
tree36265da568b852ca5c0a8b4affe706cda80c4a9d /src/kernel/libc.c
parent14b109ea24dc5cb1db948de57a2a44c80ef4622e (diff)
renamed: kernel/include/acpi.h -> include/acpi.h
renamed: kernel/include/libc.h -> include/libc.h renamed: kernel/include/paging.h -> include/paging.h renamed: kernel/include/printf.h -> include/printf.h renamed: kernel/include/serial.h -> include/serial.h renamed: kernel/include/video.h -> include/video.h new file: indigo_os renamed: kernel/libs/acpi.c -> kernel/acpi.c renamed: kernel/libs/drivers/serial.c -> kernel/drivers/serial.c renamed: kernel/libs/drivers/video.c -> kernel/drivers/video.c renamed: kernel/libs/libc.c -> kernel/libc.c renamed: kernel/libs/page.c -> kernel/page.c renamed: kernel/libs/printf.c -> kernel/printf.c renamed: kernel/libs/printf.h -> kernel/printf.h modified: makefile
Diffstat (limited to 'src/kernel/libc.c')
-rw-r--r--src/kernel/libc.c60
1 files changed, 60 insertions, 0 deletions
diff --git a/src/kernel/libc.c b/src/kernel/libc.c
new file mode 100644
index 0000000..dc5c0ac
--- /dev/null
+++ b/src/kernel/libc.c
@@ -0,0 +1,60 @@
+#include <stddef.h>
+#include <stdint.h>
+// TODO clean up variable names
+int strncmp(const char *s1, const char *s2, unsigned int n) {
+ int i;
+ for(i = 0; ((i <= n) && (s1[i] != '\0') && (s2[i] != '\0')); i++) {
+ if(s1[i] != s2[i]) {
+ return(s1[i] - s2[i]);
+ }
+ }
+ return(s1[i] - s2[i]);
+}
+
+int strcmp(const char *s1, const char *s2) {
+ int i;
+ for(i = 0; ((s1[i] != '\0') && (s2[i] != '\0')); i++) {
+ if(s1[i] != s2[i]) {
+ return(s1[i] - s2[i]);
+ }
+ }
+ return(s1[i] - s2[i]);
+}
+
+int memcmp(const void *s1, const void *s2, size_t n) {
+ const unsigned char *p1 = s1;
+ const unsigned char *p2 = s2;
+ int i;
+ for(i = 0; i < n; i++) {
+ if(p1[i] != p2[i]) {
+ return(p1[i] - p2[i]);
+ }
+ }
+ return(p1[n-1] - p2[n-1]);
+}
+
+void strcpy(char *dest, char *src) {
+ for(unsigned int i = 0; src[i] != '\0'; i++){
+ dest[i] = src[i];
+ }
+}
+
+void memcpy(char *dest, char *src, size_t n) {
+ for(unsigned int i = 0; i <= n; i++) {
+ dest[i] = src[i];
+ }
+}
+
+void bzero(void *dest, size_t size) {
+ unsigned char *p1 = dest;
+ for(uint64_t i = 0; i < size; i++) {
+ p1[i] = 0;
+ }
+}
+
+//TODO move this function to a seperate math library
+int ceil(float n) {
+ int low_n = (int)n;
+ if(n == (float)low_n) return(low_n);
+ return(low_n + 1);
+}