device->plugin->set_configuration(devcnt, SR_HWCAP_CAPTUREFILE, val);
g_ptr_array_add(capturefiles, val);
} else if (!strcmp(keys[j], "samplerate")) {
- tmp_u64 = sr_parse_sizestring(val);
+ sr_parse_sizestring(val, &tmp_u64);
device->plugin->set_configuration(devcnt, SR_HWCAP_SAMPLERATE, &tmp_u64);
} else if (!strcmp(keys[j], "unitsize")) {
tmp_u64 = strtoull(val, NULL, 10);
char *sr_period_string(uint64_t frequency);
char **sr_parse_triggerstring(struct sr_device *device,
const char *triggerstring);
-uint64_t sr_parse_sizestring(const char *sizestring);
+int sr_parse_sizestring(const char *sizestring, uint64_t *size);
uint64_t sr_parse_timestring(const char *timestring);
gboolean sr_parse_boolstring(const char *boolstring);
* Spaces (but not other whitespace) between value and suffix are allowed.
*
* @param sizestring A string containing a (decimal) size value.
- * @return The string's size value as uint64_t.
+ * @param size Pointer to uint64_t which will contain the string's size value.
+ * @return SR_OK or error code
*
- * TODO: Error handling.
*/
-uint64_t sr_parse_sizestring(const char *sizestring)
+int sr_parse_sizestring(const char *sizestring, uint64_t *size)
{
- int multiplier;
- uint64_t val;
+ int multiplier, done;
char *s;
- val = strtoull(sizestring, &s, 10);
+ *size = strtoull(sizestring, &s, 10);
multiplier = 0;
- while (s && *s && multiplier == 0) {
+ done = FALSE;
+ while (s && *s && multiplier == 0 && !done) {
switch (*s) {
case ' ':
break;
multiplier = SR_GHZ(1);
break;
default:
- val = 0;
- multiplier = -1;
+ done = TRUE;
+ s--;
}
s++;
}
if (multiplier > 0)
- val *= multiplier;
+ *size *= multiplier;
+
+ if (*s && strcasecmp(s, "Hz"))
+ return SR_ERR;
- return val;
+ return SR_OK;
}
/**