错误码定义使用方法

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.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

the future c

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值