comparison usr/src/cmd/fmli/sys/varshrink.c @ 0:c9caec207d52 b86

Initial porting based on b86
author Koji Uno <koji.uno@sun.com>
date Tue, 02 Jun 2009 18:56:50 +0900
parents
children 1a15d5aaf794
comparison
equal deleted inserted replaced
-1:000000000000 0:c9caec207d52
1 /*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
8 *
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
13 *
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 *
20 * CDDL HEADER END
21 */
22 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
23 /* All Rights Reserved */
24
25
26 /*
27 * Copyright (c) 1986 AT&T
28 * All Rights Reserved
29 */
30 #ident "@(#)varshrink.c 1.6 05/06/08 SMI" /* SVr4.0 1.3 */
31
32 #include <stdio.h>
33 #include "wish.h"
34 #include "var_arrays.h"
35
36 /*
37 * shrink the actual space used by a v_array as much as possible
38 * note that this requires the process to allocate more space
39 * before giving some back, so it may actually INCREASE the data
40 * segment size of the process. If used, array_shrink should be
41 * called before adding things to other v_arrays, since perhaps
42 * one of them can take advantage of the freed space.
43 */
44 struct v_array *
45 array_shrink(array)
46 struct v_array array[];
47 {
48 register struct v_array *ptr;
49 register struct v_array *newptr;
50
51 ptr = v_header(array);
52 if ((newptr = (struct v_array *)realloc(ptr, sizeof(struct v_array) + ptr->tot_used * ptr->ele_size)) == NULL)
53 return NULL;
54 return v_body(newptr); /* chged ptr to newptr. abs k14.2 */
55 }