/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (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
*/
/*
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include "volume_string.h"
#include <ctype.h>
#include <errno.h>
#include <libintl.h>
#include <math.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "volume_error.h"
#include "volume_output.h"
/*
* ******************************************************************
*
* Function prototypes
*
* ******************************************************************
*/
/*
* ******************************************************************
*
* Data
*
* ******************************************************************
*/
/* All-inclusive valid size units */
{"BLOCKS", BYTES_PER_BLOCK},
{"KB", BYTES_PER_KILOBYTE},
{"MB", BYTES_PER_MEGABYTE},
{"GB", BYTES_PER_GIGABYTE},
{"TB", BYTES_PER_TERABYTE},
{NULL, 0}
};
/*
* ******************************************************************
*
* External functions
*
* ******************************************************************
*/
/*
* Concatenates a list of strings. The result must be free()d.
*
* @param numargs
* The number of strings to concatenate.
*
* @param ...
* The strings (type char *) to concatenate.
*
* @return the concatenated string
* if succesful
*
* @return NULL
* if memory could not be allocated
*/
char *
int numargs,
...)
{
int i;
char *cat;
/* Determine length of concatenated string */
for (i = 0; i < numargs; i++) {
}
}
/* Allocate memory for concatenation plus a trailing NULL */
return (NULL);
}
/* Concatenate strings */
for (i = 0; i < numargs; i++) {
}
}
return (cat);
}
/*
* Convert the given string to a uint16_t, verifying that the value
* does not exceed the lower or upper bounds of a uint16_t.
*
* @param str
* the string to convert
*
* @param num
* the addr of the uint16_t
*
* @return 0
* if the given string was converted to a uint16_t
*
* @return -1
* if the string could could not be converted to a number
*
* @return -2
* if the converted number exceeds the lower or upper
* bounds of a uint16_t
*/
int
char *str,
{
long long lnum;
int error = 0;
/* Convert string to long long */
error = -1;
} else {
/*
* Verify that the long long value does not exceed the
* lower or upper bounds of a uint16_t
*/
/* Maximum value of uint16_t */
error = -2;
} else {
}
}
return (error);
}
/*
* Converts the given long long into a string. This string must be
* freed.
*
* @param num
* the long long to convert
*
* @param str
* the addr of the string
*
* @return 0
* if successful
*
* @return ENOMEM
* if the physical limits of the system are exceeded by
* size bytes of memory which cannot be allocated
*
* @return EAGAIN
* if there is not enough memory available to allocate
* size bytes of memory
*/
int
long long num,
char **str)
{
int error = 0;
/* Allocate memory for the string */
} else {
/* Convert the integer to a string */
}
return (error);
}
/*
* Convert a size specification to bytes.
*
* @param str
* a size specification strings of the form
* <value><units>, where valid <units> are specified by
* the units argument and <value> is the (floating-point)
* multiplier of the units
*
* @param bytes
* RETURN: the result of converting the given size string
* to bytes
*
* @return 0
* if successful
*
* @return non-zero
* if an error occurred. Use get_error_string() to
* retrieve the associated error message.
*/
int
char *str,
{
char *unit_str;
long double d;
int error = 0;
int i;
/* Convert <value> string to double */
error = -1;
} else {
/* Trim leading white space */
++unit_str;
}
/* Convert to bytes based on <units> */
d *= units[i].bytes_per_unit;
break;
}
}
/* Was a valid unit string found? */
gettext("missing or invalid units indicator in size: %s"),
str);
error = -1;
}
}
if (error) {
*bytes = 0;
} else {
}
return (error);
}
/*
* Convert bytes to a size specification string.
*
* @param bytes
* the number of bytes
*
* @param str
* RETURN: a size specification strings of the form
* <value><units>, where valid <units> are specified by
* the units argument and <value> is the (floating-point)
* multiplier of the units. This string must be freed.
*
* @return 0
* if successful
*
* @return non-zero
* if an error occurred. Use get_error_string() to
* retrieve the associated error message.
*/
int
char **str,
{
double value;
const char *format;
/* Determine the units to use */
}
}
/* Length of string plus trailing NULL */
if (round) {
format = "%.0f%s";
} else {
format = "%.2f%s";
}
/* Append units to string */
} else {
}
return (error);
}
/*
* Appends a copy of the given string to the given string array,
* ensuring that the last element in the array is NULL. This array
* must be freed via free_string_array.
*
* Note when an error occurs and NULL is returned, array is not freed.
* Subsequently callers should save a pointer to the original array
* until success is verified.
*
* @param array
* the array to append to, or NULL to create a new array
*
* @param str
* the string to copy and add to the array
*
* @return a pointer to the realloc'd (and possibly moved) array
* if succesful
*
* @return NULL
* if unsuccesful
*/
char **
char **array,
char *str)
{
return (NULL);
}
}
/*
* Frees each element of the given string array, then frees the array
* itself.
*
* @param array
* a NULL-terminated string array
*/
void
char **array)
{
int i;
/* Free each available element */
}
/* Free the array itself */
}
/*
* ******************************************************************
*
* Static functions
*
* ******************************************************************
*/
/*
* Appends the given pointer to the given pointer array, ensuring that
* the last element in the array is NULL.
*
* Note when an error occurs and NULL is returned, array is not freed.
* Subsequently callers should save a pointer to the original array
* until success is verified.
*
* @param array
* the array to append to, or NULL to create a new array
*
* @param pointer
* the pointer to add to the array
*
* @return a pointer to the realloc'd (and possibly moved) array
* if succesful
*
* @return NULL
* if unsuccesful
*/
static void *
void **array,
void *pointer)
{
int i = 0;
/* Count the elements currently in the array */
}
/* realloc, adding a slot for the new pointer */
/* Append pointer and terminal NULL */
}
return (newarray);
}