From 0bf496f8646b30173e3960c855540e82c013ee77 Mon Sep 17 00:00:00 2001 From: AnotherTest Date: Mon, 15 Feb 2021 15:02:07 +0330 Subject: [PATCH] LibC: Make strtoull accept the '0x' prefix when base 16 is specified Dr.POSIX says it should be. --- Userland/Libraries/LibC/stdlib.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Userland/Libraries/LibC/stdlib.cpp b/Userland/Libraries/LibC/stdlib.cpp index 56f1070e76..049733dc6b 100644 --- a/Userland/Libraries/LibC/stdlib.cpp +++ b/Userland/Libraries/LibC/stdlib.cpp @@ -991,6 +991,14 @@ unsigned long long strtoull(const char* str, char** endptr, int base) char* parse_ptr = const_cast(str); strtons(parse_ptr, &parse_ptr); + if (base == 16) { + // Dr. POSIX: "If the value of base is 16, the characters 0x or 0X may optionally precede + // the sequence of letters and digits, following the sign if present." + if (*parse_ptr == '0') { + if (tolower(*(parse_ptr + 1)) == 'x') + parse_ptr += 2; + } + } // Parse base if (base == 0) { if (*parse_ptr == '0') {