summaryrefslogtreecommitdiff
path: root/tools/perf/util/intlist.c
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2013-01-24 23:17:27 +0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2013-01-24 23:40:53 +0400
commitffe0fb769a6db3b6027d9228b6fecb6b352e4834 (patch)
tree2989ffadf34b1e16316af7d82104d3130ba3073c /tools/perf/util/intlist.c
parent5a3d04d6dc9050b4b4562f5c66aea23f0aa1c003 (diff)
downloadlinux-ffe0fb769a6db3b6027d9228b6fecb6b352e4834.tar.xz
perf tools: Allow passing a list to intlist__new
Just like strlist allows passing a list of entries to parse. Cc: David Ahern <dsahern@gmail.com> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Mike Galbraith <efault@gmx.de> Cc: Namhyung Kim <namhyung@gmail.com> Cc: Paul Mackerras <paulus@samba.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Stephane Eranian <eranian@google.com> Link: http://lkml.kernel.org/n/tip-em50vqvvmlnc6k9tw4xtixus@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/util/intlist.c')
-rw-r--r--tools/perf/util/intlist.c27
1 files changed, 26 insertions, 1 deletions
diff --git a/tools/perf/util/intlist.c b/tools/perf/util/intlist.c
index cbf0c32ce403..11a8d86f7fea 100644
--- a/tools/perf/util/intlist.c
+++ b/tools/perf/util/intlist.c
@@ -73,7 +73,26 @@ struct int_node *intlist__find(struct intlist *ilist, int i)
return node;
}
-struct intlist *intlist__new(void)
+static int intlist__parse_list(struct intlist *ilist, const char *s)
+{
+ char *sep;
+ int err;
+
+ do {
+ long value = strtol(s, &sep, 10);
+ err = -EINVAL;
+ if (*sep != ',' && *sep != '\0')
+ break;
+ err = intlist__add(ilist, value);
+ if (err)
+ break;
+ s = sep + 1;
+ } while (*sep != '\0');
+
+ return err;
+}
+
+struct intlist *intlist__new(const char *slist)
{
struct intlist *ilist = malloc(sizeof(*ilist));
@@ -82,9 +101,15 @@ struct intlist *intlist__new(void)
ilist->rblist.node_cmp = intlist__node_cmp;
ilist->rblist.node_new = intlist__node_new;
ilist->rblist.node_delete = intlist__node_delete;
+
+ if (slist && intlist__parse_list(ilist, slist))
+ goto out_delete;
}
return ilist;
+out_delete:
+ intlist__delete(ilist);
+ return NULL;
}
void intlist__delete(struct intlist *ilist)