xref: /openbsd/gnu/usr.bin/gcc/gcc/java/buffer.c (revision c87b03e5)
1*c87b03e5Sespie /* A "buffer" utility type.
2*c87b03e5Sespie    Copyright (C) 1998 Free Software Foundation, Inc.
3*c87b03e5Sespie 
4*c87b03e5Sespie This file is part of GNU CC.
5*c87b03e5Sespie 
6*c87b03e5Sespie GNU CC is free software; you can redistribute it and/or modify
7*c87b03e5Sespie it under the terms of the GNU General Public License as published by
8*c87b03e5Sespie the Free Software Foundation; either version 2, or (at your option)
9*c87b03e5Sespie any later version.
10*c87b03e5Sespie 
11*c87b03e5Sespie GNU CC is distributed in the hope that it will be useful,
12*c87b03e5Sespie but WITHOUT ANY WARRANTY; without even the implied warranty of
13*c87b03e5Sespie MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14*c87b03e5Sespie GNU General Public License for more details.
15*c87b03e5Sespie 
16*c87b03e5Sespie You should have received a copy of the GNU General Public License
17*c87b03e5Sespie along with GNU CC; see the file COPYING.  If not, write to
18*c87b03e5Sespie the Free Software Foundation, 59 Temple Place - Suite 330,
19*c87b03e5Sespie Boston, MA 02111-1307, USA.  */
20*c87b03e5Sespie 
21*c87b03e5Sespie /* Written by Per Bothner <bothner@cygnus.com>, July 1998. */
22*c87b03e5Sespie 
23*c87b03e5Sespie #include "config.h"
24*c87b03e5Sespie #include "system.h"
25*c87b03e5Sespie #include "buffer.h"
26*c87b03e5Sespie 
27*c87b03e5Sespie /* Grow BUFP so there is room for at least SIZE more bytes. */
28*c87b03e5Sespie 
29*c87b03e5Sespie void
buffer_grow(bufp,size)30*c87b03e5Sespie buffer_grow (bufp, size)
31*c87b03e5Sespie      struct buffer *bufp;
32*c87b03e5Sespie      int size;
33*c87b03e5Sespie {
34*c87b03e5Sespie   if (bufp->limit - bufp->ptr >= size)
35*c87b03e5Sespie     return;
36*c87b03e5Sespie   if (bufp->data == 0)
37*c87b03e5Sespie     {
38*c87b03e5Sespie       if (size < 120)
39*c87b03e5Sespie 	size = 120;
40*c87b03e5Sespie       bufp->data = xmalloc (size);
41*c87b03e5Sespie       bufp->ptr = bufp->data;
42*c87b03e5Sespie     }
43*c87b03e5Sespie   else
44*c87b03e5Sespie     {
45*c87b03e5Sespie       int index = bufp->ptr - bufp->data;
46*c87b03e5Sespie       size += 2 * (bufp->limit - bufp->data);
47*c87b03e5Sespie       bufp->data = xrealloc (bufp->data, size);
48*c87b03e5Sespie       bufp->ptr = bufp->data + index;
49*c87b03e5Sespie     }
50*c87b03e5Sespie   bufp->limit = bufp->data + size;
51*c87b03e5Sespie }
52