Zig 0.17.0-dev (Split by item)
This is an example of documentation generated by
ZigDoc , an alternative to Zig's built-in
Auto Doc feature. See also
examples in other modes/formats . The project being documented here (as the example) is the Zig library itself.
Zig › std/ › dynamic_library.zig › DlDynLib
DlDynLib
dynamic_library.DlDynLib
pub const DlDynLib = struct
File
Code
pub const DlDynLib = struct {
pub const Error = DlDynLibError ;
handle : *anyopaque ,
pub fn open (path : []const u8 ) Error !DlDynLib {
const path_c = try posix .toPosixPath (path );
return openZ (&path_c );
}
pub fn openZ (path_c : [*:0 ]const u8 ) Error !DlDynLib {
return .{
.handle = std .c .dlopen (path_c , .{ .LAZY = true }) orelse {
return error .FileNotFound ;
},
};
}
pub fn close (self : *DlDynLib ) void {
switch (posix .errno (std .c .dlclose (self .handle ))) {
.SUCCESS => return ,
else => unreachable ,
}
self .* = undefined ;
}
pub fn lookup (self : *DlDynLib , comptime T : type , name : [:0 ]const u8 ) ?T {
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66826
if (@call (.never_tail , std .c .dlsym , .{ self .handle , name .ptr })) |symbol | {
return @as (T , @ptrCast (@alignCast (symbol )));
} else {
return null ;
}
}
pub fn getError () ?[:0 ]const u8 {
return mem .span (std .c .dlerror ());
}
}