| 2748 | } |
| 2749 | |
| 2750 | static bool cbm_expand_user_path(const char *home_dir, const char *value, char *out, |
| 2751 | size_t out_sz) { |
| 2752 | if (!home_dir || !home_dir[0] || !value || !value[0] || !out || out_sz == 0U) { |
| 2753 | return false; |
| 2754 | } |
| 2755 | int written = -1; |
| 2756 | if (strcmp(value, "~") == 0) { |
| 2757 | written = snprintf(out, out_sz, "%s", home_dir); |
| 2758 | } else if (value[0] == '~' && (value[1] == '/' || value[1] == '\\')) { |
| 2759 | written = snprintf(out, out_sz, "%s/%s", home_dir, value + 2); |
| 2760 | } else if (value[0] == '/' || (isalpha((unsigned char)value[0]) && value[1] == ':' && |
| 2761 | (value[2] == '/' || value[2] == '\\'))) { |
| 2762 | written = snprintf(out, out_sz, "%s", value); |
| 2763 | } |
| 2764 | return written >= 0 && (size_t)written < out_sz; |
| 2765 | } |
| 2766 | |
| 2767 | static void cbm_env_home_dir(const char *env_name, const char *home_dir, const char *fallback, |
| 2768 | char *out, size_t out_sz) { |
no outgoing calls
no test coverage detected