summaryrefslogtreecommitdiffstats
path: root/src/status.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2022-08-18 16:44:41 -0400
committerDavid Robillard <d@drobilla.net>2022-08-18 16:44:41 -0400
commitb9d58f74ea1d072e7a2d1c862dc7a1e0fe5fccb0 (patch)
tree9b01f7f6e96af405457cba746ca85dd21d38a3e5 /src/status.c
parent9ac3f4e009fd0d393d2c41449b121498e5b7ad54 (diff)
downloadzix-b9d58f74ea1d072e7a2d1c862dc7a1e0fe5fccb0.tar.gz
zix-b9d58f74ea1d072e7a2d1c862dc7a1e0fe5fccb0.tar.bz2
zix-b9d58f74ea1d072e7a2d1c862dc7a1e0fe5fccb0.zip
Factor out converting errno codes to ZixStatus
Diffstat (limited to 'src/status.c')
-rw-r--r--src/status.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/status.c b/src/status.c
index b932ff4..2ca3fe8 100644
--- a/src/status.c
+++ b/src/status.c
@@ -3,6 +3,8 @@
#include "zix/common.h"
+#include <errno.h>
+
const char*
zix_strerror(const ZixStatus status)
{
@@ -26,3 +28,32 @@ zix_strerror(const ZixStatus status)
}
return "Unknown error";
}
+
+ZixStatus
+zix_errno_status(const int e)
+{
+ switch (e) {
+ case 0:
+ return ZIX_STATUS_SUCCESS;
+#ifdef EAGAIN
+ case EAGAIN:
+ return ZIX_STATUS_NO_MEM;
+#endif
+#ifdef EEXIST
+ case EEXIST:
+ return ZIX_STATUS_EXISTS;
+#endif
+#ifdef EINVAL
+ case EINVAL:
+ return ZIX_STATUS_BAD_ARG;
+#endif
+#ifdef EPERM
+ case EPERM:
+ return ZIX_STATUS_BAD_PERMS;
+#endif
+ default:
+ break;
+ }
+
+ return ZIX_STATUS_ERROR;
+}