MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / sh_dirname

Function sh_dirname

src/pipeline/pass_shell.c:328–351  ·  view source on GitHub ↗

dirname(1), on a value: textual, keeps an anchored path anchored. */

Source from the content-addressed store, hash-verified

326
327/* dirname(1), on a value: textual, keeps an anchored path anchored. */
328static const char *sh_dirname(CBMArena *a, const char *v) {
329 bool anch = v[0] == SH_ANCHOR;
330 const char *p = anch ? v + SKIP_ONE : v;
331 size_t len = strlen(p);
332 while (len > SKIP_ONE && p[len - SKIP_ONE] == '/') {
333 len--;
334 }
335 size_t k = len;
336 while (k > 0 && p[k - SKIP_ONE] != '/') {
337 k--;
338 }
339 if (k == 0) {
340 return anch ? SH_ROOT : ".";
341 }
342 size_t dl = k - SKIP_ONE;
343 while (dl > 0 && p[dl - SKIP_ONE] == '/') {
344 dl--;
345 }
346 if (dl == 0) {
347 return anch ? SH_ROOT : "/";
348 }
349 return anch ? cbm_arena_sprintf(a, "%c%.*s", SH_ANCHOR, (int)dl, p)
350 : cbm_arena_strndup(a, p, dl);
351}
352
353/* basename(1), on a value. */
354static const char *sh_value_basename(CBMArena *a, const char *v) {

Callers 3

sh_eval_subst_commandFunction · 0.85
sh_state_initFunction · 0.85
sh_make_resolveFunction · 0.85

Calls 2

cbm_arena_sprintfFunction · 0.50
cbm_arena_strndupFunction · 0.50

Tested by

no test coverage detected