memalloc.h

来自「一个学习SNMP项目:tmoerlan.」· C头文件 代码 · 共 47 行

H
47
字号
/* snap-1.0. Copyright (C) 2000 by Jonathan T. Moore and Michael Hicks. * * memalloc.h : macros for doing memory allocation. Each allocation *   checks for successful allocation, and exits upon failure. Macro *   is used mainly for code readability. * * $Id: memalloc.h,v 1.2 2003/09/17 11:26:10 tmoerlan Exp $ */#ifndef _SNAP_MEMALLOC_H_#define _SNAP_MEMALLOC_H_#include <stdio.h>#include <stdlib.h>#include <string.h>#include "timers.h"#ifdef NONZERO_MALLOC#define memalloc(ptr,t,sz)                                        \  { void *_result;                                                \    print_anti_timer(12,"memalloc");                              \    _result = (void *)malloc(sz);                                 \    if (_result == NULL) {                                        \      fprintf(stderr,"%s:%d: malloc failed\n",__FILE__,__LINE__); \      fflush(stderr);                                             \      exit(1);                                                    \    }                                                             \    (ptr) = (t)_result;                                           \    print_timer(12,"memalloc");                                   \  } #else#define memalloc(ptr,t,sz)                                        \  { void *_result;                                                \    print_anti_timer(12,"memalloc");                              \    _result = (void *)malloc(sz);                                 \    if (_result == NULL) {                                        \      fprintf(stderr,"%s:%d: malloc failed\n",__FILE__,__LINE__); \      fflush(stderr);                                             \      exit(1);                                                    \    }                                                             \    bzero(_result,sz);                                            \    (ptr) = (t)_result;                                           \    print_timer(12,"memalloc");                                   \} #endif /* NONZERO_MALLOC */#endif /* _SNAP_MEMALLOC_H_ */

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?