[kservice]Improve rt_strerror function compatibility

This commit is contained in:
guozhanxin 2023-09-20 11:30:10 +08:00 committed by Meco Man
parent 7732f8618b
commit 35e4baa786
1 changed files with 28 additions and 16 deletions

View File

@ -96,20 +96,28 @@ rt_weak const char *rt_hw_cpu_arch(void)
return "unknown"; return "unknown";
} }
static const char* rt_errno_strs[] = struct _errno_str_t
{ {
"OK", rt_err_t error;
"ERROR", const char *str;
"ETIMOUT", };
"ERSFULL",
"ERSEPTY", static struct _errno_str_t rt_errno_strs[] =
"ENOMEM", {
"ENOSYS", {RT_EOK , "OK "},
"EBUSY", {RT_ERROR , "ERROR "},
"EIO", {RT_ETIMEOUT, "ETIMOUT"},
"EINTRPT", {RT_EFULL , "ERSFULL"},
"EINVAL", {RT_EEMPTY , "ERSEPTY"},
"EUNKNOW" {RT_ENOMEM , "ENOMEM "},
{RT_ENOSYS , "ENOSYS "},
{RT_EBUSY , "EBUSY "},
{RT_EIO , "EIO "},
{RT_EINTR , "EINTRPT"},
{RT_EINVAL , "EINVAL "},
{RT_ENOENT , "ENOENT "},
{RT_ENOSPC , "ENOSPC "},
{RT_EPERM , "EPERM "},
}; };
/** /**
@ -124,9 +132,13 @@ const char *rt_strerror(rt_err_t error)
if (error < 0) if (error < 0)
error = -error; error = -error;
return (error > RT_EINVAL + 1) ? for (int i = 0; i < sizeof(rt_errno_strs) / sizeof(rt_errno_strs[0]); i++)
rt_errno_strs[RT_EINVAL + 1] : {
rt_errno_strs[error]; if (rt_errno_strs[i].error == error)
return rt_errno_strs[i].str;
}
return "EUNKNOW";
} }
RTM_EXPORT(rt_strerror); RTM_EXPORT(rt_strerror);