Skip to content

Commit

Permalink
Merge pull request #18768 from benpicco/tiny_strerror_minimal
Browse files Browse the repository at this point in the history
sys/tiny_strerror: add tiny_strerror_minimal
  • Loading branch information
maribu authored Oct 19, 2022
2 parents b4b8f2b + 8553c8f commit 1c00ce2
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions makefiles/pseudomodules.inc.mk
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,7 @@ PSEUDOMODULES += suit_transport_%
PSEUDOMODULES += suit_storage_%
PSEUDOMODULES += sys_bus_%
PSEUDOMODULES += tiny_strerror_as_strerror
PSEUDOMODULES += tiny_strerror_minimal
PSEUDOMODULES += vdd_lc_filter_%
## @defgroup pseudomodule_vfs_auto_format vfs_auto_format
## @brief Format mount points at startup unless they can be mounted
Expand Down
7 changes: 7 additions & 0 deletions sys/include/tiny_strerror.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@
* @note Using module `tiny_strerror_as_strerror` will replace all calls
* to `strerror()` by calls to `tiny_strerror()`, which may safe
* a bit of ROM.
*
* @note Using module `tiny_strerror_minimal` will just print the error
* code value.
* This will save ~1k of ROM, but won't provide much more information.
*
* @warning The module `tiny_strerror_minimal` is not thread-safe.
*
* @{
*
*
Expand Down
7 changes: 7 additions & 0 deletions sys/tiny_strerror/tiny_strerror.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/

#include <errno.h>
#include <stdio.h>
#include <string.h>

#include "kernel_defines.h"
Expand Down Expand Up @@ -112,6 +113,12 @@ const char *tiny_strerror(int errnum)
const char *retval = "-unknown";
unsigned offset = 1;

if (IS_USED(MODULE_TINY_STRERROR_MINIMAL)) {
static char buf[4];
snprintf(buf, sizeof(buf), "%d", errnum);
return buf;
}

if (errnum <= 0) {
offset = 0;
errnum = -errnum;
Expand Down

0 comments on commit 1c00ce2

Please sign in to comment.