-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sys/libc: add endian.h #20310
sys/libc: add endian.h #20310
Conversation
Regarding the design decisions. The state of support by the different C libaries used:
So, it was just easier to provide a standard compliant one based on the builtins provided by both GCC and clang. |
This provides glibc, NetBSD, FreeBSD compatible endian.h header with a lean and simple API to convert between host byte order to little endian and big endian and the other way around.
Hello 🐴 Looks reasonable to me. A few questions / nitpicks:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
I extended and documented the unit test.
I was actually hoping to do that. But that is a bit controversial and a bit of work. But if this gets in, PRs to replace the use of Note: We likely have to still ship In the very least, I could clean up
It seems the fixup improving the unit test solved this already, now the static test is green :)
While reviewing #20301 I noticed a bug in the byte order conversion. A quick peek in the related driver w5100 showed the same bug. My first reaction was "Y R U not using |
Thx :) |
Contribution description
This adds the libc
endian.h
header compatible with glibc / FreeBSD / NetBSD / musl / ...It is a standardized and lean API that provides basically the same features as
byteorder.h
.Testing procedure
A unit test was added:
make BOARD=nrf52840dk -C tests/unittests tests-libc flash test
tl;dr
Issues/PRs references
As follow up, the
byteorder.h
could be adapted to use this, which IMO would improve readability. But that may be somewhat subjective, so let's not add this here.