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 standard library.
std › posix › mmap Public Function mmap Doc Source 642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676 pub fn mmap (
ptr : ?[*]align (page_size_min ) u8 ,
length : usize ,
prot : PROT ,
flags : MAP ,
fd : fd_t ,
offset : u64 ,
) MMapError ![]align (page_size_min ) u8 {
const mmap_sym = if (lfs64_abi ) system .mmap64 else system .mmap ;
const rc = mmap_sym (ptr , length , prot , @bitCast (flags ), fd , @bitCast (offset ));
const err : E = if (builtin .link_libc ) blk : {
if (rc != std .c .MAP_FAILED ) return @as ([*]align (page_size_min ) u8 , @ptrCast (@alignCast (rc )))[0 ..length ];
break :blk @fromBackingInt (@intCast (system ._errno ().*));
} else blk : {
const err = errno (rc );
if (err == .SUCCESS ) return @as ([*]align (page_size_min ) u8 , @ptrFromInt (rc ))[0 ..length ];
break :blk err ;
};
switch (err ) {
.SUCCESS => unreachable ,
.TXTBSY => return error .AccessDenied ,
.ACCES => return error .AccessDenied ,
.PERM => return error .PermissionDenied ,
.AGAIN => return error .LockedMemoryLimitExceeded ,
.BADF => unreachable , // Always a race condition.
.OVERFLOW => unreachable , // The number of pages used for length + offset would overflow.
.NODEV => return error .MemoryMappingNotSupported ,
.INVAL => unreachable , // Invalid parameters to mmap()
.MFILE => return error .ProcessFdQuotaExceeded ,
.NFILE => return error .SystemFdQuotaExceeded ,
.NOMEM => return error .OutOfMemory ,
.EXIST => return error .MappingAlreadyExists ,
else => return unexpectedErrno (err ),
}
}
Map files or devices into memory.
lengthdoes not need to be aligned. Use of a mapped region can result in these signals: