summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorguozhanxin <[email protected]>2023-09-20 11:30:10 +0800
committerMeco Man <[email protected]>2023-09-19 23:58:27 -0400
commit35e4baa786270988f3a9a7570ef40e7512d146fa (patch)
tree884597032d799a7479af93bea3a6822520ff3eb8 /src
parent7732f8618b197e2d6ddc66c06a0978ed7834151b (diff)
[kservice]Improve rt_strerror function compatibility
Diffstat (limited to 'src')
-rw-r--r--src/kservice.c44
1 files changed, 28 insertions, 16 deletions
diff --git a/src/kservice.c b/src/kservice.c
index 1a8c047120..411e481832 100644
--- a/src/kservice.c
+++ b/src/kservice.c
@@ -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);