feature: add error conversion functions for DRANG error codes
This commit is contained in:
parent
eb60ab304a
commit
3211bb45b3
3 changed files with 68 additions and 0 deletions
|
|
@ -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.
|
||||
|
|
|
|||
56
Source/DrangPlatform/Source/errno_convert.c
Normal file
56
Source/DrangPlatform/Source/errno_convert.c
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
#include "errno_convert.h"
|
||||
|
||||
#include "drang/error.h"
|
||||
#include <errno.h>
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
11
Source/DrangPlatform/Source/errno_convert.h
Normal file
11
Source/DrangPlatform/Source/errno_convert.h
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
#pragma once
|
||||
#include <drang/platform.h>
|
||||
|
||||
|
||||
DRANG_BEGIN_DECLS
|
||||
|
||||
|
||||
int drang_error_to_errno(int error);
|
||||
int drang_errno_to_error(int errnum);
|
||||
|
||||
DRANG_END_DECLS
|
||||
Loading…
Add table
Add a link
Reference in a new issue