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

Function path_basename

ccan/ccan/tal/path/path.c:425–459  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

423}
424
425char *path_basename(const tal_t *ctx, const char *path)
426{
427 const char *sep;
428 char *ret;
429
430 if (unlikely(!path) && taken(path))
431 return NULL;
432
433 sep = strrchr(path, PATH_SEP);
434 if (!sep)
435 return tal_strdup(ctx, path);
436
437 /* Trailing slashes need to be trimmed. */
438 if (!sep[1]) {
439 const char *end;
440
441 for (end = sep; end != path; end--)
442 if (*end != PATH_SEP)
443 break;
444
445 /* Find *previous* / */
446 for (sep = end; sep >= path && *sep != PATH_SEP; sep--);
447
448 /* All /? Just return / */
449 if (end == sep)
450 ret = tal_strdup(ctx, PATH_SEP_STR);
451 else
452 ret = tal_strndup(ctx, sep+1, end - sep);
453 } else
454 ret = tal_strdup(ctx, sep + 1);
455
456 if (taken(path))
457 tal_free(path);
458 return ret;
459}
460
461/* This reuses str if we're to take it. */
462static char *fixed_string(const tal_t *ctx,

Callers 5

mainFunction · 0.85
plugin_registerFunction · 0.85
plugin_paths_matchFunction · 0.85
mainFunction · 0.85
new_pluginFunction · 0.85

Calls 2

takenFunction · 0.85
tal_freeFunction · 0.85

Tested by 1

mainFunction · 0.68