+static int cmp_names(struct ccan_file *const *a, struct ccan_file *const *b,
+ void *unused)
+{
+ return strcmp((*a)->name, (*b)->name);
+}
+
+static void sort_files(struct list_head *list)
+{
+ struct ccan_file **files = NULL, *f;
+ unsigned int i, num;
+
+ num = 0;
+ while ((f = list_top(list, struct ccan_file, list)) != NULL) {
+ files = talloc_realloc(NULL, files, struct ccan_file *, num+1);
+ files[num++] = f;
+ list_del(&f->list);
+ }
+ asort(files, num, cmp_names, NULL);
+
+ for (i = 0; i < num; i++)
+ list_add_tail(list, &files[i]->list);
+ talloc_free(files);
+}
+