alloc.c

来自「另一款电路设计软件」· C语言 代码 · 共 73 行

C
73
字号
/**********Copyright 1990 Regents of the University of California.  All rights reserved.**********//* * Memory alloction functions */#include "spice.h"#include "stdio.h"#include "misc.h"#include "suffix.h"/* Malloc num bytes and initialize to zero. Fatal error if the space can't * be malloc'd.   Return NULL for a request for 0 bytes. */char *tmalloc(num)    int num;{    char *s;    int i;    if (!num)	return NULL;    s = malloc((unsigned) num);    if (!s) {        fprintf(stderr, 		"malloc: Internal Error: can't allocate %d bytes.\n", num);        exit(EXIT_BAD);    }    bzero(s, num);    return(s);}char *trealloc(str, num)    char *str;    int num;{    char *s;    if (!num) {	if (str)		free(str);	return NULL;    }    if (!str)	s = tmalloc(num);    else        s = realloc(str, (unsigned) num);    if (!s) {        fprintf(stderr, 		"realloc: Internal Error: can't allocate %d bytes.\n", num);        exit(EXIT_BAD);    }    return(s);}voidtxfree(ptr)	char	*ptr;{	if (ptr)		free(ptr);}

⌨️ 快捷键说明

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