How to get from abspath dir1 to abspath dir2? */
| 543 | |
| 544 | /* How to get from abspath dir1 to abspath dir2? */ |
| 545 | static const char *relative(const tal_t *ctx, const char *dir1, const char *dir2) |
| 546 | { |
| 547 | char **dir1_parts, **dir2_parts; |
| 548 | size_t common; |
| 549 | char *backwards; |
| 550 | |
| 551 | /* Collapse double /, and split into parts */ |
| 552 | dir1_parts = path_split(tmpctx, take(path_simplify(NULL, dir1))); |
| 553 | dir2_parts = path_split(tmpctx, take(path_simplify(NULL, dir2))); |
| 554 | |
| 555 | for (common = 0; |
| 556 | dir1_parts[common] |
| 557 | && dir2_parts[common] |
| 558 | && streq(dir1_parts[common], dir2_parts[common]); |
| 559 | common++); |
| 560 | |
| 561 | /* We append .. for every non-shared part in dir1_parts */ |
| 562 | for (size_t i = common; dir1_parts[i]; i++) |
| 563 | dir1_parts[i] = ".."; |
| 564 | |
| 565 | backwards = tal_strjoin(tmpctx, dir1_parts + common, PATH_SEP_STR, STR_TRAIL); |
| 566 | return tal_fmt(ctx, "%s%s", backwards, |
| 567 | tal_strjoin(tmpctx, dir2_parts + common, PATH_SEP_STR, STR_NO_TRAIL)); |
| 568 | } |
| 569 | |
| 570 | /* Determine the correct daemon dir. */ |
| 571 | static void find_subdaemons_and_plugins(struct lightningd *ld, const char *argv0) |
no test coverage detected