struct DynLib [src]
Alias for std.dynamic_library.DynLib
Cross-platform dynamic library loading and symbol lookup.
Platform-specific functionality is available through the inner field.
Fields
inner: InnerType
Members
Source
pub 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,
.windows => WindowsDynLib,
.macos, .tvos, .watchos, .ios, .visionos, .freebsd, .netbsd, .openbsd, .dragonfly, .solaris, .illumos => DlDynLib,
else => struct {
const open = @compileError("unsupported platform");
const openZ = @compileError("unsupported platform");
},
};
inner: InnerType,
pub const Error = ElfDynLibError || DlDynLibError || WindowsDynLibError;
/// Trusts the file. Malicious file will be able to execute arbitrary code.
pub fn open(path: []const u8) Error!DynLib {
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 {
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);
}
}