1 /*------------------------------------------------------------\
2 |                                                             |
3 | This file is part of the Alliance CAD System Copyright      |
4 | (C) Laboratoire LIP6 - D�partement ASIM Universite P&M Curie|
5 |                                                             |
6 | Home page      : http://www-asim.lip6.fr/alliance/          |
7 | E-mail         : mailto:alliance-users@asim.lip6.fr       |
8 |                                                             |
9 | This progam is  free software; you can redistribute it      |
10 | and/or modify it under the  terms of the GNU Library General|
11 | Public License as published by the Free Software Foundation |
12 | either version 2 of the License, or (at your option) any    |
13 | later version.                                              |
14 |                                                             |
15 | Alliance VLSI  CAD System  is distributed  in the hope that |
16 | it  will be useful, but WITHOUT  ANY WARRANTY;              |
17 | without even the  implied warranty of MERCHANTABILITY or    |
18 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General       |
19 | Public License for more details.                            |
20 |                                                             |
21 | You should have received a copy  of the GNU General Public  |
22 | License along with the GNU C Library; see the file COPYING. |
23 | If not, write to the Free Software Foundation, Inc.,        |
24 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.                     |
25 |                                                             |
26 \------------------------------------------------------------*/
27 /*------------------------------------------------------------\
28 |                                                             |
29 | Tool    :                     Aut                           |
30 |                                                             |
31 | File    :                 autresize.c                       |
32 |                                                             |
33 | Date    :                   03.12.96                        |
34 |                                                             |
35 | Author  :               Jacomme Ludovic                     |
36 |                                                             |
37 \------------------------------------------------------------*/
38 /*------------------------------------------------------------\
39 |                                                             |
40 |                         Include Files                       |
41 |                                                             |
42 \------------------------------------------------------------*/
43 
44 # include <stdio.h>
45 # include <stdlib.h>
46 # include <memory.h>
47 # include <string.h>
48 
49 
50 # include <mut.h>
51 # include "aut.h"
52 
53 # include "autresize.h"
54 # include "autenv.h"
55 # include "auterror.h"
56 
57 /*------------------------------------------------------------\
58 |                                                             |
59 |                           Constants                         |
60 |                                                             |
61 \------------------------------------------------------------*/
62 /*------------------------------------------------------------\
63 |                                                             |
64 |                            Types                            |
65 |                                                             |
66 \------------------------------------------------------------*/
67 /*------------------------------------------------------------\
68 |                                                             |
69 |                          Variables                          |
70 |                                                             |
71 \------------------------------------------------------------*/
72 /*------------------------------------------------------------\
73 |                                                             |
74 |                          Functions                          |
75 |                                                             |
76 \------------------------------------------------------------*/
77 /*------------------------------------------------------------\
78 |                                                             |
79 |                       Resize Functions                      |
80 |                                                             |
81 \------------------------------------------------------------*/
82 /*------------------------------------------------------------\
83 |                                                             |
84 |                          Aut Resize                         |
85 |                                                             |
86 \------------------------------------------------------------*/
87 
autresize(Source,OldSize,NewSize)88 char *autresize( Source, OldSize, NewSize )
89 
90    char         *Source;
91    unsigned int  OldSize;
92    unsigned int  NewSize;
93 {
94   char *Target;
95 
96   if ( Source == (char *)0 )
97   {
98     return( autalloc( NewSize, 0 ) );
99   }
100 
101   if ( ! AUT_ALLOC_DEBUG )
102   {
103     if ( ! ( Target = realloc( Source, NewSize ) ) )
104     {
105       auterror( AUT_RESIZE_ERROR, (char *)0 );
106     }
107   }
108   else
109   {
110     Target = autallocblock( NewSize );
111     memcpy( Target, Source, ( NewSize > OldSize ) ? OldSize : NewSize );
112     autfreeblock( Source );
113   }
114 
115   if ( NewSize > OldSize )
116   {
117     memset( Target + OldSize, 0, NewSize - OldSize );
118   }
119 
120   return( Target );
121 }
122