| ... | @@ -2663,7 +2663,7 @@ pub fn selfExePath(out_buffer: []u8) SelfExePathError![]u8 { | ... | @@ -2663,7 +2663,7 @@ pub fn selfExePath(out_buffer: []u8) SelfExePathError![]u8 { |
| 2663 | /// using a fixed executable directory path: "/zig" | 2663 | /// using a fixed executable directory path: "/zig" |
| 2664 | /// | 2664 | /// |
| 2665 | /// This path can be configured in wasmtime using `--mapdir=/zig::/path/to/zig/dir/` | 2665 | /// This path can be configured in wasmtime using `--mapdir=/zig::/path/to/zig/dir/` |
| 2666 | fn selfExePathWasi(out_buffer: []u8, exe_name: []const u8) SelfExePathError![]const u8 { | 2666 | fn selfExePathWasi(out_buffer: []u8, argv0: []const u8) SelfExePathError![]const u8 { |
| 2667 | var allocator = std.heap.FixedBufferAllocator.init(out_buffer); | 2667 | var allocator = std.heap.FixedBufferAllocator.init(out_buffer); |
| 2668 | var alloc = allocator.allocator(); | 2668 | var alloc = allocator.allocator(); |
| 2669 | | 2669 | |
| ... | @@ -2671,22 +2671,25 @@ fn selfExePathWasi(out_buffer: []u8, exe_name: []const u8) SelfExePathError![]co | ... | @@ -2671,22 +2671,25 @@ fn selfExePathWasi(out_buffer: []u8, exe_name: []const u8) SelfExePathError![]co |
| 2671 | // 1. "/zig/{exe_name}" | 2671 | // 1. "/zig/{exe_name}" |
| 2672 | // 2. "/zig/bin/{exe_name}" | 2672 | // 2. "/zig/bin/{exe_name}" |
| 2673 | const base_paths_to_check = &[_][]const u8{ "/zig", "/zig/bin" }; | 2673 | const base_paths_to_check = &[_][]const u8{ "/zig", "/zig/bin" }; |
| | 2674 | const exe_names_to_check = &[_][]const u8{ path.basename(argv0), "zig.wasm" }; |
| 2674 | | 2675 | |
| 2675 | for (base_paths_to_check) |base_path| { | 2676 | for (base_paths_to_check) |base_path| { |
| 2676 | const test_path = path.join(alloc, &.{ base_path, path.basename(exe_name) }) catch continue; | 2677 | for (exe_names_to_check) |exe_name| { |
| | 2678 | const test_path = path.join(alloc, &.{ base_path, exe_name }) catch continue; |
| 2677 | | 2679 | |
| 2678 | // Make sure it's a file we're pointing to | 2680 | // Make sure it's a file we're pointing to |
| 2679 | const file = os.fstatat(os.wasi.AT.FDCWD, test_path, 0) catch continue; | 2681 | const file = os.fstatat(os.wasi.AT.FDCWD, test_path, 0) catch continue; |
| 2680 | if (file.filetype != .REGULAR_FILE) continue; | 2682 | if (file.filetype != .REGULAR_FILE) continue; |
| 2681 | | 2683 | |
| 2682 | // Path seems to be valid, let's try to turn it into an absolute path | 2684 | // Path seems to be valid, let's try to turn it into an absolute path |
| 2683 | var real_path_buf: [MAX_PATH_BYTES]u8 = undefined; | 2685 | var real_path_buf: [MAX_PATH_BYTES]u8 = undefined; |
| 2684 | if (os.realpath(test_path, &real_path_buf)) |real_path| { | 2686 | if (os.realpath(test_path, &real_path_buf)) |real_path| { |
| 2685 | if (real_path.len > out_buffer.len) | 2687 | if (real_path.len > out_buffer.len) |
| 2686 | return error.NameTooLong; | 2688 | return error.NameTooLong; |
| 2687 | mem.copy(u8, out_buffer, real_path); | 2689 | mem.copy(u8, out_buffer, real_path); |
| 2688 | return out_buffer[0..real_path.len]; | 2690 | return out_buffer[0..real_path.len]; |
| 2689 | } else |_| continue; | 2691 | } else |_| continue; |
| | 2692 | } |
| 2690 | } | 2693 | } |
| 2691 | return error.FileNotFound; | 2694 | return error.FileNotFound; |
| 2692 | } | 2695 | } |