summaryrefslogtreecommitdiff
path: root/userland/libc/stdlib
diff options
context:
space:
mode:
authorAnton Kling <anton@kling.gg>2024-11-22 22:29:56 +0100
committerAnton Kling <anton@kling.gg>2024-11-22 22:32:02 +0100
commit8827f3033d76b0d9c7d8d8225077176a813f7f49 (patch)
tree51f7a8aa1865bb816e408b39dca4e97426e48870 /userland/libc/stdlib
parentd39100c01385815174f2c4ad2058b9b2a00c18f9 (diff)
libc: Add case for strtol(l) where base is 0
Diffstat (limited to 'userland/libc/stdlib')
-rw-r--r--userland/libc/stdlib/strtol.c14
-rw-r--r--userland/libc/stdlib/strtoll.c14
-rw-r--r--userland/libc/stdlib/strtoul.c14
3 files changed, 36 insertions, 6 deletions
diff --git a/userland/libc/stdlib/strtol.c b/userland/libc/stdlib/strtol.c
index 30d04ec..4a1e189 100644
--- a/userland/libc/stdlib/strtol.c
+++ b/userland/libc/stdlib/strtol.c
@@ -28,8 +28,18 @@ long strtol(const char *str, char **restrict endptr, int base) {
}
if (0 == base) {
- // FIXME
- assert(0);
+ char prefix = *str;
+ if ('0' == prefix) {
+ str++;
+ if ('x' == tolower(*str)) {
+ str++;
+ base = 16;
+ } else {
+ base = 8;
+ }
+ } else {
+ base = 10;
+ }
}
if (2 <= base && 36 >= base) {
diff --git a/userland/libc/stdlib/strtoll.c b/userland/libc/stdlib/strtoll.c
index 486f91d..d1eacde 100644
--- a/userland/libc/stdlib/strtoll.c
+++ b/userland/libc/stdlib/strtoll.c
@@ -28,8 +28,18 @@ long long strtoll(const char *str, char **restrict endptr, int base) {
}
if (0 == base) {
- // FIXME
- assert(0);
+ char prefix = *str;
+ if ('0' == prefix) {
+ str++;
+ if ('x' == tolower(*str)) {
+ str++;
+ base = 16;
+ } else {
+ base = 8;
+ }
+ } else {
+ base = 10;
+ }
}
if (2 <= base && 36 >= base) {
diff --git a/userland/libc/stdlib/strtoul.c b/userland/libc/stdlib/strtoul.c
index c490aeb..f286a77 100644
--- a/userland/libc/stdlib/strtoul.c
+++ b/userland/libc/stdlib/strtoul.c
@@ -43,8 +43,18 @@ unsigned long strtoul(const char *restrict str, char **restrict endptr,
}
if (0 == base) {
- // FIXME
- assert(0);
+ char prefix = *str;
+ if ('0' == prefix) {
+ str++;
+ if ('x' == tolower(*str)) {
+ str++;
+ base = 16;
+ } else {
+ base = 8;
+ }
+ } else {
+ base = 10;
+ }
}
if (2 <= base && 36 >= base) {