| 1498 | } |
| 1499 | |
| 1500 | static bool resolve_from_path(const char *name, char *out, size_t outsz) { |
| 1501 | const char *path = getenv("PATH"); |
| 1502 | if (!name || !name[0] || strchr(name, '/') || !path || !path[0]) { |
| 1503 | return false; |
| 1504 | } |
| 1505 | |
| 1506 | const char *cur = path; |
| 1507 | while (*cur) { |
| 1508 | const char *colon = strchr(cur, ':'); |
| 1509 | size_t dir_len = colon ? (size_t)(colon - cur) : strlen(cur); |
| 1510 | if (dir_len > 0 && dir_len < 900) { |
| 1511 | char candidate[1024]; |
| 1512 | int n = snprintf(candidate, sizeof(candidate), "%.*s/%s", (int)dir_len, cur, name); |
| 1513 | if (n > 0 && (size_t)n < sizeof(candidate) && is_executable_file(candidate)) { |
| 1514 | return copy_path(out, outsz, candidate); |
| 1515 | } |
| 1516 | } |
| 1517 | if (!colon) { |
| 1518 | break; |
| 1519 | } |
| 1520 | cur = colon + 1; |
| 1521 | } |
| 1522 | return false; |
| 1523 | } |
| 1524 | |
| 1525 | static bool resolve_self_executable(char *out, size_t outsz) { |
| 1526 | #if defined(__APPLE__) |
no test coverage detected