mirror of
https://github.com/limine-bootloader/limine
synced 2024-11-23 09:02:11 +03:00
blib: Update strtoui
This commit is contained in:
parent
82a715142a
commit
48a9d06aa2
BIN
limine.bin
BIN
limine.bin
Binary file not shown.
@ -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;
|
||||
}
|
||||
|
@ -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))
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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"))
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user