| 2292 | } |
| 2293 | |
| 2294 | static bool cbm_openclaw_state_dir(const char *home_dir, char *out, size_t out_sz) { |
| 2295 | char internal_home[CLI_BUF_1K]; |
| 2296 | if (!cbm_openclaw_internal_home(home_dir, internal_home, sizeof(internal_home))) { |
| 2297 | return false; |
| 2298 | } |
| 2299 | char env_buf[CLI_BUF_1K]; |
| 2300 | const char *custom = cbm_safe_getenv("OPENCLAW_STATE_DIR", env_buf, sizeof(env_buf), NULL); |
| 2301 | if (custom && custom[0]) { |
| 2302 | return cbm_expand_user_path(internal_home, custom, out, out_sz); |
| 2303 | } |
| 2304 | char profile_buf[CLI_BUF_256]; |
| 2305 | const char *profile = |
| 2306 | cbm_safe_getenv("OPENCLAW_PROFILE", profile_buf, sizeof(profile_buf), NULL); |
| 2307 | const char *separator = ""; |
| 2308 | const char *profile_name = ""; |
| 2309 | if (profile && profile[0] && strcmp(profile, "default") != 0) { |
| 2310 | for (const unsigned char *p = (const unsigned char *)profile; *p; p++) { |
| 2311 | if (!isalnum(*p) && *p != '-' && *p != '_') { |
| 2312 | return false; |
| 2313 | } |
| 2314 | } |
| 2315 | separator = "-"; |
| 2316 | profile_name = profile; |
| 2317 | } |
| 2318 | int written = snprintf(out, out_sz, "%s/.openclaw%s%s", internal_home, separator, profile_name); |
| 2319 | return written > 0 && (size_t)written < out_sz; |
| 2320 | } |
| 2321 | |
| 2322 | static bool cbm_openclaw_config_path(const char *home_dir, char *out, size_t out_sz) { |
| 2323 | char internal_home[CLI_BUF_1K]; |
no test coverage detected