xref: /titanic_51/usr/src/cmd/acct/lib/expand.c (revision 1e49577a7fcde812700ded04431b49d67cc57d6d)
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 /*
23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
28 /*	  All Rights Reserved  	*/
29 
30 
31 #pragma ident	"%Z%%M%	%I%	%E% SMI"	/* SVr4.0 1.7	*/
32 
33 #include <sys/types.h>
34 #include <sys/param.h>
35 #include <sys/acct.h>
36 
37 #ifdef uts
38 float
39 #else
40 /*
41  * For as long as ct is of type comp_t, and comp_t is defined to be of type
42  * unsigned short, the maximum value of ct will be 2^16-1 ie 65535. Based on
43  * this input value, the maximum value that expand() can return will therefore
44  * be 4292870144. A return type of ulong_t ensures we don't overflow.
45  */
46 ulong_t
47 #endif
48 expand(comp_t ct)
49 {
50 	int e;
51 #ifdef uts
52 	float f;
53 #else
54 	ulong_t f;
55 #endif
56 	e = (ct >> 13) & 07;
57 	f = ct & 017777;
58 
59 	while (e-- > 0)
60 #ifdef uts
61 		f *= 8.0;		/* can't shift a float */
62 #else
63 		f <<=3;
64 #endif
65 
66 	return f;
67 }
68