-#include <ccan/talloc/talloc.h>
+#include <ccan/err/err.h>
+#include <ccan/tal/path/path.h>
#include "tools.h"
#include <assert.h>
#include <string.h>
const char *find_ccan_dir(const char *base)
{
- unsigned int prefix = ccan_dir_prefix(base);
+ static char *ccan_dir;
- if (!prefix)
- return NULL;
-
- return talloc_strndup(NULL, base, prefix);
+ if (!ccan_dir) {
+ if (base[0] != '/') {
+ const char *tmpctx = path_cwd(NULL);
+ find_ccan_dir(path_join(tmpctx, tmpctx, base));
+ tal_free(tmpctx);
+ } else {
+ unsigned int prefix = ccan_dir_prefix(base);
+ if (prefix)
+ ccan_dir = tal_strndup(NULL, base, prefix);
+ }
+ }
+ return ccan_dir;
}