diff --git a/Source/DrangPlatform/Include/drang/error.h b/Source/DrangPlatform/Include/drang/error.h index 8a616ae..5a72e66 100644 --- a/Source/DrangPlatform/Include/drang/error.h +++ b/Source/DrangPlatform/Include/drang/error.h @@ -21,6 +21,7 @@ DRANG_PLATFORM_API const char *drang_error_str(int err); #define DRANG_EPERM (-8) // Operation not permitted #define DRANG_ETIMEDOUT (-9) // Connection timed out #define DRANG_EBUSY (-10) // Device or resource busy +#define DRANG_EPLATFORM (-1000) // An unknown platform-specific error occurred /** * @brief Begins a try-catch block for error handling. diff --git a/Source/DrangPlatform/Source/errno_convert.c b/Source/DrangPlatform/Source/errno_convert.c new file mode 100644 index 0000000..0ec599f --- /dev/null +++ b/Source/DrangPlatform/Source/errno_convert.c @@ -0,0 +1,56 @@ +#include "errno_convert.h" + +#include "drang/error.h" +#include + +int drang_error_to_errno(int error) +{ + switch (error) { + case DRANG_EOK: + return 0; + case DRANG_EAGAIN: + return EAGAIN; + case DRANG_ENOMEM: + return ENOMEM; + case DRANG_EINVAL: + return EINVAL; + case DRANG_ENOENT: + return ENOENT; + case DRANG_EDEADLK: + return EDEADLK; + case DRANG_EPERM: + return EPERM; + case DRANG_ETIMEDOUT: + return ETIMEDOUT; + case DRANG_EBUSY: + return EBUSY; + case DRANG_EPLATFORM: + default: + return EIO; // Generic I/O error for unknown platform errors + } +} +int drang_errno_to_error(const int errnum) +{ + switch (errnum) { + case 0: + return DRANG_EOK; + case EAGAIN: + return DRANG_EAGAIN; + case ENOMEM: + return DRANG_ENOMEM; + case EINVAL: + return DRANG_EINVAL; + case ENOENT: + return DRANG_ENOENT; + case EDEADLK: + return DRANG_EDEADLK; + case EPERM: + return DRANG_EPERM; + case ETIMEDOUT: + return DRANG_ETIMEDOUT; + case EBUSY: + return DRANG_EBUSY; + default: + return DRANG_EPLATFORM; + } +} diff --git a/Source/DrangPlatform/Source/errno_convert.h b/Source/DrangPlatform/Source/errno_convert.h new file mode 100644 index 0000000..0d95042 --- /dev/null +++ b/Source/DrangPlatform/Source/errno_convert.h @@ -0,0 +1,11 @@ +#pragma once +#include + + +DRANG_BEGIN_DECLS + + +int drang_error_to_errno(int error); +int drang_errno_to_error(int errnum); + +DRANG_END_DECLS \ No newline at end of file