mirror of
https://github.com/ipmitool/ipmitool.git
synced 2025-05-10 18:47:22 +00:00
'lib/helper.c', 'include/ipmitool/helper.h' - add str2double()
Commit adds function to handle conversion from string to double. Function has the same concept as other str2*() functions.
This commit is contained in:
parent
bd851bab8f
commit
9b3000e329
@ -65,6 +65,7 @@ struct oemvalstr {
|
|||||||
const char * val2str(uint16_t val, const struct valstr * vs);
|
const char * val2str(uint16_t val, const struct valstr * vs);
|
||||||
const char * oemval2str(uint32_t oem,uint16_t val, const struct oemvalstr * vs);
|
const char * oemval2str(uint32_t oem,uint16_t val, const struct oemvalstr * vs);
|
||||||
|
|
||||||
|
int str2double(const char * str, double * double_ptr);
|
||||||
int str2long(const char * str, int64_t * lng_ptr);
|
int str2long(const char * str, int64_t * lng_ptr);
|
||||||
int str2ulong(const char * str, uint64_t * ulng_ptr);
|
int str2ulong(const char * str, uint64_t * ulng_ptr);
|
||||||
int str2int(const char * str, int32_t * int_ptr);
|
int str2int(const char * str, int32_t * int_ptr);
|
||||||
|
@ -145,6 +145,33 @@ const char * oemval2str(uint32_t oem, uint16_t val,
|
|||||||
return un_str;
|
return un_str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* str2double - safely convert string to double
|
||||||
|
*
|
||||||
|
* @str: source string to convert from
|
||||||
|
* @double_ptr: pointer where to store result
|
||||||
|
*
|
||||||
|
* returns zero on success
|
||||||
|
* returns (-1) if one of args is NULL, (-2) invalid input, (-3) for *flow
|
||||||
|
*/
|
||||||
|
int str2double(const char * str, double * double_ptr)
|
||||||
|
{
|
||||||
|
char * end_ptr = 0;
|
||||||
|
if (!str || !double_ptr)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
*double_ptr = 0;
|
||||||
|
errno = 0;
|
||||||
|
*double_ptr = strtod(str, &end_ptr);
|
||||||
|
|
||||||
|
if (*end_ptr != '\0')
|
||||||
|
return (-2);
|
||||||
|
|
||||||
|
if (errno != 0)
|
||||||
|
return (-3);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
} /* str2double(...) */
|
||||||
|
|
||||||
/* str2long - safely convert string to int64_t
|
/* str2long - safely convert string to int64_t
|
||||||
*
|
*
|
||||||
* @str: source string to convert from
|
* @str: source string to convert from
|
||||||
|
Loading…
x
Reference in New Issue
Block a user