self_argv.ha (607B)
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 match (exec::lookup(os::args[0])) { 13 case let path: str => 14 const file = os::open(path)?; 15 match (open(file)) { 16 case let img: image => 17 return img; 18 case let err: io::error => 19 return err; 20 case errors::invalid => 21 abort("Running program image is not a valid ELF file"); 22 }; 23 case void => 24 return errors::noentry: fs::error; 25 }; 26 };