#include "usrerr.h" #include "misc.h" #define MAX_DESC_LENGTH (256) #define GENERATE_STRING(STRING,x, desc) {#STRING, desc}, static const char *g_enumStrVal[][MAX_DESC_LENGTH] = { DEF_ERR_CODE(GENERATE_STRING) {"ERR_UNKNOWN", "未知错误"}, }; const char *getErrorEnumNameString(int errCode) { if (errCode < 0) { errCode = -errCode; } if (errCode >= ARRAY_SIZE(g_enumStrVal) || errCode < 0) { return g_enumStrVal[ARRAY_SIZE(g_enumStrVal) - 1][0]; } return g_enumStrVal[errCode][0]; } const char *getErrorEnumDesc(int errCode) { if (errCode >= ARRAY_SIZE(g_enumStrVal) || errCode < 0) { return g_enumStrVal[ARRAY_SIZE(g_enumStrVal) - 1][0]; } return g_enumStrVal[errCode][1]; }