From 6fe18b35722c0cf2cfd7bbaf7233b5ae66d3babf Mon Sep 17 00:00:00 2001 From: starnakin Date: Sat, 7 Sep 2024 01:44:17 +0200 Subject: [PATCH] fix --- Makefile | 4 ++-- src/kprint/kvprintf.c | 1 + src/terminal/terminal.c | 38 +++++++++++++++++--------------------- 3 files changed, 20 insertions(+), 23 deletions(-) diff --git a/Makefile b/Makefile index 2a9bcf7..8d74865 100644 --- a/Makefile +++ b/Makefile @@ -5,8 +5,8 @@ BUILDDIR = build SRC := $(wildcard $(SRCDIR)/**/*.c) OBJ := $(patsubst $(SRCDIR)/%.c,$(OBJDIR)/%.o,$(SRC)) -CC = gcc -CFLAGS = -iquoteheaders -c +CC = i386-elf-gcc +CFLAGS = -std=gnu99 -ffreestanding -O2 -Wall -Wextra -iquoteheaders -c AR = ar ARFLAGS = diff --git a/src/kprint/kvprintf.c b/src/kprint/kvprintf.c index abb32fb..d02557a 100644 --- a/src/kprint/kvprintf.c +++ b/src/kprint/kvprintf.c @@ -18,6 +18,7 @@ static int print_flag(char flag, va_list ap) case 's': return terminal_writestring(va_arg(ap, char *)); } + return 0; } int kvprintf(int level, const char *restrict format, va_list ap) diff --git a/src/terminal/terminal.c b/src/terminal/terminal.c index bcfd583..e3d7b25 100644 --- a/src/terminal/terminal.c +++ b/src/terminal/terminal.c @@ -1,4 +1,5 @@ -#include "../../headers/terminal.h" +#include "terminal.h" +#include "string.h" #include #include @@ -14,14 +15,6 @@ static inline uint16_t vga_entry(unsigned char uc, uint8_t color) return (uint16_t) uc | (uint16_t) color << 8; } -size_t strlen(const char* str) -{ - size_t len = 0; - while (str[len]) - len++; - return len; -} - static const size_t VGA_WIDTH = 80; static const size_t VGA_HEIGHT = 25; @@ -81,17 +74,20 @@ int terminal_writestring(const char* data) return len; } -int terminal_writelong(long number) +int terminal_writelong(long n) { - unsigned long number2 = number; - - if (number < 0) { - terminal_putchar('-'); - number2 = -number; - } - else { - if (number2 > 9) - terminal_writelong(number2 / 10); - terminal_putchar(number2 % 10); - } + long div = 10; + int rv = 0; + if (n < 0) { + rv += terminal_putchar('-'); + n *= -1; + } + div = 1; + while (div <= n / 10) + div *= 10; + while (div > 0) { + rv += terminal_putchar('0' + n / div % 10); + div /= 10; + } + return rv; } \ No newline at end of file