| 2845 | } |
| 2846 | |
| 2847 | static bool cbm_openclaw_state_dir(const char *home_dir, char *out, size_t out_sz) { |
| 2848 | char internal_home[CLI_BUF_1K]; |
| 2849 | if (!cbm_openclaw_internal_home(home_dir, internal_home, sizeof(internal_home))) { |
| 2850 | return false; |
| 2851 | } |
| 2852 | char env_buf[CLI_BUF_1K]; |
| 2853 | const char *custom = cbm_safe_getenv("OPENCLAW_STATE_DIR", env_buf, sizeof(env_buf), NULL); |
| 2854 | if (custom && custom[0]) { |
| 2855 | return cbm_expand_user_path(internal_home, custom, out, out_sz); |
| 2856 | } |
| 2857 | char profile_buf[CLI_BUF_256]; |
| 2858 | const char *profile = |
| 2859 | cbm_safe_getenv("OPENCLAW_PROFILE", profile_buf, sizeof(profile_buf), NULL); |
| 2860 | const char *separator = ""; |
| 2861 | const char *profile_name = ""; |
| 2862 | if (profile && profile[0] && strcmp(profile, "default") != 0) { |
| 2863 | for (const unsigned char *p = (const unsigned char *)profile; *p; p++) { |
| 2864 | if (!isalnum(*p) && *p != '-' && *p != '_') { |
| 2865 | return false; |
| 2866 | } |
| 2867 | } |
| 2868 | separator = "-"; |
| 2869 | profile_name = profile; |
| 2870 | } |
| 2871 | int written = snprintf(out, out_sz, "%s/.openclaw%s%s", internal_home, separator, profile_name); |
| 2872 | return written > 0 && (size_t)written < out_sz; |
| 2873 | } |
| 2874 | |
| 2875 | static bool cbm_openclaw_config_path(const char *home_dir, char *out, size_t out_sz) { |
| 2876 | char internal_home[CLI_BUF_1K]; |
no test coverage detected