+ tal_resize(&ret, rlen + add + strlen(to)+1);
+ memcpy(ret+rlen, src+len, add);
+ if (!next)
+ return ret;
+ len += add;
+ rlen += add;
+ strcpy(ret+rlen, to);
+ rlen += strlen(to);
+ len += strlen(from);
+ }
+}
+
+/* This is a terrible hack. We scan for ccan/ strings. */
+static char **get_one_safe_deps(const void *ctx,
+ const char *dir,
+ const char *style,
+ char *(*unused)(const void *, const char *))
+{
+ char **deps, **lines, *raw, *fname;
+ unsigned int i, n;
+ bool correct_style = false;
+
+ fname = path_join(ctx, dir, "_info");
+ raw = tal_grab_file(fname, fname, NULL);
+ if (!raw)
+ errx(1, "Could not open %s", fname);
+
+ /* Replace \n by actual line breaks, and split it. */
+ lines = tal_strsplit(raw, replace(raw, raw, "\\n", "\n"), "\n",
+ STR_EMPTY_OK);
+
+ deps = tal_arr(ctx, char *, tal_count(lines));
+
+ for (n = i = 0; lines[i]; i++) {
+ char *str;
+ unsigned int len;
+
+ /* Ignore lines starting with # (e.g. #include) */
+ if (lines[i][0] == '#')
+ continue;
+
+ if (strstr(lines[i], "\"testdepends\""))
+ correct_style = streq(style, "testdepends");
+ else if (strstr(lines[i], "\"depends\""))
+ correct_style = streq(style, "depends");
+
+ if (!correct_style)
+ continue;
+
+ /* Start of line, or after ". */
+ if (strstarts(lines[i], "ccan/"))
+ str = lines[i];
+ else {
+ str = strstr(lines[i], "\"ccan/");
+ if (!str)
+ continue;
+ str++;
+ }
+
+ len = strspn(str, "/abcdefghijklmnopqrstuvxwyz12345678980_");
+ if (len == 5)
+ continue;
+ deps[n++] = tal_strndup(deps, str, len);
+ }
+ deps[n] = NULL;
+ tal_free(fname);
+
+ /* Make sure tal_array_length() works */
+ tal_resize(&deps, n + 1);