| 881 | } |
| 882 | |
| 883 | static bool resolve_from_path(const char *name, char *out, size_t outsz) { |
| 884 | const char *path = getenv("PATH"); |
| 885 | if (!name || !name[0] || strchr(name, '/') || !path || !path[0]) { |
| 886 | return false; |
| 887 | } |
| 888 | |
| 889 | const char *cur = path; |
| 890 | while (*cur) { |
| 891 | const char *colon = strchr(cur, ':'); |
| 892 | size_t dir_len = colon ? (size_t)(colon - cur) : strlen(cur); |
| 893 | if (dir_len > 0 && dir_len < 900) { |
| 894 | char candidate[1024]; |
| 895 | int n = snprintf(candidate, sizeof(candidate), "%.*s/%s", (int)dir_len, cur, name); |
| 896 | if (n > 0 && (size_t)n < sizeof(candidate) && is_executable_file(candidate)) { |
| 897 | return copy_path(out, outsz, candidate); |
| 898 | } |
| 899 | } |
| 900 | if (!colon) { |
| 901 | break; |
| 902 | } |
| 903 | cur = colon + 1; |
| 904 | } |
| 905 | return false; |
| 906 | } |
| 907 | |
| 908 | static bool resolve_self_executable(char *out, size_t outsz) { |
| 909 | #if defined(__APPLE__) |
no test coverage detected