xref: /illumos-gate/usr/src/cmd/acct/lib/expand.c (revision 1a2d662a91cee3bf82f41cd47c7ae6f3825d9db2)
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 #include <sys/types.h>
31 #include <sys/param.h>
32 #include <sys/acct.h>
33 
34 #ifdef uts
35 float
36 #else
37 /*
38  * For as long as ct is of type comp_t, and comp_t is defined to be of type
39  * unsigned short, the maximum value of ct will be 2^16-1 ie 65535. Based on
40  * this input value, the maximum value that expand() can return will therefore
41  * be 4292870144. A return type of ulong_t ensures we don't overflow.
42  */
43 ulong_t
44 #endif
45 expand(comp_t ct)
46 {
47 	int e;
48 #ifdef uts
49 	float f;
50 #else
51 	ulong_t f;
52 #endif
53 	e = (ct >> 13) & 07;
54 	f = ct & 017777;
55 
56 	while (e-- > 0)
57 #ifdef uts
58 		f *= 8.0;		/* can't shift a float */
59 #else
60 		f <<=3;
61 #endif
62 
63 	return f;
64 }
65