| 598 | } |
| 599 | |
| 600 | const char *cbm_resolve_cache_dir(void) { |
| 601 | static CBM_TLS char buf[CBM_SZ_4K]; |
| 602 | static const char missing[] = "\x1f" |
| 603 | "CBM_CACHE_DIR_MISSING" |
| 604 | "\x1f"; |
| 605 | const char *configured = cbm_safe_getenv("CBM_CACHE_DIR", buf, sizeof(buf), missing); |
| 606 | if (!configured) { |
| 607 | /* Present but not representable in the product path bound. */ |
| 608 | return NULL; |
| 609 | } |
| 610 | if (strcmp(configured, missing) != 0 && configured[0]) { |
| 611 | cbm_normalize_path_sep(buf); |
| 612 | return buf; |
| 613 | } |
| 614 | const char *home = cbm_get_home_dir(); |
| 615 | if (!home) { |
| 616 | return NULL; |
| 617 | } |
| 618 | int written = snprintf(buf, sizeof(buf), "%s/.cache/codebase-memory-mcp", home); |
| 619 | if (written <= 0 || (size_t)written >= sizeof(buf)) { |
| 620 | buf[0] = '\0'; |
| 621 | return NULL; |
| 622 | } |
| 623 | return buf; |
| 624 | } |