RIOT icon indicating copy to clipboard operation
RIOT copied to clipboard

sys/tiny_strerror: add tiny `strerror()` implementation

Open maribu opened this issue 3 years ago • 6 comments

Contribution description

tiny_strerror() is a drop-in replacement for strerror(), but instead of a long help message it returns the much shorter macro name matching the given number.

The (pseudo-)module tiny_strerror_as_strerror can be used to replace all calls to strerror() with calls to tiny_strerror().

This new module is directly put to use:

  • The custom AVR8 strerror() implementation is dropped and replaced by tiny_strerror_as_strerror
  • The vfs shell command used another custom strerror() implementation, which is also replaced

Testing procedure

The vfs shell command should still provide sensible error output and AVR8 builds that use strerror() should still succeed.

Issues/PRs references

None

maribu avatar Sep 09 '22 10:09 maribu

Anything still needed here?

maribu avatar Sep 19 '22 09:09 maribu

Please squash!

benpicco avatar Sep 19 '22 09:09 benpicco

:+1: This will also be very helpful for testing, as clibs tend to use there own string (or even worse: having native running with a e.g. a de locale). Having a deterministic string output greatly improves things!

miri64 avatar Sep 20 '22 11:09 miri64

Note that sadly it will not be fully deterministic, as EGAIN and EWOULDBLOCK may or may not have different numeric values. And on Linux, even ENOTSUP and EOPNOTSUPP have the same numeric value, but the man page says

   EOPNOTSUPP      Operation not supported on socket (POSIX.1-2001).

                   (ENOTSUP and EOPNOTSUPP have the same value on Linux,
                   but according to POSIX.1 these error values should be
                   distinct.)

But it will indeed be much more predictable.

maribu avatar Sep 20 '22 11:09 maribu

as EGAIN and EWOULDBLOCK may or may not have different numeric values

Different numeric numbers are not a problem. That can very easily handled with a regular expression. Having to look out for completely different strings based on trial-and-error is a whole other beast ;-)

miri64 avatar Sep 20 '22 12:09 miri64

CI is now happy :)

maribu avatar Sep 20 '22 18:09 maribu