| 897 | } |
| 898 | |
| 899 | static bool resolve_from_path(const char *name, char *out, size_t outsz) { |
| 900 | const char *path = getenv("PATH"); |
| 901 | if (!name || !name[0] || strchr(name, '/') || !path || !path[0]) { |
| 902 | return false; |
| 903 | } |
| 904 | |
| 905 | const char *cur = path; |
| 906 | while (*cur) { |
| 907 | const char *colon = strchr(cur, ':'); |
| 908 | size_t dir_len = colon ? (size_t)(colon - cur) : strlen(cur); |
| 909 | if (dir_len > 0 && dir_len < 900) { |
| 910 | char candidate[1024]; |
| 911 | int n = snprintf(candidate, sizeof(candidate), "%.*s/%s", (int)dir_len, cur, name); |
| 912 | if (n > 0 && (size_t)n < sizeof(candidate) && is_executable_file(candidate)) { |
| 913 | return copy_path(out, outsz, candidate); |
| 914 | } |
| 915 | } |
| 916 | if (!colon) { |
| 917 | break; |
| 918 | } |
| 919 | cur = colon + 1; |
| 920 | } |
| 921 | return false; |
| 922 | } |
| 923 | |
| 924 | static bool resolve_self_executable(char *out, size_t outsz) { |
| 925 | #if defined(__APPLE__) |
no test coverage detected