/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
*/
#include <libintl.h>
#include <string.h>
#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>
#include <errno.h>
#include <strings.h>
#include <limits.h>
#include "utils.h"
static char *pname;
char *
{
if (p == NULL)
p = arg0;
else
p++;
pname = p;
return (pname);
}
/*PRINTFLIKE1*/
void
{
if (err)
else
}
1000LLU,
1000LLU * 1000,
1000LLU * 1000 * 1000,
1000LLU * 1000 * 1000 * 1000,
1000LLU * 1000 * 1000 * 1000 * 1000,
1000LLU * 1000 * 1000 * 1000 * 1000 * 1000
};
1024LLU,
1024LLU * 1024,
1024LLU * 1024 * 1024,
1024LLU * 1024 * 1024 * 1024,
1024LLU * 1024 * 1024 * 1024 * 1024,
1024LLU * 1024 * 1024 * 1024 * 1024 * 1024
};
int
double result;
double value;
int index = 0;
char *endptr;
int cmp;
int hasmodifier = 0;
if (modifierout)
*modifierout = NULL;
if (unitout)
/*
* first check for hex value, which cannot be scaled, as
* hex letters cannot be disserned from modifier or unit letters
*/
/* unit cannot be required on hex values */
return (SCALED_INVALID_UNIT);
errno = 0;
if (errno) {
return (SCALED_OVERFLOW);
else
return (SCALED_INVALID_NUMBER);
}
if (*endptr != '\0')
return (SCALED_INVALID_NUMBER);
/* compute width of decimal equivalent */
if (widthout) {
(void) snprintf(
}
return (0);
}
/* scan out numeric value */
errno = 0;
if (errno) {
return (SCALED_OVERFLOW);
else
return (SCALED_INVALID_NUMBER);
}
return (SCALED_INVALID_NUMBER);
/* no negative values */
return (SCALED_INVALID_NUMBER);
if (value < 0.0)
return (SCALED_INVALID_NUMBER);
/* compute width of number string */
if (widthout)
/* check possible modifier */
if (*endptr != '\0') {
index = 0;
else
if (cmp == 0) {
if (modifierout)
if (result > UINT64_MAX)
return (SCALED_OVERFLOW);
hasmodifier = 1;
break;
}
index++;
}
}
/* if there is no modifier, value must be an integer */
if (!hasmodifier) {
errno = 0;
if (errno) {
return (SCALED_OVERFLOW);
else
return (SCALED_INVALID_NUMBER);
}
return (SCALED_INVALID_NUMBER);
}
/* if unit is present when no unit is allowed, fail */
return (SCALED_INVALID_UNIT);
/* check for missing unit when unit is required */
!(flags & SCALED_UNIT_OPTIONAL_FLAG) &&
(*endptr == '\0'))
return (SCALED_INVALID_UNIT);
/* validate unit */
/* allow for missing unit if it is optional */
if ((flags & SCALED_UNIT_OPTIONAL_FLAG) &&
(*endptr == '\0'))
return (0);
else
if (cmp != 0)
return (SCALED_INVALID_UNIT);
return (SCALED_INVALID_UNIT);
if (unitout)
}
return (0);
}
int
int index = 0;
int count;
int width;
int decimals = 0;
double value;
/* don't scale if there is no reason to */
if (flags & SCALED_PAD_WIDTH_FLAG)
else
width = 0;
/* LINTED */
if (widthout)
if (modifierout)
*modifierout = NULL;
return (0);
}
break;
break;
}
if (modifierout)
decimals++;
/* LINTED */
/* reduce decimal places if we've overshot the desired width */
decimals--;
break;
}
}
if (flags & SCALED_PAD_WIDTH_FLAG)
else
width = 0;
/* LINTED */
if (widthout)
return (0);
}
int
int ret;
if (ret)
return (ret);
return (ret);
}
int
int ret;
char *modifier1;
char *modifier2;
int i;
int width;
int width1;
int width2;
/*
* remove padding flag, so strings to compare will not have
* whitespace
*/
/* determine each number's width and modifier */
if (ret)
return (0);
if (ret)
return (0);
/*
* determine the width and modifier to use for comparison.
* Use widest width and smallest modifier.
* Rescale to new width and modifier
*/
else {
break;
}
break;
}
}
}
width = 0;
/*
* Convert first number to width and modifier.
* This is done for the following reasons:
* 1. In case first number is hecadecimal. This will convert
* it to decimal
* 2. In case the first number has < the minimum number of
* columns.
* 3. The first number is missing an optional unit string.
* 4. Fix casing of modifier and unit.
*/
if (ret)
return (0);
/* convert second number to width and modifier matching first number */
if (ret)
return (0);
/* numbers are equal if strings match */
}
int
int ret;
char *modifier;
int width;
/* determine for number's width and modifier */
if (ret)
return (0);
/*
* Convert first number to width and modifier.
* This is done for the following reasons:
* 1. In case first number is hecadecimal. This will convert
* it to decimal
* 2. In case the first number has < the minimum number of
* columns.
* 3. The first number is missing an optional unit string.
* 4. Fix casing of modifier and unit.
*/
if (ret)
return (0);
/* convert second number to width and modifier matching first number */
if (ret)
return (0);
/* numbers are equal if strings match */
}