Linux内核编程:源码分析之防御性编程学习
/* *Kernel : Linux2.6.32.63 *File : \scripts\mod\modpost.h \scripts\mod\modpost.c *Author : DavidLin *Date : 2014-12-25pm *Email : [email protected] or [email protected] *world : the city of SZ, in China *Ver : 000.000.001 *history : editor time do * 1)LinPeng 2014-12-25 created this file! * 2) */ /* modpost.h */ #define NOFAIL(ptr) do_nofail((ptr), #ptr) void* do_nofail (void* ptr, const char* expr); /* end of modpost.h */ /* modpost.c */ void* do_nofail(void* ptr, const char* expr) { if(!ptr) fatal("modpost: Memory allocation failure:%s.\n", expr); return ptr; } static struct module* new_module(char* modname) { struct module* mod; char *p, *s; mod = NOFAIL(malloc(sizeof(*mod))); memset(mod, 0, sizeof(*mod)); p = NOFAIL(strdup(modname)); /* strip trailing .o */ s = strrchr(p, ‘.‘); if(s != NULL) if(strcmp(s, ".o") == 0) *s = ‘\0‘; /* add to list */ mod->name = p; mod->gpl_compatible = -1; mod->next = modules; modules = mod; return mod; }
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。