Add support for retrieving float and double variables from the configuration.

remotes/origin/master-1.0.x
Victor Julien 15 years ago
parent b60d2c4345
commit cb0bb668eb

@ -309,6 +309,68 @@ ConfGetBool(char *name, int *val)
return 1;
}
/**
* \brief Retrieve a configuration value as a double
*
* \param name Name of configuration parameter to get.
* \param val Pointer to an double that will be set the
* configuration value.
*
* \retval 1 will be returned if the name is found and was properly
* converted to a double, otherwise 0 will be returned.
*/
int
ConfGetDouble(char *name, double *val)
{
char *strval;
double tmpdo;
char *endptr;
if (ConfGet(name, &strval) == 0)
return 0;
errno = 0;
tmpdo = strtod(strval, &endptr);
if (strval[0] == '\0' || *endptr != '\0')
return 0;
if (errno == ERANGE)
return 0;
*val = tmpdo;
return 1;
}
/**
* \brief Retrieve a configuration value as a float
*
* \param name Name of configuration parameter to get.
* \param val Pointer to an float that will be set the
* configuration value.
*
* \retval 1 will be returned if the name is found and was properly
* converted to a double, otherwise 0 will be returned.
*/
int
ConfGetFloat(char *name, float *val)
{
char *strval;
double tmpfl;
char *endptr;
if (ConfGet(name, &strval) == 0)
return 0;
errno = 0;
tmpfl = strtof(strval, &endptr);
if (strval[0] == '\0' || *endptr != '\0')
return 0;
if (errno == ERANGE)
return 0;
*val = tmpfl;
return 1;
}
/**
* \brief Remove (and SCFree) the provided configuration node.
*/

@ -53,6 +53,8 @@ ConfNode *ConfGetRootNode(void);
int ConfGet(char *name, char **vptr);
int ConfGetInt(char *name, intmax_t *val);
int ConfGetBool(char *name, int *val);
int ConfGetDouble(char *name, double *val);
int ConfGetFloat(char *name, float *val);
int ConfSet(char *name, char *val, int allow_override);
void ConfDump(void);
void ConfNodeDump(ConfNode *node, const char *prefix);

Loading…
Cancel
Save