⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 realloc.c

📁 一组基础的C库的实现
💻 C
字号:
/* $Id: realloc.c 262 2006-11-16 07:34:57Z solar $ *//* Release $Name$ *//* void * realloc( void *, size_t )   This file is part of the Public Domain C Library (PDCLib).   Permission is granted to use, modify, and / or redistribute at will.*/#include <stdlib.h>#include <string.h>#include <stddef.h>#ifndef REGTEST/* TODO: Primitive placeholder. Improve. */void * realloc( void * ptr, size_t size ){    void * newptr = NULL;    if ( ptr == NULL )    {        return malloc( size );    }    if ( size > 0 )    {        struct _PDCLIB_memnode_t * baseptr = (struct _PDCLIB_memnode_t *)( (char *)ptr - sizeof( struct _PDCLIB_memnode_t ) );        if ( baseptr->size >= size )        {            /* Current memnode is large enough; nothing to do. */            return ptr;        }        else        {            /* Get larger memnode and copy over contents. */            if ( ( newptr = malloc( size ) ) == NULL )            {                return NULL;            }            memcpy( newptr, ptr, baseptr->size );        }    }    free( ptr );    return newptr;}#endif#ifdef TEST#include <_PDCLIB_test.h>int main(){    BEGIN_TESTS;    /* tests covered in malloc test driver */    return TEST_RESULTS;}#endif

⌨️ 快捷键说明

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