Generates random numbers just like random(). This further ensures that
the random number generator is seeded exactly once per process.
+=item B<rrd_strtodbl>
+
+an rrd aware string to double convertor which sets rrd_error in if there is a problem
+and uses the return code exclusively for conversion status reporting.
+
=item B<rrd_strtod>
works like normal strtod, but it is locale independent (and thread safe)
/* make sure update time is always moving forward. We use double here since
update does support subsecond precision for timestamps ... */
- if ( ( rrd_strtodbl( value, &eostamp, &stamp, "error while parsing time stamp" ) != 1 ) || *eostamp != ':')
+ if ( ( rrd_strtodbl( value, &eostamp, &stamp, NULL) != 1 ) || *eostamp != ':')
{
pthread_mutex_unlock(&cache_lock);
return send_response(sock, RESP_ERR,
im->forceleftspace = 1;
break;
case 'T':
- rrd_strtodbl(optarg, 0, &(im->tabwidth), "Function rrd_graph_options, option 'T'");
+ if (rrd_strtodbl(optarg, 0, &(im->tabwidth), "option -T") != 2)
+ return;
break;
case 'S':
im->step = atoi(optarg);
break;
};
if (sscanf(optarg, "%[-0-9.e+]:%d", double_str , &im->ylabfact) == 2) {
- rrd_strtodbl( double_str, 0, &(im->ygridstep), "Function rrd_graph_options, option 'y'");
+ if (rrd_strtodbl( double_str, 0, &(im->ygridstep), "option -y") != 2){
+ return;
+ }
if (im->ygridstep <= 0) {
rrd_set_error("grid step must be > 0");
return;
"%[-0-9.e+]:%[-0-9.e+]",
double_str,
double_str2 ) != 2) {
- rrd_strtodbl( double_str, 0, &(im->grid_dash_on), "Function rrd_graph_options, option 1008");
- rrd_strtodbl( double_str2, 0, &(im->grid_dash_off), "Function rrd_graph_options, option 1008");
- rrd_set_error("expected grid-dash format float:float");
- return;
+ if ( rrd_strtodbl( double_str, 0, &(im->grid_dash_on),NULL) !=2
+ || rrd_strtodbl( double_str2, 0, &(im->grid_dash_off), NULL) != 2 ){
+ rrd_set_error("expected grid-dash format float:float");
+ return;
+ }
}
break;
case 1009: /* enable dynamic labels */
if(sscanf(optarg,
"%[-0-9.e+]:%[-0-9.e+]",
double_str,
- double_str2 ) == 2) {
- rrd_strtodbl( double_str, 0, &(im->second_axis_scale), "Function rrd_graph_options, option 1002");
- rrd_strtodbl( double_str2, 0, &(im->second_axis_shift), "Function rrd_graph_options, option 1002");
+ double_str2 ) == 2
+ && rrd_strtodbl( double_str, 0, &(im->second_axis_scale),NULL) == 2
+ && rrd_strtodbl( double_str2, 0, &(im->second_axis_shift),NULL) == 2){
if(im->second_axis_scale==0){
rrd_set_error("the second_axis_scale must not be 0");
return;
}
break;
case 'u':
- rrd_strtodbl(optarg, 0, &(im->maxval), "Function rrd_graph_options, option 'u'");
+ if (rrd_strtodbl(optarg, 0, &(im->maxval), "option -u") != 2){
+ return;
+ }
break;
case 'l':
- rrd_strtodbl(optarg, 0, &(im->minval), "Function rrd_graph_options, option 'l'");
+ if (rrd_strtodbl(optarg, 0, &(im->minval), "option -l") != 2){
+ return;
+ }
break;
case 'b':
im->base = atol(optarg);
double size = 1;
int end;
- if (sscanf(optarg, "%10[A-Z]:%[-0-9.e+]%n", prop, double_str, &end) >= 2) {
- rrd_strtodbl( double_str, 0, &size, "Function rrd_graph_options, option 'n'" );
+ if (sscanf(optarg, "%10[A-Z]:%[-0-9.e+]%n", prop, double_str, &end) >= 2
+ && rrd_strtodbl( double_str, 0, &size, NULL) == 2) {
int sindex, propidx;
if ((sindex = text_prop_conv(prop)) != -1) {
break;
}
case 'm':
- rrd_strtodbl(optarg, 0, &(im->zoom), "Function rrd_graph_options, option 'm'");
+ if (rrd_strtodbl(optarg, 0, &(im->zoom), "option -m") != 2){
+ return;
+ }
if (im->zoom <= 0.0) {
rrd_set_error("zoom factor must be > 0");
return;
n = 0;
sscanf(str, "%20[-0-9.e+],%29[A-Z]%n", double_str, func, &n);
- if ( rrd_strtodbl( str, NULL, ¶m, "Function vdef_parse" ) != 2){
- rrd_clear_error();
+ if ( rrd_strtodbl( str, NULL, ¶m, NULL) != 2 ){
n = 0;
sscanf(str, "%29[A-Z]%n", func, &n);
if (n == (int) strlen(str)) { /* matched */
unsigned int strtod_ret;
*extra=NULL;
- if( rrd_strtodbl( v, extra, val, "Function getDouble" ) != 2 ) {
- return -1;
- }
-
- strtod_ret = rrd_strtodbl( v, extra, val, "Function getDouble" );
+ strtod_ret = rrd_strtodbl( v, extra, val, NULL);
/* see rrd_strtodbl's return values for more infromation */
- if( strtod_ret == 0 )
- return -1;
- else if( strtod_ret == 1 )
- return 1;
- else if( strtod_ret == 2 )
- return 0;
- else
- return -2;
+ switch (rrd_strtodbl( v, extra, val, NULL)){
+ case 0:
+ return -1;
+ break;
+ case 1:
+ return 1;
+ break;
+ case 2:
+ return 0;
+ break;
+ default:
+ return -2;
+ break;
+ }
}
int addToArguments(parsedargs_t* pa, char*key, char*value, int cnt) {
xmlFree(text);
return 0;
}
- if ( rrd_strtodbl((char *)text,NULL, &temp, "Function xml_get_double") != 2 ){
+ if ( rrd_strtodbl((char *)text,NULL, &temp, NULL) != 2 ){
rrd_set_error("ling %d: get_xml_double from '%s' %s",
xmlTextReaderGetParserLineNumber(reader),
text,rrd_strerror(errno));
if ( local_endptr == (char *)str ) {
/* no conversion has been done */
/* for inputs like "abcdj", i.e. no number at all */
- if( error == NULL ) {
- rrd_set_error("Cannot convert %s to float", str);
- } else {
+ if( error ) {
rrd_set_error("%s - Cannot convert %s to float", error, str);
}
return 0;
} else if( local_endptr[0] != '\0' ) {
/* conversion has been done, but whole string is not a number */
/* for inputs like "33.343djdjk" */
- if( error == NULL ) {
- rrd_set_error("Converted %s to %lf, but cannot convert %s",
- str, *dbl, local_endptr);
- } else {
+ if( error ) {
rrd_set_error("%s - Converted %s to %lf, but cannot convert %s",
error, str, *dbl, local_endptr);
}
return 2;
} else {
/* just to be safe */
- if( error == NULL )
- rrd_set_error("Internal error. Something is seriously wrong '%s'", str);
- else
+ if( error ) {
rrd_set_error("%s - Internal error. Something is seriously wrong '%s'",error, str);
-
+ }
return 3;
}
}
case 'i':
matches = sscanf(optarg, DS_NAM_FMT ":%[-0-9.e+]", ds_nam, double_str);
if( matches >= 1 ) {
- strtod_ret_val = rrd_strtodbl( double_str, 0, &min, "Function rrd_tune, option i" );
+ strtod_ret_val = rrd_strtodbl( double_str, NULL, &min, NULL );
}
if ((matches < 1) || (strtod_ret_val != 2)) {
case 'a':
matches = sscanf(optarg, DS_NAM_FMT ":%[-0-9.e+]", ds_nam, double_str);
if( matches >= 1 ) {
- strtod_ret_val = rrd_strtodbl( double_str, 0, &max, "Function rrd_tune, option i" );
+ strtod_ret_val = rrd_strtodbl( double_str, NULL, &max, NULL );
}
if ((matches < 1 ) || (strtod_ret_val != 2)) {
signed short rra_idx = -1;
unsigned int strtod_ret_val;
- strtod_ret_val = rrd_strtodbl(arg, 0, ¶m, "Error while parsing Holt-Winters parameter");
+ strtod_ret_val = rrd_strtodbl(arg, NULL, ¶m, NULL);
/* read the value */
if ((strtod_ret_val == 1 || strtod_ret_val == 2 ) &&
(param <= 0.0 || param >= 1.0) ) {
unsigned int strtod_ret_val;
/* read the value */
- strtod_ret_val = rrd_strtodbl(arg, 0, ¶m, "Error while parsing Holt-Winters parameter, function set_hesmootharg");
+ strtod_ret_val = rrd_strtodbl(arg, NULL, ¶m, NULL);
/* in order to avoid smoothing of SEASONAL or DEVSEASONAL, we need to
* the 0.0 value*/
if ( (strtod_ret_val == 1 || strtod_ret_val == 2 ) &&
signed short rra_idx = -1;
unsigned int strtod_ret_val;
- strtod_ret_val = rrd_strtodbl(arg, 0, ¶m, "Function set_deltaarg" );
+ strtod_ret_val = rrd_strtodbl(arg, NULL, ¶m, NULL);
if ((strtod_ret_val == 1 || strtod_ret_val == 2) &&
param < 0.1) {
rrd_set_error("Parameter specified is too small");
*current_time = tmp_time.tv_sec;
*current_time_usec = tmp_time.tv_usec;
} else {
- if ( rrd_strtodbl( updvals[0], 0, &tmp, "error while parsing time in get_time_from_reading") != 2) {
+ if ( rrd_strtodbl( updvals[0], NULL, &tmp, "error while parsing time in get_time_from_reading") != 2) {
return -1;
};
if (tmp < 0.0){
}
break;
case DST_ABSOLUTE:
- if( rrd_strtodbl(updvals[ds_idx + 1], 0, &pdp_new[ds_idx], "Function update_pdp_prep, case DST_ABSOLUTE" ) != 2 ) {
+ if( rrd_strtodbl(updvals[ds_idx + 1], NULL, &pdp_new[ds_idx], "Function update_pdp_prep, case DST_ABSOLUTE" ) != 2 ) {
return -1;
}
rate = pdp_new[ds_idx] / interval;
break;
case DST_GAUGE:
- if( rrd_strtodbl( updvals[ds_idx + 1], 0, &tmp, "Function update_pdp_prep, case DST_GAUGE") == 2 ) {
+ if( rrd_strtodbl( updvals[ds_idx + 1], NULL, &tmp, "Function update_pdp_prep, case DST_GAUGE") == 2 ) {
pdp_new[ds_idx] = tmp * interval;
} else {
return -1;