+
+ /* Before we recurse, sanity check this is a ccan module. */
+ if (!dir[0]) {
+ size_t i;
+
+ if (!m->info_file
+ && list_empty(&m->c_files)
+ && list_empty(&m->h_files))
+ errx(1, "No _info, C or H files found here!");
+
+ for (i = 0; i < talloc_array_length(subs); i++)
+ add_files(m, subs[i]);
+ }
+ talloc_free(subs);
+}
+
+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);