1141 Commits
Author SHA1 Message Date
Sönke Holz d2d78ed715 LibC: Add Kernel/API/POSIX/winsize.h to HEADERS
I forgot to do this in be0e1aaf8f.

This makes us actually install that header into the sysroot, unbreaking
ports like openssl, which previously failed to build with:
"fatal error: Kernel/API/POSIX/winsize.h: No such file or directory"
2026-11-05 14:53:49 +01:00
Lucas Chollet d85d1a984f LibC: Set the pty size in openpty
This aligns the behavior with both Linux and OpenBSD (and probably all
other implementations of openpty).

This bug was visible in SSHServer, indeed when using an interactive
shell, the start pty size was always the default (80x25) instead of
whatever the client's window is using. It is quite visible with `top`,
which now fills the whole window :^)
2026-11-03 12:10:04 +01:00
Lucas Chollet 8e34c970b5 LibC: Implement tc{get,set}winsize functions
We already support the operation with ioctl, these functions are simply
the POSIX-compatible way of doing it. They were added in POSIX 2024.
2026-11-03 12:10:04 +01:00
Linus Groh e20af91244 LibC: Align LOCK_* with various other impls
Same motivation as the previous commit.
2026-10-23 09:18:11 -04:00
Linus Groh cc0614db24 LibC: Align PTHREAD_PROCESS_* with various other impls
POSIX doesn't mandate values but basically everyone except Darwin uses
0/1 for these:

- https://git.musl-libc.org/cgit/musl/tree/include/pthread.h?id=7813e9119eb5fe681b6750b8a033a0490bca0941#n54
- https://github.com/freebsd/freebsd-src/blob/775e421dc38f18fa6b7fdc7b214a013cca44b58b/include/pthread.h#L77-L78
- https://github.com/openbsd/src/blob/2114d7b7c8fbfd8d285dd7b5b5eb44e1f6b70f55/include/pthread.h#L73-L74
- https://github.com/NetBSD/src/blob/5b0e0d5997518246c017c6577adcb59be12d0a79/lib/libpthread/pthread.h#L259-L260
- https://github.com/illumos/illumos-gate/blob/a2504179488e929aea246b617973c10d05727e95/usr/src/head/pthread.h#L70-L71
- https://android.googlesource.com/platform/bionic/+/731631f300090436d7f5df80d50b6275c8c60a93/libc/include/pthread.h#91

This avoids having to special case serenity in Zig's standard library
(where they currently mismatch) and other future toolchain ports like
Rust.

See: https://codeberg.org/ziglang/zig/pulls/37364
2026-10-23 09:18:11 -04:00
Lucas Chollet 15a07a1073 LibC+AK: Move tgamma definition from LibC to AK
This makes the tgamma function accessible from constexpr contexts and
allows us to test it in CompareAKMathAgainstMPFR.
2026-10-14 22:19:04 +02:00
Lucas Chollet 5b636c2d1d AK+LibC: Move lgamma_r definition from LibC to AK
This allows us to have a constexpr lgamma_r function and also to test it
with CompareAKMathAgainstMPFR.
2026-10-12 18:39:50 +02:00
Lucas Chollet a3b87c3293 LibC: Consider f80's explicit leading 1 in internal_to_integer
While the existing f80 path gave a valid result in the float extractor,
the rounding steps were applied as if it was a normal float.
2026-09-24 20:33:35 +02:00
Lucas Chollet d2a1d0e075 LibC: Make nextafterl return a correct value when given equal arguments
This is done by moving the check to the shared implementation.
2026-09-24 20:33:35 +02:00
Lucas Chollet 2b94b63ebc LibC: Handle edge cases correctly in erf 2026-09-24 20:33:35 +02:00
Lucas Chollet f8a9d61aa7 LibC: Compute erf values in the correct type
It's wasteful to compute everything with long double precision when we
don't need it, so this change will be required down the road when we get
to make erf precise and fast. For the time being, this is more a
cosmetic change to align this implementation with others.
2026-09-24 20:33:35 +02:00
Lucas Chollet 627b81a7e5 LibC: Implement fdim* and remquo* functions 2026-09-24 20:33:35 +02:00
Lucas Chollet 33fc5740a2 LibC: Make ctype functions inlinable and have external linkage
Before this commit, you could either use the inlinable function by
using the macro or have the externally-linked version by first
undefining the macro and then using the function.

This commit makes all the ctype functions both inlinable and have
external linkage at the same time. To pull this trick, we provide
inlinable definitions in ctype.h and use a dedicated C feature that
forces the symbol to be emitted in the TU of ctype.c.

This could also have been achieved by using some #ifdef to hide the
inline definition in ctype.h so a C++ compiler would still emit a normal
symbol for the functions in ctype.cpp.
2026-09-24 11:53:15 +02:00
Lucas Chollet abd41e812d LibC: Don't use reserved names for the arguments in strftime declaration
The `max` argument could collide with the macro. Let's use the name
provided by POSIX instead.
2026-09-23 09:36:07 +02:00
Lucas Chollet 5528cdcfb7 LibC: Don't include assert.h from wctype.h
This is not required or used. Removing the include also fixes a bunch
of libcxx tests.
2026-09-22 23:05:29 +02:00
Lucas Chollet ce1809234d LibC: Use an explicit fixme for unsupported formats in strftime 2026-09-21 20:12:39 -04:00
Lucas Chollet df91038f4a LibC: Support a few other formats in strftime 2026-09-21 20:12:39 -04:00
Lucas Chollet 3fcd7ac87b LibC: Don't consider E and O modifiers in strftime
This only affect the output if the current locale has alternative
representations. Given that on Serenity we only use the POSIX/C locale,
and it doesn't have any alternative representations, these modifiers are
basically useless.

"If the alternative format or specification does not exist for the
current locale [...], the behavior shall be as if the unmodified
conversion specification were used."
2026-09-21 20:12:39 -04:00
Lucas Chollet 9fce834276 LibC: Display the correct week number when using %W in strftime
I'm not 100% sure if my formula always produces the right number, but it
is at least correct for the included test case.
2026-09-21 20:12:39 -04:00
Lucas Chollet 5d4da773be LibC: Make MB_CUR_MAX have a value compatible with our supported locales
According to POSIX:
"In the POSIX locale the value of {MB_CUR_MAX} shall be 1."
As we only support "POSIX"-compatible locales, let's make MB_CUR_MAX
equal to 1. Note that if we start to support other locales, this macro
will need to defer to a runtime function.
2026-09-21 20:12:39 -04:00
Lucas Chollet d8e8dfeeec LibC: Define MB_CUR_MAX and MB_LEN_MAX in their specified headers
Both locations are specified by POSIX and these values are only user
facing for the moment, so no need to have them in a private header.
2026-09-21 20:12:39 -04:00
Lucas Chollet c13073686e LibC: Start implementing newlocale and freelocale
This is just enough to let caller create default-compatible locales. It
is required by some of libcxx test cases.
2026-09-21 20:12:39 -04:00
Lucas Chollet 5a4c0d7bd3 LibC: Make strchr and friends compatible with the C++ standard
The C++ standard defines strchr, strrchr, strpbrk, strstr and memchr
differently than POSIX. To be conformant, we need to provide a different
signature when __cplusplus is defined.

This is the same logic as 73d178af, but applied to string.h.
2026-09-14 09:54:00 +02:00
Lucas Chollet 391cb83487 LibC: Align PTHREAD_COND_INITIALIZER with pthread_cond_init
According to POSIX:
"In cases where default condition variable attributes are appropriate,
the macro PTHREAD_COND_INITIALIZER can be used to initialise condition
variables that are statically allocated. The effect is equivalent to
dynamic initialisation by a call to pthread_cond_init() with parameter
attr specified as NULL, except that no error checks are performed."

AFAICT, the clock choice is left as an implementation detail, but other
systems seem to use CLOCK_REALTIME as the default:

https://sourceware.org/git/?p=glibc.git;a=blob;f=nptl/pthread_cond_init.c

https://github.com/openbsd/src/blob/7da33d17d09f1f2c0e27643875d90dc64f79173c/lib/libc/thread/rthread_cond.c#L30-L47
2026-09-14 09:47:03 +02:00
Lucas Chollet 10b2e3cca3 LibC: Make the NULL macro available in locale.h
From POSIX:
"The <locale.h> header shall define NULL (as defined in <stddef.h>)"
2026-09-12 08:13:32 +02:00
Lucas Chollet 232e5ff01f LibC: Fix typo scalbnlf => scalblnf 2026-09-11 21:44:14 +02:00
Eduardo Casadei c850d3aa7f LibC: Define LC_GLOBAL_LOCALE in locale.h
POSIX left its specific value implementation defined so, at least for
now, just set it to `(locale_t) -1`.
2026-09-10 21:30:11 -04:00
Eduardo Casadei 07b683c43b LibC: Add stub implementation of getlocalename_l
https://pubs.opengroup.org/onlinepubs/9799919799/functions/getlocalename_l.html
2026-09-10 21:30:11 -04:00
Linus Groh 5bf5658e03 LibC: Fix PTHREAD_RWLOCK_INITIALIZER
This was forgotten in 8e074f8.
2026-09-10 21:46:16 +02:00
Linus Groh 57f6385bba LibC: Implement stpncpy()
This is needed by the latest version of the dash port.
2026-09-10 19:20:42 +02:00
Lucas Chollet 7641d1cb0e LibC: Approximate lgamma(x) directly instead of computing log(gamma(x))
This is required to obtain results for large values of `x`. The Gamma
function can produce extremely large values, causing `gamma(x)` to
return `inf` even when `lgamma(x)` can still return a finite result.
2026-08-30 14:57:35 +02:00
Lucas Chollet 01158653d2 LibC: Use a common implementation for lgamma* functions 2026-08-30 14:57:35 +02:00
Lucas Chollet a97fe9899a LibC: Stub the timespec_get function
And add the related TIME_UTC macro.
2026-08-30 14:54:52 +02:00
Lucas Chollet 7784b1f535 LibC: Respect FILE's direction in fread and fwrite
Don't allow writing to a read-only file or reading from a write-only
file.
2026-08-27 19:29:33 -04:00
Lucas Chollet 73d178af94 LibC: Make wcschr and friends compatible with the C++ standard
The C++ standard defines wcschr, wcsrchr, wcspbrk, wcsstr and wmemchr
differently than POSIX. To be conformant, we need to provide a different
signature when __cplusplus is defined.

By defining the `__WCHAR_FORCE_C_DECLARATION` macro, users of `wchar.h`
can force the header to provide the C declaration even if __cplusplus is
defined. This escape hatch is needed to properly implement the C
function in LibC.

This makes us pass 3 more libcxx tests.
2026-08-27 17:24:28 +02:00
Lucas Chollet d4288b4c7f LibC: Stub wcstoimax and wcstoumax 2026-08-26 13:21:14 +02:00
Lucas Chollet a591ec9417 LibC: Define SIG_ATOMIC_{MIN,MAX} and WINT_{MIN,MAX} 2026-08-26 13:21:14 +02:00
Lucas Chollet 532f2ddd34 LibC: Support the 'x' mode in the fopen family 2026-08-24 20:19:46 -04:00
Lucas Chollet 78bf9db1a3 LibC: Define TMP_MAX
This is required by POSIX and is supposed to be equal to the number
of unique filenames that tmpnam can return. Given that we only have a
stub for that function, TMP_MAX is only here to please libcxx tests.
2026-08-24 20:16:51 -04:00
Lucas Chollet d557a8a7bc LibC: Define std{in,out,err} as macros
This is required by POSIX.
2026-08-24 20:16:51 -04:00
Lucas Chollet b7b8874f54 LibC: Do not create files in truncate
This is not required by POSIX, and ENOENT seems more natural here. This
fixes a libcxx test.
2026-08-23 12:16:10 +02:00
Lucas Chollet 5c3721c18b LibC: Rename FP_ILOGNAN => FP_ILOGBNAN
FP_ILOGBNAN is the correct POSIX-specified name.
2026-08-22 21:48:49 +02:00
Lucas Chollet e1bbd5b2d4 LibC: Add stubs for more parts of the locale API
The current version of the libcxx patch stubs these function in libcxx
internals. A future revision of the patch will instead require us to
define these functions in LibC.
2026-08-22 21:48:49 +02:00
Linus Groh 9ad0303622 Kernel+LibC: Use ESPIPE in preadv/prwitev for unseekable files
The expected error for preadv/pwritev with a non-negative offset and
unseekable file is ESPIPE[1][2].

Since LibC readv/preadv and writev/pwritev share a syscall we now check
the offset in userland for preadv/pwritev and return EINVAL before
performing the syscall.

The existing implementation was observed to cause issues with Zig's file
writer implementation, which handles EINVAL as an errno bug and attempts
a streaming write upon receiving ESPIPE for a positional write[3][4].

[1]: https://linux.die.net/man/2/pwritev / https://linux.die.net/man/2/lseek
[2]: https://man.freebsd.org/cgi/man.cgi?query=pwritev&sektion=2
[3]: https://codeberg.org/ziglang/zig/src/tag/0.16.0/lib/std/Io/Threaded.zig#L10553-L10581
[4]: https://codeberg.org/ziglang/zig/src/tag/0.16.0/lib/std/Io/File/Writer.zig#L101-L118
2026-08-11 22:48:28 -04:00
Andrew Kaster 4275329b3c LibC: Remove ESUCCESS as a public macro
ESUCCESS is not part of POSIX or any SUS standard, and is only present
in esoteric Unix-like systems from days gone by. And glibc, for some
reason. Remove it from the public headers now that there's no uses
in Userland/ anymore.
2026-07-26 13:06:44 -04:00
implicitfield 36afadd06e LibC: Back futimes with futimens
utimensat would fail because it EFAULTs if the path is null.
2026-07-14 08:20:09 -04:00
Nico Weber c5af100c9e Everywhere: Use NaN<T> instead of __builtin_nan{f,,l}("")
No behavior change.
2026-06-26 13:15:59 +02:00
Nico Weber c793c2e626 Everywhere: Use Infinity<double> instead of __builtin_huge_val()
No behavior change.
2026-06-26 13:15:59 +02:00
Nico Weber 341274075a LibC: Remove unused code from math.cpp
These have been dead since c5f6ba6e71 in #8743.

No behavior change.
2026-06-23 15:35:40 +02:00
Nico Weber afd64ca68e LibC: Remove unused code from math.cpp
These are dead after 92c6ae57fc in #4622.

No behavior change.
2026-06-23 15:35:40 +02:00