📄 realloc.c
字号:
/***********************************************************************/
/* This file is part of the C51 Compiler package */
/* Copyright KEIL ELEKTRONIK GmbH 1993 */
/***********************************************************************/
/* */
/* REALLOC.C: */
/* */
/* To translate this file use C51 with the following invocation: */
/* */
/* C51 REALLOC.C <memory model> */
/* */
/* To link the modified REALLOC.OBJ file to your application use the */
/* following L51 invocation: */
/* */
/* L51 <your object file list>, REALLOC.OBJ <controls> */
/* */
/***********************************************************************/
#include <string.h>
extern free (void *);
extern void *malloc (int);
struct mem {
struct mem xdata *next;
struct mem xdata *prev;
unsigned int len;
unsigned char mem[1];
};
void *realloc (struct mem xdata *p, unsigned int size) {
void xdata *p1;
if (!p) return ((void *) 0);
p = (void xdata *) p - (sizeof (struct mem) - 1);
if ((((unsigned int) p->next) - ((unsigned int) p)) >=
((sizeof (struct mem) - 1) + size)) {
p->len = size + sizeof (struct mem) - 1;
return (p->mem);
}
p1 = malloc (size);
if (!p1) return ((void *) 0);
memcpy (p1, p->mem, p->len);
free (p->mem);
return (p1);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -