54 lines
1.4 KiB
C
54 lines
1.4 KiB
C
#include <blue/core/status.h>
|
|
#include <errno.h>
|
|
#include <ivy/status.h>
|
|
|
|
#define ENUM_STR(x) \
|
|
case x: \
|
|
return #x
|
|
|
|
const char *ivy_status_to_string(enum ivy_status status)
|
|
{
|
|
switch (status) {
|
|
ENUM_STR(IVY_OK);
|
|
ENUM_STR(IVY_ERR_EOF);
|
|
ENUM_STR(IVY_ERR_IO_FAILURE);
|
|
ENUM_STR(IVY_ERR_BAD_SYNTAX);
|
|
ENUM_STR(IVY_ERR_NO_MEMORY);
|
|
ENUM_STR(IVY_ERR_NOT_SUPPORTED);
|
|
ENUM_STR(IVY_ERR_INTERNAL_FAILURE);
|
|
ENUM_STR(IVY_ERR_BAD_STATE);
|
|
ENUM_STR(IVY_ERR_INVALID_VALUE);
|
|
ENUM_STR(IVY_ERR_NO_ENTRY);
|
|
ENUM_STR(IVY_ERR_NAME_EXISTS);
|
|
ENUM_STR(IVY_ERR_BAD_FORMAT);
|
|
default:
|
|
return "";
|
|
}
|
|
}
|
|
|
|
#define ENUM_CONVERT(from, to) \
|
|
case (from): \
|
|
return (to)
|
|
|
|
enum ivy_status ivy_status_from_b_status(enum b_status status)
|
|
{
|
|
switch (status) {
|
|
ENUM_CONVERT(B_SUCCESS, IVY_OK);
|
|
ENUM_CONVERT(B_ERR_NAME_EXISTS, IVY_ERR_NAME_EXISTS);
|
|
ENUM_CONVERT(B_ERR_NO_MEMORY, IVY_ERR_NO_MEMORY);
|
|
default:
|
|
return IVY_ERR_INTERNAL_FAILURE;
|
|
}
|
|
}
|
|
|
|
enum ivy_status ivy_status_from_errno(int err)
|
|
{
|
|
switch (err) {
|
|
ENUM_CONVERT(0, IVY_OK);
|
|
ENUM_CONVERT(ENOENT, IVY_ERR_NO_ENTRY);
|
|
ENUM_CONVERT(ENOMEM, IVY_ERR_NO_MEMORY);
|
|
default:
|
|
return IVY_ERR_INTERNAL_FAILURE;
|
|
}
|
|
}
|