blib: Update strtoui
diff --git a/limine.bin b/limine.bin
index 211982d2..f07d8143 100644
Binary files a/limine.bin and b/limine.bin differ
diff --git a/stage2/lib/blib.c b/stage2/lib/blib.c
index 7173da64..d593c15f 100644
--- a/stage2/lib/blib.c
+++ b/stage2/lib/blib.c
@@ -1,6 +1,7 @@
#include <stdint.h>
#include <stddef.h>
#include <stdarg.h>
+#include <lib/libc.h>
#include <lib/blib.h>
#include <lib/print.h>
@@ -65,16 +66,11 @@ int digit_to_int(char c) {
return -1;
}
-uint64_t strtoui(const char *s) {
+uint64_t strtoui(const char *s, size_t limit, int base) {
uint64_t n = 0;
- while (*s)
- n = n * 10 + digit_to_int(*(s++));
- return n;
-}
-
-uint64_t strtoui16(const char *s) {
- uint64_t n = 0;
- while (*s)
- n = n * 16 + digit_to_int(*(s++));
+ if (!limit)
+ limit = strlen(s);
+ for (size_t i = 0; i < limit; i++)
+ n = n * base + digit_to_int(s[i]);
return n;
}
diff --git a/stage2/lib/blib.h b/stage2/lib/blib.h
index 5f124128..e177d0f2 100644
--- a/stage2/lib/blib.h
+++ b/stage2/lib/blib.h
@@ -16,8 +16,7 @@ __attribute__((noreturn)) void panic(const char *fmt, ...);
int pit_sleep_and_quit_on_keypress(uint32_t pit_ticks);
-uint64_t strtoui(const char *s);
-uint64_t strtoui16(const char *s);
+uint64_t strtoui(const char *s, size_t limit, int base);
#define DIV_ROUNDUP(a, b) (((a) + ((b) - 1)) / (b))
diff --git a/stage2/lib/uri.c b/stage2/lib/uri.c
index 439f44ac..ed8173d4 100644
--- a/stage2/lib/uri.c
+++ b/stage2/lib/uri.c
@@ -57,10 +57,10 @@ static bool parse_bios_partition(char *loc, uint8_t *drive, uint8_t *partition)
if (*loc == 0) {
*drive = boot_drive;
} else {
- if (strtoui(loc) < 1 || strtoui(loc) > 16) {
+ if (strtoui(loc, 0, 10) < 1 || strtoui(loc, 0, 10) > 16) {
panic("BIOS drive number outside range 1-16");
}
- *drive = (strtoui(loc) - 1) + 0x80;
+ *drive = (strtoui(loc, 0, 10) - 1) + 0x80;
}
loc += i + 1;
break;
@@ -70,10 +70,10 @@ static bool parse_bios_partition(char *loc, uint8_t *drive, uint8_t *partition)
if (*loc == 0)
return false;
- if (strtoui(loc) < 1 || strtoui(loc) > 256) {
+ if (strtoui(loc, 0, 10) < 1 || strtoui(loc, 0, 10) > 256) {
panic("BIOS partition number outside range 1-256");
}
- *partition = strtoui(loc) - 1;
+ *partition = strtoui(loc, 0, 10) - 1;
return true;
}
diff --git a/stage2/menu.c b/stage2/menu.c
index afc11a09..90b14ab7 100644
--- a/stage2/menu.c
+++ b/stage2/menu.c
@@ -25,12 +25,12 @@ char *menu(void) {
int selected_entry = 0;
if (config_get_value(buf, 0, 16, "DEFAULT_ENTRY")) {
- selected_entry = (int)strtoui(buf);
+ selected_entry = (int)strtoui(buf, 0, 10);
}
int timeout = 5;
if (config_get_value(buf, 0, 16, "TIMEOUT")) {
- timeout = (int)strtoui(buf);
+ timeout = (int)strtoui(buf, 0, 10);
}
if (!timeout)
@@ -53,43 +53,43 @@ char *menu(void) {
};
if (config_get_value(buf, 0, 16, "THEME_BLACK")) {
- colourscheme[0] = (int)strtoui16(buf);
+ colourscheme[0] = (int)strtoui(buf, 0, 16);
}
if (config_get_value(buf, 0, 16, "THEME_RED")) {
- colourscheme[1] = (int)strtoui16(buf);
+ colourscheme[1] = (int)strtoui(buf, 0, 16);
}
if (config_get_value(buf, 0, 16, "THEME_GREEN")) {
- colourscheme[2] = (int)strtoui16(buf);
+ colourscheme[2] = (int)strtoui(buf, 0, 16);
}
if (config_get_value(buf, 0, 16, "THEME_BROWN")) {
- colourscheme[3] = (int)strtoui16(buf);
+ colourscheme[3] = (int)strtoui(buf, 0, 16);
}
if (config_get_value(buf, 0, 16, "THEME_BLUE")) {
- colourscheme[4] = (int)strtoui16(buf);
+ colourscheme[4] = (int)strtoui(buf, 0, 16);
}
if (config_get_value(buf, 0, 16, "THEME_MAGENTA")) {
- colourscheme[5] = (int)strtoui16(buf);
+ colourscheme[5] = (int)strtoui(buf, 0, 16);
}
if (config_get_value(buf, 0, 16, "THEME_CYAN")) {
- colourscheme[6] = (int)strtoui16(buf);
+ colourscheme[6] = (int)strtoui(buf, 0, 16);
}
if (config_get_value(buf, 0, 16, "THEME_GREY")) {
- colourscheme[7] = (int)strtoui16(buf);
+ colourscheme[7] = (int)strtoui(buf, 0, 16);
}
if (config_get_value(buf, 0, 16, "THEME_MARGIN")) {
- margin = (int)strtoui(buf);
+ margin = (int)strtoui(buf, 0, 10);
}
if (config_get_value(buf, 0, 16, "THEME_MARGIN_GRADIENT")) {
- margin_gradient = (int)strtoui(buf);
+ margin_gradient = (int)strtoui(buf, 0, 10);
}
if (!config_get_value(cmdline, 0, CMDLINE_MAX, "BACKGROUND_PATH"))
diff --git a/stage2/protos/chainload.c b/stage2/protos/chainload.c
index cc33ccc8..d7a422bd 100644
--- a/stage2/protos/chainload.c
+++ b/stage2/protos/chainload.c
@@ -52,10 +52,10 @@ void chainload(void) {
if (!config_get_value(buf, 0, 32, "PARTITION")) {
part = -1;
} else {
- if (strtoui(buf) < 1 || strtoui(buf) > 256) {
+ if (strtoui(buf, 0, 10) < 1 || strtoui(buf, 0, 10) > 256) {
panic("BIOS partition number outside range 1-256");
}
- part = (int)strtoui(buf);
+ part = (int)strtoui(buf, 0, 10);
}
}
int drive; {
@@ -63,10 +63,10 @@ void chainload(void) {
if (!config_get_value(buf, 0, 32, "DRIVE")) {
panic("DRIVE not specified");
}
- if (strtoui(buf) < 1 || strtoui(buf) > 16) {
+ if (strtoui(buf, 0, 10) < 1 || strtoui(buf, 0, 10) > 16) {
panic("BIOS drive number outside range 1-16");
}
- drive = (int)strtoui(buf);
+ drive = (int)strtoui(buf, 0, 10);
}
term_deinit();
