MCPcopy Create free account
hub / github.com/ElementsProject/lightning / path_dirname

Function path_dirname

ccan/ccan/tal/path/path.c:471–505  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

469}
470
471char *path_dirname(const tal_t *ctx, const char *path)
472{
473 const char *sep;
474
475 if (unlikely(!path) && taken(path))
476 return NULL;
477
478 sep = strrchr(path, PATH_SEP);
479 if (!sep)
480 return fixed_string(ctx, ".", path);
481
482 /* Trailing slashes need to be trimmed. */
483 if (!sep[1]) {
484 const char *end;
485
486 for (end = sep; end != path; end--)
487 if (*end != PATH_SEP)
488 break;
489
490 /* Find *previous* / */
491 for (sep = end; sep > path && *sep != PATH_SEP; sep--);
492 }
493
494 /* In case there are multiple / in a row. */
495 while (sep > path && sep[-1] == PATH_SEP)
496 sep--;
497
498 if (sep == path) {
499 if (path_is_abs(path))
500 return tal_strndup(ctx, path, 1);
501 else
502 return fixed_string(ctx, ".", path);
503 }
504 return tal_strndup(ctx, path, sep - path);
505}
506
507bool path_is_abs(const char *path)
508{

Callers 7

ensure_hsm_secret_existsFunction · 0.85
decrypt_hsmFunction · 0.85
encrypt_hsmFunction · 0.85
mainFunction · 0.85
find_my_directoryFunction · 0.85
mainFunction · 0.85
parse_includeFunction · 0.85

Calls 3

takenFunction · 0.85
fixed_stringFunction · 0.85
path_is_absFunction · 0.85

Tested by 1

mainFunction · 0.68