mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
sys/tiny_strerror: fix compilation on LLVM
Mixing address spaces is something LLVM doesn't like (for good reason). This re-organized the code a bit so that this does not happen anymore, even on AVR. Split out of https://github.com/RIOT-OS/RIOT/pull/16924
This commit is contained in:
parent
1c036e0116
commit
7775fa7de5
@ -215,37 +215,35 @@ static FLASH_ATTR const char * FLASH_ATTR const lookup[] = {
|
|||||||
|
|
||||||
const char *tiny_strerror(int errnum)
|
const char *tiny_strerror(int errnum)
|
||||||
{
|
{
|
||||||
/* dark magic: All error strings start with a "-". For positive error codes
|
|
||||||
* an offset of 1 is added to the address of the string, jumping one char
|
|
||||||
* behind the "-". This way the strings do not have to be allocated twice
|
|
||||||
* (once with and once without minus char).
|
|
||||||
*/
|
|
||||||
const char *retval = "-unknown";
|
|
||||||
unsigned offset = 1;
|
|
||||||
|
|
||||||
if (IS_USED(MODULE_TINY_STRERROR_MINIMAL)) {
|
if (IS_USED(MODULE_TINY_STRERROR_MINIMAL)) {
|
||||||
static char buf[4];
|
static char buf[4];
|
||||||
snprintf(buf, sizeof(buf), "%d", errnum);
|
snprintf(buf, sizeof(buf), "%d", errnum);
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* dark magic: All error strings start with a "-". For positive error codes
|
||||||
|
* an offset of 1 is added to the address of the string, jumping one char
|
||||||
|
* behind the "-". This way the strings do not have to be allocated twice
|
||||||
|
* (once with and once without minus char).
|
||||||
|
*/
|
||||||
|
unsigned offset = 1;
|
||||||
if (errnum <= 0) {
|
if (errnum <= 0) {
|
||||||
offset = 0;
|
offset = 0;
|
||||||
errnum = -errnum;
|
errnum = -errnum;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (((unsigned)errnum < ARRAY_SIZE(lookup))
|
if (((unsigned)errnum >= ARRAY_SIZE(lookup))
|
||||||
&& (lookup[(unsigned)errnum] != NULL)) {
|
|| (lookup[(unsigned)errnum] == NULL)) {
|
||||||
retval = lookup[(unsigned)errnum];
|
return "unknown";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IS_ACTIVE(HAS_FLASH_UTILS_ARCH)) {
|
#if IS_ACTIVE(HAS_FLASH_UTILS_ARCH)
|
||||||
static char buf[16];
|
static char buf[16];
|
||||||
flash_strncpy(buf, retval + offset, sizeof(buf));
|
flash_strncpy(buf, lookup[(unsigned)errnum] + offset, sizeof(buf));
|
||||||
return buf;
|
return buf;
|
||||||
}
|
#else
|
||||||
|
return lookup[(unsigned)errnum] + offset;
|
||||||
return retval + offset;
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#if IS_USED(MODULE_TINY_STRERROR_AS_STRERROR)
|
#if IS_USED(MODULE_TINY_STRERROR_AS_STRERROR)
|
||||||
|
Loading…
Reference in New Issue
Block a user