+out:
+ ds_put_format(ds, ")");
+}
+
+static int
+parse_flags(const char *s, const char *(*bit_to_string)(uint32_t),
+ uint32_t *res)
+{
+ uint32_t result = 0;
+ int n = 0;
+
+ if (s[n] != '(') {
+ return -EINVAL;
+ }
+ n++;
+
+ while (s[n] != ')') {
+ unsigned long long int flags;
+ uint32_t bit;
+ int n0;
+
+ if (sscanf(&s[n], "%lli%n", &flags, &n0) > 0 && n0 > 0) {
+ n += n0 + (s[n + n0] == ',');
+ result |= flags;
+ continue;
+ }
+
+ for (bit = 1; bit; bit <<= 1) {
+ const char *name = bit_to_string(bit);
+ size_t len;
+
+ if (!name) {
+ continue;
+ }
+
+ len = strlen(name);
+ if (!strncmp(s + n, name, len) &&
+ (s[n + len] == ',' || s[n + len] == ')')) {
+ result |= bit;
+ n += len + (s[n + len] == ',');
+ break;
+ }
+ }
+
+ if (!bit) {
+ return -EINVAL;
+ }
+ }
+ n++;
+
+ *res = result;
+ return n;