| ... | ... | @@ -7152,7 +7152,30 @@ fn processExecutableOpen(userdata: ?*anyopaque, flags: File.OpenFlags) std.proce |
| 7152 | 7152 | const prefixed_path_w = try windows.wToPrefixedFileW(null, image_path_name); |
| 7153 | 7153 | return dirOpenFileWtf16(t, null, prefixed_path_w.span(), flags); |
| 7154 | 7154 | }, |
| 7155 | | else => @panic("TODO implement processExecutableOpen"), |
| 7155 | .driverkit, |
| 7156 | .ios, |
| 7157 | .maccatalyst, |
| 7158 | .macos, |
| 7159 | .tvos, |
| 7160 | .visionos, |
| 7161 | .watchos, |
| 7162 | => { |
| 7163 | // _NSGetExecutablePath() returns a path that might be a symlink to |
| 7164 | // the executable. Here it does not matter since we open it. |
| 7165 | var symlink_path_buf: [posix.PATH_MAX + 1]u8 = undefined; |
| 7166 | var n: u32 = symlink_path_buf.len; |
| 7167 | const rc = std.c._NSGetExecutablePath(&symlink_path_buf, &n); |
| 7168 | if (rc != 0) return error.NameTooLong; |
| 7169 | const symlink_path = std.mem.sliceTo(&symlink_path_buf, 0); |
| 7170 | return dirOpenFilePosix(t, .cwd(), symlink_path, flags); |
| 7171 | }, |
| 7172 | else => { |
| 7173 | var buffer: [Dir.max_path_bytes]u8 = undefined; |
| 7174 | const n = try processExecutablePath(t, &buffer); |
| 7175 | buffer[n] = 0; |
| 7176 | const executable_path = buffer[0..n :0]; |
| 7177 | return dirOpenFilePosix(t, .cwd(), executable_path, flags); |
| 7178 | }, |
| 7156 | 7179 | } |
| 7157 | 7180 | } |
| 7158 | 7181 | |
| ... | ... | @@ -7168,21 +7191,17 @@ fn processExecutablePath(userdata: ?*anyopaque, out_buffer: []u8) std.process.Ex |
| 7168 | 7191 | .visionos, |
| 7169 | 7192 | .watchos, |
| 7170 | 7193 | => { |
| 7171 | | // Note that _NSGetExecutablePath() will return "a path" to |
| 7172 | | // the executable not a "real path" to the executable. |
| 7173 | | var symlink_path_buf: [posix.PATH_MAX:0]u8 = undefined; |
| 7174 | | var u32_len: u32 = posix.PATH_MAX + 1; // include the sentinel |
| 7175 | | const rc = std.c._NSGetExecutablePath(&symlink_path_buf, &u32_len); |
| 7194 | // _NSGetExecutablePath() returns a path that might be a symlink to |
| 7195 | // the executable. |
| 7196 | var symlink_path_buf: [posix.PATH_MAX + 1]u8 = undefined; |
| 7197 | var n: u32 = symlink_path_buf.len; |
| 7198 | const rc = std.c._NSGetExecutablePath(&symlink_path_buf, &n); |
| 7176 | 7199 | if (rc != 0) return error.NameTooLong; |
| 7177 | | |
| 7178 | | var real_path_buf: [posix.PATH_MAX]u8 = undefined; |
| 7179 | | const n = Io.Dir.realPathFileAbsolute(ioBasic(t), &symlink_path_buf, &real_path_buf) catch |err| switch (err) { |
| 7200 | const symlink_path = std.mem.sliceTo(&symlink_path_buf, 0); |
| 7201 | return Io.Dir.realPathFileAbsolute(ioBasic(t), symlink_path, out_buffer) catch |err| switch (err) { |
| 7180 | 7202 | error.NetworkNotFound => unreachable, // Windows-only |
| 7181 | 7203 | else => |e| return e, |
| 7182 | 7204 | }; |
| 7183 | | if (n > out_buffer.len) return error.NameTooLong; |
| 7184 | | @memcpy(out_buffer[0..n], real_path_buf[0..n]); |
| 7185 | | return n; |
| 7186 | 7205 | }, |
| 7187 | 7206 | .linux, .serenity => return Io.Dir.readLinkAbsolute(ioBasic(t), "/proc/self/exe", out_buffer) catch |err| switch (err) { |
| 7188 | 7207 | error.UnsupportedReparsePointType => unreachable, // Windows-only |