| 2320 | } |
| 2321 | |
| 2322 | static bool cbm_openclaw_state_dir(const char *home_dir, char *out, size_t out_sz) { |
| 2323 | char internal_home[CLI_BUF_1K]; |
| 2324 | if (!cbm_openclaw_internal_home(home_dir, internal_home, sizeof(internal_home))) { |
| 2325 | return false; |
| 2326 | } |
| 2327 | char env_buf[CLI_BUF_1K]; |
| 2328 | const char *custom = cbm_safe_getenv("OPENCLAW_STATE_DIR", env_buf, sizeof(env_buf), NULL); |
| 2329 | if (custom && custom[0]) { |
| 2330 | return cbm_expand_user_path(internal_home, custom, out, out_sz); |
| 2331 | } |
| 2332 | char profile_buf[CLI_BUF_256]; |
| 2333 | const char *profile = |
| 2334 | cbm_safe_getenv("OPENCLAW_PROFILE", profile_buf, sizeof(profile_buf), NULL); |
| 2335 | const char *separator = ""; |
| 2336 | const char *profile_name = ""; |
| 2337 | if (profile && profile[0] && strcmp(profile, "default") != 0) { |
| 2338 | for (const unsigned char *p = (const unsigned char *)profile; *p; p++) { |
| 2339 | if (!isalnum(*p) && *p != '-' && *p != '_') { |
| 2340 | return false; |
| 2341 | } |
| 2342 | } |
| 2343 | separator = "-"; |
| 2344 | profile_name = profile; |
| 2345 | } |
| 2346 | int written = snprintf(out, out_sz, "%s/.openclaw%s%s", internal_home, separator, profile_name); |
| 2347 | return written > 0 && (size_t)written < out_sz; |
| 2348 | } |
| 2349 | |
| 2350 | static bool cbm_openclaw_config_path(const char *home_dir, char *out, size_t out_sz) { |
| 2351 | char internal_home[CLI_BUF_1K]; |
no test coverage detected