pub const DynLib = struct inner: InnerTypepub fn open(path: []const u8) Error!DynLibTrusts the file. Malicious file will be able to execute arbitrary code.
pub fn openZ(path_c: [*: 0]const u8) Error!DynLibTrusts the file. Malicious file will be able to execute arbitrary code.
pub fn close(self: *DynLib) voidTrusts the file.
pub fn lookup(self: *DynLib, comptime T: type, name: [: 0]const u8) ?T14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57pub const DynLib = struct {
const InnerType = switch (native_os) {
.linux => if (!builtin.link_libc or builtin.abi == .musl and builtin.link_mode == .static)
ElfDynLib
else
DlDynLib,
.driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos, .freebsd, .netbsd, .openbsd, .dragonfly, .illumos => DlDynLib,
else => struct {
const open = @compileError("unsupported platform");
const openZ = @compileError("unsupported platform");
},
};
inner: InnerType,
pub const Error = ElfDynLibError || DlDynLibError;
/// Trusts the file. Malicious file will be able to execute arbitrary code.
pub fn open(path: []const u8) Error!DynLib {
if (InnerType == ElfDynLib) {
return .{ .inner = try InnerType.open(path, null) };
} else {
return .{ .inner = try InnerType.open(path) };
}
}
/// Trusts the file. Malicious file will be able to execute arbitrary code.
pub fn openZ(path_c: [*:0]const u8) Error!DynLib {
if (InnerType == ElfDynLib) {
return .{ .inner = try InnerType.openZ(path_c, null) };
} else {
return .{ .inner = try InnerType.openZ(path_c) };
}
}
/// Trusts the file.
pub fn close(self: *DynLib) void {
return self.inner.close();
}
pub fn lookup(self: *DynLib, comptime T: type, name: [:0]const u8) ?T {
return self.inner.lookup(T, name);
}
}
Cross-platform dynamic library loading and symbol lookup. Platform-specific functionality is available through the
innerfield.