return 1;
}
-// Continues to read line as long as it matches s
-static int consume(char** line, const char* s) {
- char* p = *line;
-
- for (;;) {
- // Successful if we have consumed all of s
- if (!*s)
- break;
-
- // It is bad if we have run out of input
- if (!*p)
- return -EBADMSG;
-
- // The strings don't seem to match
- if (*p != *s)
- return -EBADMSG;
-
- // Advance both pointers
- p++;
- s++;
- }
-
- // Restore the line
- *line = p;
-
- return 0;
-}
-
static int td_source_get_info(td_source* self, rrd_info_t* info,
const char* field, const char* key, rrd_info_type_t type, rrd_info_t** result) {
char* p = NULL;
p = info->key;
// Lines must start with "ds["
- r = consume(&p, "ds[");
+ r = td_string_consume(&p, "ds[");
if (r < 0)
continue;
// After that, we must have the field name
- r = consume(&p, field);
+ r = td_string_consume(&p, field);
if (r < 0)
continue;
// Then, we must have "]."
- r = consume(&p, "].");
+ r = td_string_consume(&p, "].");
if (r < 0)
continue;
// Then we must have the key
- r = consume(&p, key);
+ r = td_string_consume(&p, key);
if (r < 0)
continue;
td_string_rstrip(s);
}
+// Continues to read line as long as it matches s
+static inline int td_string_consume(char** line, const char* s) {
+ char* p = *line;
+
+ for (;;) {
+ // Successful if we have consumed all of s
+ if (!*s)
+ break;
+
+ // It is bad if we have run out of input
+ if (!*p)
+ return -EBADMSG;
+
+ // The strings don't seem to match
+ if (*p != *s)
+ return -EBADMSG;
+
+ // Advance both pointers
+ p++;
+ s++;
+ }
+
+ // Restore the line
+ *line = p;
+
+ return 0;
+}
+
static inline void td_strings_free(char** array) {
for (char** s = array; *s; s++)
free(*s);