You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
One is RT-Thread's own error code, such as RT_ERROR, RT_EINVAL, etc.
The other is POSIX standard error codes such as ERROR, EINVAL, etc.
If the code and component are designed for POSIX compatibility, use the POSIX standard error code, otherwise use the RT-Thread error code.
For example: AT components are not POSIX compliant, so RT-Thread error codes are used; DFSv2 is POSIX compliant, so POSIX error codes are used.
2 The sign of the error code
Regardless of the POSIX error code or the RT-Thread error code, the function returns a negative value error code (except for EOK and RT_EOK, which do not need to be negative), for example:
return -RT_EINVAL;
return -EINVAL;
return EOK;
return RT_EOK;
Inject error codes with errno= or rt_set_errno, regardless of POSIX error codes or RT-Thread error codes, use positive error codes, for example:
rt_set_errno(EINVAL);
rt_set_errno(RT_EINVAL);
errno = EINVAL;
errno = RT_EINVAL;
rt_set_errno(RT_EOK);
errno = EOK;
The text was updated successfully, but these errors were encountered:
mysterywolf
changed the title
错误码设定和返回规范
错误码设定和返回规范 | Error code setting and return specification
Aug 12, 2023
1 RT-Thread 有两种错误码
RT_ERROR
、RT_EINVAL
等ERROR
、EINVAL
等若代码、组件是针对POSIX兼容设计的,则使用POSIX标准错误码,否则使用RT-Thread错误码。
例如:AT组件不是POSIX兼容设计,因此使用RT-Thread错误码;DFSv2是POSIX兼容设计,因此采用POSIX错误码。
2 错误码的正负
EOK
和RT_EOK
,这俩不用加负号),例如:return -RT_EINVAL;
return -EINVAL;
return EOK;
return RT_EOK;
errno=
或rt_set_errno
方式注入错误码,无论POSIX错误码还是RT-Thread错误码都使用正值错误码, 例如:rt_set_errno(EINVAL);
rt_set_errno(RT_EINVAL);
errno = EINVAL;
errno = RT_EINVAL;
rt_set_errno(RT_EOK);
errno = EOK;
3 相关
#4791
1 RT-Thread has two error codes
RT_ERROR
,RT_EINVAL
, etc.ERROR
,EINVAL
, etc.If the code and component are designed for POSIX compatibility, use the POSIX standard error code, otherwise use the RT-Thread error code.
For example: AT components are not POSIX compliant, so RT-Thread error codes are used; DFSv2 is POSIX compliant, so POSIX error codes are used.
2 The sign of the error code
EOK
andRT_EOK
, which do not need to be negative), for example:return -RT_EINVAL;
return -EINVAL;
return EOK;
return RT_EOK;
errno=
orrt_set_errno
, regardless of POSIX error codes or RT-Thread error codes, use positive error codes, for example:rt_set_errno(EINVAL);
rt_set_errno(RT_EINVAL);
errno = EINVAL;
errno = RT_EINVAL;
rt_set_errno(RT_EOK);
errno = EOK;
The text was updated successfully, but these errors were encountered: