| 1 |
// SPDX-License-Identifier: MPL-2.0 |
| 2 |
// (c) Hare authors <https://harelang.org> |
| 3 |
|
| 4 |
use errors; |
| 5 |
use fs; |
| 6 |
use io; |
| 7 |
use os; |
| 8 |
use os::exec; |
| 9 |
|
| 10 |
// Fallback implementation of self() that performs path resolution on argv[0] |
| 11 |
fn self_argv() (image | io::error | fs::error) = { |
| 12 |
const path = exec::lookup(os::args[0])?; |
| 13 |
const file = os::open(path)?; |
| 14 |
match (open(file)) { |
| 15 |
case let img: image => |
| 16 |
return img; |
| 17 |
case let err: io::error => |
| 18 |
return err; |
| 19 |
case errors::invalid => |
| 20 |
abort("Running program image is not a valid ELF file"); |
| 21 |
}; |
| 22 |
}; |