| ... | ... | @@ -104,9 +104,9 @@ pub const LinuxDynLib = struct { |
| 104 | 104 | memory: []align(mem.page_size) u8, |
| 105 | 105 | |
| 106 | 106 | /// Trusts the file |
| 107 | | pub fn open(allocator: *mem.Allocator, path: []const u8) !DynLib { |
| 108 | | const fd = try os.open(path, 0, os.O_RDONLY | os.O_CLOEXEC); |
| 109 | | errdefer os.close(fd); |
| 107 | pub fn open(path: []const u8) !DynLib { |
| 108 | const fd = try std.os.posixOpen(path, 0, linux.O_RDONLY | linux.O_CLOEXEC); |
| 109 | errdefer std.os.close(fd); |
| 110 | 110 | |
| 111 | 111 | const size = @intCast(usize, (try os.fstat(fd)).size); |
| 112 | 112 | |
| ... | ... | @@ -244,15 +244,21 @@ fn checkver(def_arg: *elf.Verdef, vsym_arg: i32, vername: []const u8, strings: [ |
| 244 | 244 | } |
| 245 | 245 | |
| 246 | 246 | pub const WindowsDynLib = struct { |
| 247 | | allocator: *mem.Allocator, |
| 248 | 247 | dll: windows.HMODULE, |
| 249 | 248 | |
| 250 | | pub fn open(allocator: *mem.Allocator, path: []const u8) !WindowsDynLib { |
| 251 | | const wpath = try windows.sliceToPrefixedFileW(path); |
| 249 | pub fn open(path: []const u8) !WindowsDynLib { |
| 250 | const wpath = try win_util.sliceToPrefixedFileW(path); |
| 252 | 251 | |
| 253 | 252 | return WindowsDynLib{ |
| 254 | | .allocator = allocator, |
| 255 | | .dll = try windows.LoadLibraryW(&wpath), |
| 253 | .dll = windows.LoadLibraryW(&wpath) orelse { |
| 254 | const err = windows.GetLastError(); |
| 255 | switch (err) { |
| 256 | windows.ERROR.FILE_NOT_FOUND => return error.FileNotFound, |
| 257 | windows.ERROR.PATH_NOT_FOUND => return error.FileNotFound, |
| 258 | windows.ERROR.MOD_NOT_FOUND => return error.FileNotFound, |
| 259 | else => return os.unexpectedErrorWindows(err), |
| 260 | } |
| 261 | }, |
| 256 | 262 | }; |
| 257 | 263 | } |
| 258 | 264 | |
| ... | ... | @@ -273,7 +279,7 @@ test "dynamic_library" { |
| 273 | 279 | else => return, |
| 274 | 280 | }; |
| 275 | 281 | |
| 276 | | const dynlib = DynLib.open(std.debug.global_allocator, libname) catch |err| { |
| 282 | const dynlib = DynLib.open(libname) catch |err| { |
| 277 | 283 | testing.expect(err == error.FileNotFound); |
| 278 | 284 | return; |
| 279 | 285 | }; |