This new header complies with ISO/IEC 9899:2024 (C23).
Contrary to glibc, we do not provide inline definitions in
<stdbit.h> as we expect our system compiler to soon recognise
these as builtins anyway.
Relnotes: yes
MFC after: 1 month
Reviewed by: adrian
Approved by: markj (mentor)
Differential Revision: https://reviews.freebsd.org/D53657
This file checks the correctness of the various _MAX, _MIN, and
_WIDTH macros defined for the libc types. It assumes that none
of the types have padding bits.
Approved by: markj (mentor)
MFC after: 1 month
Differential Revision: https://reviews.freebsd.org/D53831
If the locale's positive_sign and negative_sign values would both be
returned by localeconv() as empty strings, strfmon() shall behave as if
the negative_sign value was the string "-".
This occurs with the C locale. The implementation previously assigned
"0" to sign_posn (parentheses around the entire string); now it assigns
it to "1" (sign before the string) when it is undefined (CHAR_MAX).
Austin Group Defect 1199[1] is applied, changing the requirements for
the '+' and '(' flags.
[1]: https://www.austingroupbugs.net/view.php?id=1199
Reviewed by: kib
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D53913
Add tests for The Open Group Base Specifications Issue 8[1], Austin
Group Defect 1199[2].
Items marked with XXX represent an invalid output. These items will be
fixed in subsequent commits.
Notice that an existing test is now considered invalid.
Our locale definitions do not include int_p_sep_by_space nor
int_n_sep_by_space[3]. Those will be addressed in a subsequent commit.
However, the CLDR project defines them as "0", which causes the output
to appear as "USD123.45". If our locale definitions were to set the
international {n,p}_sep_by_space to "1", the output would display as the
expected "USD 123.45".
While here, use the SPDX license identifier and add my name to the
file.
[1]: https://pubs.opengroup.org/onlinepubs/9799919799/functions/strfmon.html
[2]: https://www.austingroupbugs.net/view.php?id=1199
[3]: https://unicode-org.atlassian.net/browse/CLDR-237
Reviewed by: kib
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D53911
This new function computes the alignment of a pointer.
It is part of ISO/IEC 9899:2024, the new C standard.
If the pointer is a null pointer, null is returned.
I have tried to write an implementation that can cope
with traditional address-based architectures, even if
size_t and uintptr_t are of different length. Adjustments
may be needed for CHERI though.
A man page is provided, too. No unit test for now.
Reviewed by: kib, imp, ziaee (manpages), pauamma@gundo.com
Approved by: markj (mentor)
MFC after: 1 month
Relnotes: yes
Differential Revision: https://reviews.freebsd.org/D53673
This picks up the accelerated string functions written by
strajabot@.
Event: Google Summer of Code 2024
MFC after: 1 month
MFC to: stable/15
See also: 79e01e7e64
Approved by: markj (mentor)
Differential Revision: https://reviews.freebsd.org/D53248
We don't support CPU hotplug, but we do support cpuset(8) restrictions
on jails (including prison0, which uses cpuset 1). The process cannot
widen its cpuset beyond its root set, so it makes sense to instead
report the number of cpus enabled there rather than the total number
in the system.
This change is effectively a nop for the majority of systems and jails
in the wild, though it does reduce the performance of this query now
that we can't take advantage of AT_NCPUS being provided in the auxinfo.
The implementation here is notably different than Linux, which would not
take cgroups into account. They do, however, take CPU hotplug into
account, so the possibility for it to diverge from (and be lower than)
the # configured count to reflect what the process can actually be
scheduled on doesn't really diverge in semantics.
Reviewed by: kib
Differential Revision: https://reviews.freebsd.org/D52295
mac_text(3) as-written would seem to indicate that a `mac_t` should be
freed with free(3), but this isn't the case. One can derive from
context from when the change was introduced and COMPATIBILITY that this
was intended to talk about *text in `mac_to_text`, so move the comment
there.
PR: 179832
Co-authored-by: Priit Järv <priit cc ttu ee>
MFC after: 3 days
Add a new per-group SUBPACKAGE option to bsd.man.mk. When MANSPLITPKG
is enabled, this is forced to "-man", otherwise it defaults to empty
but can be overridden by the caller.
Use this in bsd.lib.mk to install library manpages in the -dev package
instead of the base package. This is nearly always preferable, since
library manpages are usually in section 2 or 3 and are only relevant
to people with development packages installed.
For manpages which should be installed in the base package even for
libraries, add a new MANNODEV group in bsd.lib.mk. Update existing
Makefiles to use this where appropriate.
MFC after: 3 days
Discussed with: olce
Reviewed by: olce
Sponsored by: https://www.patreon.com/bsdivy
Differential Revision: https://reviews.freebsd.org/D52832
The ffs() function conforms to IEEE Std 1003.1-2008 ("POSIX.1").
The ffsl() and ffsll() functions conform to IEEE Std 1003.1-2024 ("POSIX.1").
Reviewed by: ziaee
MFC after: 5 days
Differential Revision: https://reviews.freebsd.org/D53352
GCC does not like passing NULL (__null) to std::ostringstream::operator<<
inside of ATF_REQUIRE_EQ:
lib/libc/tests/net/inet_net_test.cc: In member function 'virtual void {anonymous}::atfu_tc_inet_net_ntop_invalid::body() const':
lib/libc/tests/net/inet_net_test.cc:306:9: error: passing NULL to non-pointer argument 1 of 'std::__1::basic_ostream<_CharT, _Traits>& std::__1::basic_ostream<_CharT, _Traits>::operator<<(long int) [with _CharT = char; _Traits = std::__1::char_traits<char>]' [-Werror=conversion-null]
306 | ATF_REQUIRE_EQ(ret, NULL);
| ^~~~~~~~~~~~~~
In file included from /usr/obj/.../amd64.amd64/tmp/usr/include/c++/v1/sstream:317,
from /usr/obj/.../amd64.amd64/tmp/usr/include/atf-c++/macros.hpp:29,
from /usr/obj/.../amd64.amd64/tmp/usr/include/atf-c++.hpp:29,
from lib/libc/tests/net/inet_net_test.cc:33:
/usr/obj/.../amd64.amd64/tmp/usr/include/c++/v1/__ostream/basic_ostream.h:338:81: note: declared here
338 | basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::operator<<(long __n) {
| ~~~~~^~~
...
Fixes: 8f4a0d2f7b ("libc: Import OpenBSD's inet_net_{ntop,pton}")
GCC warns about the sign mismatch in comparisons:
lib/libc/tests/net/inet_net_test.cc: In member function 'virtual void {anonymous}::atfu_tc_inet_net_inet4::body() const':
lib/libc/tests/net/inet_net_test.cc:86:17: error: comparison of integer expressions of different signedness: 'int' and 'const unsigned int' [-Werror=sign-compare]
86 | ATF_REQUIRE_EQ(bits, addr.bits);
| ^~~~~~~~~~~~~~
lib/libc/tests/net/inet_net_test.cc: In member function 'virtual void {anonymous}::atfu_tc_inet_net_inet6::body() const':
lib/libc/tests/net/inet_net_test.cc:205:17: error: comparison of integer expressions of different signedness: 'int' and 'const unsigned int' [-Werror=sign-compare]
205 | ATF_REQUIRE_EQ(bits, addr.bits);
| ^~~~~~~~~~~~~~
Fixes: 8f4a0d2f7b ("libc: Import OpenBSD's inet_net_{ntop,pton}")
Our versions of these functions (originally taken from BIND) simply
don't work correctly for AF_INET6. These were removed from BIND itself
quite a while ago, but OpenBSD has made several fixes in the mean time,
so import their code.
Add tests for both functions.
PR: 289198
Reported by: Nico Sonack <nsonack@herrhotzenplotz.de>
MFC after: 1 week
Reviewed by: des
Obtained from: OpenBSD (lib/libc/net)
Sponsored by: https://www.patreon.com/bsdivy
Differential Revision: https://reviews.freebsd.org/D52629
ISO 8601 allows use of "Z" as the time zone designator. Update the
strptime parser to allow this usage.
While we are at it, update the manpage to reflect that both UTC and Z
are now valid options.
Reviewed by: des
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D53083
We've been mostly POSIX-conforming since r236400 and fully since r240410,
which fixed a corner case where a missing non-leaf directory would be
reported as ENOTDIR instead of ENOENT.
Sponsored by: Klara, Inc.
Fixes: 7877ed7ce3 ("Avoid mapping ENOENT to ENOTDIR for non-existent path components.")
Reviewed by: ziaee, markj
Differential Revision: https://reviews.freebsd.org/D53027
If lstat() fails with EACCES or ENOTDIR, the path we need to return in
the caller-provided buffer is that of the parent directory (which is
either unreadable or not a directory; the latter can only happen in the
case of a race) rather than that of the child we attempted to stat.
Sponsored by: Klara, Inc.
Reviewed by: markj
Differential Revision: https://reviews.freebsd.org/D53025
* Passing NULL should result in EINVAL
* Passing an empty path should result in ENOENT
* Failure with a non-null buffer should leave a partial result. As
pointed out in a comment in the test case, this reveals a discrepancy
between the documentation and reality.
Sponsored by: Klara, Inc.
Reviewed by: markj
Differential Revision: https://reviews.freebsd.org/D53024
The current phrasing could be interpreted as meaning that initgroups(3)
could return ENOMEM instead of -1, which it actually did until I fixed
it in commit 0b018cfd81 ("initgroups(3): Fix return value on
allocation failure").
While here, mention setgroups(2) as a system call rather than a library
function.
MFC with: 0b018cfd81 ("initgroups(3): Fix return value on allocation failure")
Sponsored by: The FreeBSD Foundation
Emphasize the peculiar treatment of 'ngroups', through which the
effective group list's size is returned, even if the passed allocated
size is not big enough, in which case the output 'groups' array is
completely filled with the effective group list's first elements.
Use the precise POSIX term for the group associated to the user in the
password database ("initial numerical group ID"), consistently with what
was done in initgroups.3.
Use "length" instead of "size" to refer to the number of elements of an
array (in contrast with its actual size in bytes).
Perform some minor simplifications on top of the last rework.
MFC after: 1 hour
Sponsored by: The FreeBSD Foundation
* Add subsections for the three functions that didn't already have one.
* Add a RETURN VALUES section.
* Improve the grammar somewhat.
* Clarify that fts_read() will not set errno to 0 if called again after
having already returned NULL.
Sponsored by: Klara, Inc.
Reviewed by: bcr, markj
Differential Revision: https://reviews.freebsd.org/D52925
Rather than implementing the recurrence using 3 16-bit integers, as was
done in _dorand48() before this patch, provide an equivalent
implementation using 64-bit integers.
For drand48() and erand48(), replace the use of ldexp() with
bit-twiddling assuming IEEE 754 double-precision float layout.
This implementation is significantly faster and requires less code,
while producing identical outputs on supported platforms.
While here, add a STANDARDS section to rand48.3.
Obtained from: https://github.com/apple-oss-distributions/libc
MFC after: 3 weeks
Sponsored by: Klara, Inc.
Differential Revision: https://reviews.freebsd.org/D52429
We don't want to put these in clibs (where libc is) since they are not
critical to system operation. Move them to locales, since anyone who
is interested in translated versions of strerror() is going to have
that installed anyway.
While here, add some more documentation to bsd.nls.mk, particularly
the NLSPACKAGE option.
MFC after: 3 seconds
Reviewed by: manu, kib
Sponsored by: https://www.patreon.com/bsdivy
Differential Revision: https://reviews.freebsd.org/D52898
MD5 is used by libc/resolv to generate a random sequence id from a
current time stamp. Replace this convoluted mechanism with a call
to arc4random(). This permits us to entirely drop MD5 from libc,
simplifying the MD5 rework proposed in D45670.
Approved by: markj
Reviewed by: kevans, markj
See also: D45670
Event: EuroBSDcon 2025
Differential Revision: https://reviews.freebsd.org/D52784
This function from OpenBSD is a hybrid of reallocarray() and calloc().
It reallocates an array, clearing any newly allocated items.
reallocarray() ultimately originates from OpenBSD.
The source is taken from lib/libopenbsd, which now no longer has the
function unless when bootstrapping (needed for mandoc).
Reviewed by: kib
Differential Revision: https://reviews.freebsd.org/D52863
Summary:
This makes the code easier to understand and slightly faster,
but requires C23. calloc() would benefit, too, but I didn't
want to touch the imported jemalloc code base.
Reviewed by: kib
Differential Revision: https://reviews.freebsd.org/D52854
Commit c5d671b added netlink support to
server side rpcbind. However it did not add
a case for AF_NETLINK to __rpc_taddr2uaddr_af().
(Reported as PR#289625.)
As such, without this patch the r_addr field of the
netlink rbllist is NULL, which causes a crash in
svc_sendreply() for a Dump query (what rpcinfo
does).
PR: 289625
Reviewed by: glebius
MFC after: 3 days
Differential Revision: https://reviews.freebsd.org/D52651
Fixes: c5d671b711 ("libc/rpc: add userland side RPC server over netlink(4)")
* If TZ starts with TZDIR, strip any additional slashes so relname
does not end up looking like an absolute path. For instance,
TZ=/usr/share/zoneinfo//UTC should result in UTC, not /UTC.
* In the setugid case, we were incorrectly passing name rather than
relname to fstatat().
* Modify the tz_env and tz_env_setugid test cases to exercise both
of these scenarios.
* Also add test cases for invalid values of TZ, which I wrote
earlier but forgot to include in a5f14e4f90.
Reported by: Paul Eggert <eggert@cs.ucla.edu>
MFC after: 3 days
Fixes: 967a49a21a ("Update tzcode to 2025b")
Fixes: a5f14e4f90 ("tzcode: Use -00 only for invalid time zones")
Reviewed by: philip
Differential Revision: https://reviews.freebsd.org/D52753