gcc fcgi_test.c -o fcgi_test.cgi -lfcgi -I/usr/local/fastcgikit/make/include
-L/usr/local/fastcgikit/make/lib
#include <stdio.h>
#include <string.h>
#define WEB_ERR_TOTAL 10001
enum {
WEB_OK = -WEB_ERR_TOTAL,
WEB_ERR_SYSTEM,
WEB_ERR_MALLOC,
WEB_ERR_MSGSEND,
WEB_ERR_AUTH,
WEB_ERR_PWDLONG,
WEB_ERR_IGMP_SNOOPING_FILTER,
WEB_END,
}WEB_ERR_CODE;
#define WEB_IDX(x) (~(x-1))
#define WEB_ERR_IDX(value) (WEB_ERR_TOTAL - WEB_IDX(value))
char *WebErrString[] = {
[WEB_ERR_IDX(WEB_OK)] = "operation ok.",
[WEB_ERR_IDX(WEB_ERR_SYSTEM)] = "system error",
[WEB_ERR_IDX(WEB_ERR_MALLOC)] = "malloc memory failure",
[WEB_ERR_IDX(WEB_ERR_MSGSEND)] = "not supported this message",
[WEB_ERR_IDX(WEB_ERR_AUTH)] = "auth is error",
[WEB_ERR_IDX(WEB_ERR_PWDLONG)] = "username's pasword is error",
[WEB_ERR_IDX(WEB_ERR_IGMP_SNOOPING_FILTER)] = "igmp snooping error",
};
#define WEB_ERRSTR(value) (value > 0 ? WebErrString[WEB_ERR_IDX(WEB_OK)] : WebErrString[WEB_ERR_IDX(value)])
int main()
{
printf("WEB_OK:%d, %d, string:%s.\n", WEB_OK, WEB_ERR_IDX(WEB_OK), WEB_ERRSTR(WEB_OK));
printf("WEB_ERR_SYSTEM:%d, :%d, string:%s.\n", WEB_ERR_SYSTEM, WEB_ERR_IDX(WEB_ERR_SYSTEM), WEB_ERRSTR(WEB_ERR_SYSTEM));
printf("WEB_ERR_MALLOC:%d, :%d, string:%s.\n", WEB_ERR_MALLOC, WEB_ERR_IDX(WEB_ERR_MALLOC), WEB_ERRSTR(WEB_ERR_MALLOC));
return 0;
}
root@ubuntu:/home/lyeffort# gcc test_error_define.c -o aaa && ./aaa && rm -rf aaa
WEB_OK:-10001, 0, string:operation ok..
WEB_ERR_SYSTEM:-10000, :1, string:system error.
WEB_ERR_MALLOC:-9999, :2, string:malloc memory failure.
错误码定义使用方法
于 2022-02-22 14:09:14 首次发布