Replace a C library strcspn(3) call with the more portable glib
g_strstr_len(3) routine. This is possible since a single separator
is searched for, no actual "set of characters" is involved.
As a byproduct, this eliminates a "late" reference to 'cnt' at the
bottom of the routine, after the value was assigned in a rather distant
location at the top of the routine. The cost of strlen() should be
acceptable for a buffer with a single digit total length.
{
char valstr[7 + 1];
const char *valp;
{
char valstr[7 + 1];
const char *valp;
- int i, cnt, is_ol, dot_pos;
+ int i, cnt, is_ol;
+ const char *dot_pos;
/*
* Strip all spaces from bytes 0-6. By copying all
/*
* Strip all spaces from bytes 0-6. By copying all
sr_spew("%s(), cannot convert number", __func__);
return SR_ERR_DATA;
}
sr_spew("%s(), cannot convert number", __func__);
return SR_ERR_DATA;
}
- dot_pos = strcspn(valstr, ".");
- if (dot_pos < cnt)
- *exponent = -(cnt - dot_pos - 1);
+ dot_pos = g_strstr_len(valstr, -1, ".");
+ if (dot_pos)
+ *exponent = -(valstr + strlen(valstr) - dot_pos - 1);
- sr_spew("%s(), display value is %f", __func__, *result);
+ sr_spew("%s(), display value is %f, exponent %d",
+ __func__, *result, *exponent);