diff --git a/Libraries/LibC/dlfcn.h b/Libraries/LibC/dlfcn.h index f07144a9158..2e45db06126 100644 --- a/Libraries/LibC/dlfcn.h +++ b/Libraries/LibC/dlfcn.h @@ -4,6 +4,7 @@ __BEGIN_DECLS +#define RTLD_DEFAULT 0 #define RTLD_LAZY 1 #define RTLD_NOW 2 #define RTLD_GLOBAL 3 diff --git a/Libraries/LibC/limits.h b/Libraries/LibC/limits.h index 0be8a426001..b08fcf4759d 100644 --- a/Libraries/LibC/limits.h +++ b/Libraries/LibC/limits.h @@ -23,6 +23,9 @@ #define LONG_MAX 2147483647L #define LONG_MIN (-LONG_MAX - 1L) +#define LONG_LONG_MAX 9223372036854775807LL +#define LONG_LONG_MIN (-LONG_LONG_MAX - 1LL) + #define CHAR_MIN SCHAR_MIN #define CHAR_MAX SCHAR_MAX diff --git a/Libraries/LibC/stdlib.cpp b/Libraries/LibC/stdlib.cpp index d8828d368fd..342029ce1eb 100644 --- a/Libraries/LibC/stdlib.cpp +++ b/Libraries/LibC/stdlib.cpp @@ -167,6 +167,8 @@ int putenv(char* new_var) return 0; } +} + double strtod(const char* str, char** endptr) { (void)str; @@ -175,6 +177,15 @@ double strtod(const char* str, char** endptr) ASSERT_NOT_REACHED(); } +long double strtold(const char* str, char** endptr) +{ + (void)str; + (void)endptr; + dbgprintf("LibC: strtold: '%s'\n", str); + ASSERT_NOT_REACHED(); +} + + float strtof(const char* str, char** endptr) { (void)str; @@ -374,7 +385,8 @@ size_t mbstowcs(wchar_t*, const char*, size_t) ASSERT_NOT_REACHED(); } -long strtol(const char* nptr, char** endptr, int base) +template +static T strtol_impl(const char* nptr, char** endptr, int base) { errno = 0; @@ -411,8 +423,8 @@ long strtol(const char* nptr, char** endptr, int base) } } - long cutoff_point = is_negative ? (LONG_MIN / base) : (LONG_MAX / base); - int max_valid_digit_at_cutoff_point = is_negative ? (LONG_MIN % base) : (LONG_MAX % base); + long cutoff_point = is_negative ? (min_value / base) : (max_value / base); + int max_valid_digit_at_cutoff_point = is_negative ? (min_value % base) : (max_value % base); long num = 0; @@ -441,7 +453,7 @@ long strtol(const char* nptr, char** endptr, int base) if (is_past_cutoff || (num == cutoff_point && digit > max_valid_digit_at_cutoff_point)) { has_overflowed = true; - num = is_negative ? LONG_MIN : LONG_MAX; + num = is_negative ? min_value : max_value; errno = ERANGE; } else { num *= base; @@ -459,10 +471,27 @@ long strtol(const char* nptr, char** endptr, int base) return num; } +long strtol(const char* str, char** endptr, int base) +{ + return strtol_impl(str, endptr, base); +} + unsigned long strtoul(const char* str, char** endptr, int base) { auto value = strtol(str, endptr, base); ASSERT(value >= 0); return value; } + +long long strtoll(const char* str, char** endptr, int base) +{ + return strtol_impl(str, endptr, base); } + +unsigned long long strtoull(const char* str, char** endptr, int base) +{ + auto value = strtoll(str, endptr, base); + ASSERT(value >= 0); + return value; +} + diff --git a/Libraries/LibC/stdlib.h b/Libraries/LibC/stdlib.h index 08fd255c0a9..9e48e3254e2 100644 --- a/Libraries/LibC/stdlib.h +++ b/Libraries/LibC/stdlib.h @@ -23,8 +23,11 @@ int atoi(const char*); long atol(const char*); long long atoll(const char*); double strtod(const char*, char** endptr); +long double strtold(const char*, char** endptr); float strtof(const char*, char** endptr); long strtol(const char*, char** endptr, int base); +long long strtoll(const char*, char** endptr, int base); +unsigned long long strtoull(const char*, char** endptr, int base); unsigned long strtoul(const char*, char** endptr, int base); void qsort(void* base, size_t nmemb, size_t size, int (*compar)(const void*, const void*)); void qsort_r(void* base, size_t nmemb, size_t size, int (*compar)(const void*, const void*, void*), void* arg);