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 /*
24 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
25 * Use is subject to license terms.
26 */
27
28 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
29 /* All Rights Reserved */
30
31 #pragma ident "%Z%%M% %I% %E% SMI"
32
33 /*
34 * convert and copy
35 */
36
37 #include <stdio.h>
38 #include <signal.h>
39 #include <fcntl.h>
40 #include <sys/param.h>
41 #include <sys/types.h>
42 #include <sys/sysmacros.h>
43 #include <sys/stat.h>
44 #include <unistd.h>
45 #include <stdlib.h>
1625 }
1626 }
1627 if (*s != '\0')
1628 {
1629 return (0);
1630 }
1631
1632 true:
1633 cs--;
1634 string = cs;
1635 return (1);
1636 }
1637
1638 /* number ************************************************************* */
1639 /* */
1640 /* Convert a numeric arg to binary */
1641 /* */
1642 /* Arg: big - maximum valid input number */
1643 /* Global arg: string - pointer to command arg */
1644 /* */
1645 /* Valid forms: 123 | 123k | 123w | 123b | 123*123 | 123x123 */
1646 /* plus combinations such as 2b*3kw*4w */
1647 /* */
1648 /* Return: converted number */
1649 /* */
1650 /* ******************************************************************** */
1651
1652 static unsigned long long
1653 number(big)
1654 long long big;
1655 {
1656 char *cs;
1657 long long n;
1658 long long cut = BIG / 10; /* limit to avoid overflow */
1659
1660 cs = string;
1661 n = 0;
1662 while ((*cs >= '0') && (*cs <= '9') && (n <= cut))
1663 {
1664 n = n*10 + *cs++ - '0';
1665 }
1666 for (;;)
1667 {
1668 switch (*cs++)
1669 {
1670
1671 case 'k':
1672 n *= 1024;
1673 continue;
1674
1675 case 'w':
1676 n *= 2;
1677 continue;
1678
1679 case 'b':
1680 n *= BSIZE;
1681 continue;
1682
1683 case '*':
1684 case 'x':
1685 string = cs;
1686 n *= number(BIG);
1687
1688 /* FALLTHROUGH */
1689 /* Fall into exit test, recursion has read rest of string */
1690 /* End of string, check for a valid number */
|
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 /*
24 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
25 * Use is subject to license terms.
26 * Copyright 2012, Josef 'Jeff' Sipek <jeffpc@31bits.net>. All rights reserved.
27 */
28
29 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
30 /* All Rights Reserved */
31
32 #pragma ident "%Z%%M% %I% %E% SMI"
33
34 /*
35 * convert and copy
36 */
37
38 #include <stdio.h>
39 #include <signal.h>
40 #include <fcntl.h>
41 #include <sys/param.h>
42 #include <sys/types.h>
43 #include <sys/sysmacros.h>
44 #include <sys/stat.h>
45 #include <unistd.h>
46 #include <stdlib.h>
1626 }
1627 }
1628 if (*s != '\0')
1629 {
1630 return (0);
1631 }
1632
1633 true:
1634 cs--;
1635 string = cs;
1636 return (1);
1637 }
1638
1639 /* number ************************************************************* */
1640 /* */
1641 /* Convert a numeric arg to binary */
1642 /* */
1643 /* Arg: big - maximum valid input number */
1644 /* Global arg: string - pointer to command arg */
1645 /* */
1646 /* Valid forms: 123 | 123k | 123M | 123G | 123T | 123P | 123E | 123Z | */
1647 /* 123w | 123b | 123*123 | 123x123 */
1648 /* plus combinations such as 2b*3kw*4w */
1649 /* */
1650 /* Return: converted number */
1651 /* */
1652 /* ******************************************************************** */
1653
1654 static unsigned long long
1655 number(big)
1656 long long big;
1657 {
1658 char *cs;
1659 long long n;
1660 long long cut = BIG / 10; /* limit to avoid overflow */
1661
1662 cs = string;
1663 n = 0;
1664 while ((*cs >= '0') && (*cs <= '9') && (n <= cut))
1665 {
1666 n = n*10 + *cs++ - '0';
1667 }
1668 for (;;)
1669 {
1670 switch (*cs++)
1671 {
1672
1673 case 'Z':
1674 n *= 1024;
1675 /* FALLTHROUGH */
1676
1677 case 'E':
1678 n *= 1024;
1679 /* FALLTHROUGH */
1680
1681 case 'P':
1682 n *= 1024;
1683 /* FALLTHROUGH */
1684
1685 case 'T':
1686 n *= 1024;
1687 /* FALLTHROUGH */
1688
1689 case 'G':
1690 n *= 1024;
1691 /* FALLTHROUGH */
1692
1693 case 'M':
1694 n *= 1024;
1695 /* FALLTHROUGH */
1696
1697 case 'k':
1698 n *= 1024;
1699 continue;
1700
1701 case 'w':
1702 n *= 2;
1703 continue;
1704
1705 case 'b':
1706 n *= BSIZE;
1707 continue;
1708
1709 case '*':
1710 case 'x':
1711 string = cs;
1712 n *= number(BIG);
1713
1714 /* FALLTHROUGH */
1715 /* Fall into exit test, recursion has read rest of string */
1716 /* End of string, check for a valid number */
|