summaryrefslogtreecommitdiff
path: root/Libraries/LibC/stdlib.cpp
AgeCommit message (Collapse)Author
2020-05-11LibC: Implement new strtod, accurate up to 8 epsBen Wiederhake
This strtod implementation is not perfectly accurate, as evidenced by the test (accuracy_strtod.cpp), but it is sufficiently close (up to 8 eps). The main sources of inaccuracy are: - Highly repeated division/multiplication by 'base' (Each operation brings a multiplicative error of 1+2^-53.) - Loss during the initial conversion from long long to double (most prominently, 69294956446009195 should first be rounded to 69294956446009200 and then converted to 69294956446009200.0 and then divided by ten, yielding 6929495644600920.0. Currently, it converts first to double, can't represent 69294956446009195.0, and instead represents 69294956446009190, which eventually yields 6929495644600919.0. Close, but technically wrong.) I believe that these issues can be fixed by rewriting the part at and after double value = digits.number(); and that the loss before that is acceptable. Specifically, losing the exact exponent on overflow is obviously fine. The only other loss occurs when the significant digits overflow a 'long long'. But these store 64(-7ish) bits, and the mantissa of a double only stores 52 bits. With a bit more thinking, one could probably get the error down to 1 or 2 eps. (But not better.) Fixes #1979.
2020-04-05LibC: Fix strtod() parsing of negative exponents (#1645)Stephan Unverwerth
Before this fix negative exponents were interpreted as positive.
2020-02-05LibC: Add posix_openpt(), grantpt() and unlockpt()Andreas Kling
This makes getting a pseudoterminal pair a little bit more portable. Note that grantpt() and unlockpt() are currently no-ops, since we've already granted the pseudoterminal slave to the calling user. We also accept O_CLOEXEC to posix_openpt(), unlike some systems. :^)
2020-01-18LibC: Use the templated type consistently in strtol_impl<T>Andreas Kling
2020-01-18Meta: Add license header to source filesAndreas Kling
As suggested by Joshua, this commit adds the 2-clause BSD license as a comment block to the top of every source file. For the first pass, I've just added myself for simplicity. I encourage everyone to add themselves as copyright holders of any file they've added or modified in some significant way. If I've added myself in error somewhere, feel free to replace it with the appropriate copyright holder instead. Going forward, all new source files should include a license header.
2020-01-11Kernel: Use the Syscall string and buffer types moreAndreas Kling
While I was updating syscalls to stop passing null-terminated strings, I added some helpful struct types: - StringArgument { const char*; size_t; } - ImmutableBuffer<Data, Size> { const Data*; Size; } - MutableBuffer<Data, Size> { Data*; Size; } The Process class has some convenience functions for validating and optionally extracting the contents from these structs: - get_syscall_path_argument(StringArgument) - validate_and_copy_string_from_user(StringArgument) - validate(ImmutableBuffer) - validate(MutableBuffer) There's still so much code around this and I'm wondering if we should generate most of it instead. Possible nice little project.
2020-01-06Kernel: Make realpath() take path+length, get rid of SmapDisablerAndreas Kling
2020-01-06LibC: Remove dubious String ends_with usageShannon Booth
As mentioned in #917, the String destructor could potentially be clobbering the errno. Use memcpy so that we do not need String at all.
2019-12-26LibC: Oops x2, we can't use "bool" in stdlib.h eitherAndreas Kling
2019-12-26LibC: Use shared functon to generate unique filenamesShannon Booth
Move some dupliated code into __generate_unique_filename()
2019-12-22LibC: Support exit time destructors per the Itanium C++ ABIAndrew Kaster
Implement __cxa_atexit and __cxa_finalize per the Itanium spec, and convert stdlib's atexit and exit() to to call them instead of a custom 'C-only' atexit implementation.
2019-12-10LibC: Implement strtod()Valtteri Koskivuori
2019-11-29LibC: Implement bsearchWilliam McPherson
Nothing fancy, just a simple implementation of bsearch(3).
2019-11-16LibC: Move realpath() to <stdlib.h>Andreas Kling
2019-11-16LibC: Implemented mkstemp in stdlibBrandon Scott
Implemented mkstemp method in stdlib.
2019-11-11LibC, LibM: Add functions needed to compile python3Emanuel Sprung
2019-11-10LibC: Implement a very naive mbtowc()Andreas Kling
This just copies the short char into the wide char without any decoding whatsoever. A proper implementation should look at the current LC_CTYPE and implement multi-byte decoding.
2019-11-04LibC: Implemented atof()Jesse Buhagiar
`atof()` has now been implemented as part of the standard C library. It supports scientific notation such as `1.2e-3` etc, ala the version found as part of `glibc`. It's a bit chunky, so there's probably room for optimisations here and there, however, for now it works as intended (and allows Quake to run).
2019-10-13Kernel: Use word-sized entropy as much as possible in syscallCalvin Buckley
2019-10-13LibC: add arc4random* using new getrandom syscallCalvin Buckley
Serenity is really not production ready; I shouldn't have to warn you not to trust the RNG here. This is for compatibility with software expecting the interface. arc4random does expose an annoying flaw with the syscall I want to discuss with Kling though.
2019-10-13LibC: Add some wchar functionsCalvin Buckley
These are basically copy and pasted from the regular string version. Also add some more multi-byte/wide conversion stub. libarchive wanted these. There's a lot more, but we can add them one at a time.
2019-10-03LibC: Misc additionsSergey Bugaev
2019-09-27LibC: Make div() and ldiv() behave according to the C standardAndreas Kling
2019-09-27LibC: Make system() behave according to POSIXAndreas Kling
- system(nullptr) returns non-zero to indicate the presence of a shell - Failure to fork() returns -1 - Failure to exec() in the child returns 127
2019-09-14LibC: Implement mkdtemp library functionMauri de Souza Nunes
2019-09-06AK: Rename <AK/AKString.h> to <AK/String.h>Andreas Kling
This was a workaround to be able to build on case-insensitive file systems where it might get confused about <string.h> vs <String.h>. Let's just not support building that way, so String.h can have an objectively nicer name. :^)
2019-08-24LibC: Fix strtol() handling of invalid charactersAndreas Kling
Rewrite this function to go from left-to-right instead of right-to-left since this allows us to accumulate valid characters before encountering any invalid ones. This fixes parsing of strings emitted by GCC, like "1, %0|%0, %1}". :^)
2019-08-17LibC: Fix strtol() not populating `endptr' for valid stringsAndreas Kling
We were not writing anything out to the `endptr` pointer if a number was successfully parsed from the input string. Fixes #460.
2019-07-04Libraries: Create top level directory for libraries.Andreas Kling
Things were getting a little crowded in the project root, so this patch moves the Lib*/ directories into Libraries/.