[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";
}
static const char* rt_errno_strs[] =
struct _errno_str_t
{
"OK",
"ERROR",
"ETIMOUT",
"ERSFULL",
"ERSEPTY",
"ENOMEM",
"ENOSYS",
"EBUSY",
"EIO",
"EINTRPT",
"EINVAL",
"EUNKNOW"
rt_err_t error;
const char *str;
};
static struct _errno_str_t rt_errno_strs[] =
{
{RT_EOK , "OK "},
{RT_ERROR , "ERROR "},
{RT_ETIMEOUT, "ETIMOUT"},
{RT_EFULL , "ERSFULL"},
{RT_EEMPTY , "ERSEPTY"},
{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)
error = -error;
return (error > RT_EINVAL + 1) ?
rt_errno_strs[RT_EINVAL + 1] :
rt_errno_strs[error];
for (int i = 0; i < sizeof(rt_errno_strs) / sizeof(rt_errno_strs[0]); i++)
{
if (rt_errno_strs[i].error == error)
return rt_errno_strs[i].str;
}
return "EUNKNOW";
}
RTM_EXPORT(rt_strerror);