00001 /* A "buffer" utility type. 00002 Copyright (C) 1998 Free Software Foundation, Inc. 00003 00004 This file is part of GNU CC. 00005 00006 GNU CC is free software; you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation; either version 2, or (at your option) 00009 any later version. 00010 00011 GNU CC is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 GNU General Public License for more details. 00015 00016 You should have received a copy of the GNU General Public License 00017 along with GNU CC; see the file COPYING. If not, write to 00018 the Free Software Foundation, 59 Temple Place - Suite 330, 00019 Boston, MA 02111-1307, USA. */ 00020 00021 /* Written by Per Bothner <bothner@cygnus.com>, July 1998. */ 00022 00023 #include "config.h" 00024 #include "system.h" 00025 #include "buffer.h" 00026 00027 /* Grow BUFP so there is room for at least SIZE more bytes. */ 00028 00029 void 00030 buffer_grow (bufp, size) 00031 struct buffer *bufp; 00032 int size; 00033 { 00034 if (bufp->limit - bufp->ptr >= size) 00035 return; 00036 if (bufp->data == 0) 00037 { 00038 if (size < 120) 00039 size = 120; 00040 bufp->data = (unsigned char*) xmalloc (size); 00041 bufp->ptr = bufp->data; 00042 } 00043 else 00044 { 00045 int index = bufp->ptr - bufp->data; 00046 size += 2 * (bufp->limit - bufp->data); 00047 bufp->data = (unsigned char *) xrealloc (bufp->data, size); 00048 bufp->ptr = bufp->data + index; 00049 } 00050 bufp->limit = bufp->data + size; 00051 }
1.5.6