]> git.ozlabs.org Git - ccan/blobdiff - tools/ccan_dir.c
opt: only use termios if HAVE_SYS_TERMIOS_H is defined
[ccan] / tools / ccan_dir.c
index 0bb9b14457c73aad61a7473085a07232b3af2d4e..6d95e064a5968d463b4528505406a37bd8995029 100644 (file)
@@ -1,4 +1,5 @@
-#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>
 #include "tools.h"
 #include <assert.h>
 #include <string.h>
@@ -22,10 +23,18 @@ static unsigned int ccan_dir_prefix(const char *fulldir)
 
 const char *find_ccan_dir(const char *base)
 {
 
 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;
 }
 }