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 › Io › Threaded › fileMemoryMapCreate Private Function fileMemoryMapCreate Doc Source Private Function std.Io.Threaded.fileMemoryMapCreate
fn fileMemoryMapCreate (
userdata : ?*anyopaque ,
file : File ,
options : File .MemoryMap .CreateOptions ,
) File .MemoryMap .CreateError !File .MemoryMap Params userdata : ?*anyopaque file : File options : File .MemoryMap .CreateOptions File Io/Threaded.zig: 18361
18361
18362
18363
18364
18365
18366
18367
18368
18369
18370
18371
18372
18373
18374
18375
18376
18377
18378
18379
18380
18381
18382
18383
18384
18385
18386
18387
18388
18389
18390
18391
18392
18393
18394
18395
18396
18397
18398
18399
18400 fn fileMemoryMapCreate (
userdata : ?*anyopaque ,
file : File ,
options : File .MemoryMap .CreateOptions ,
) File .MemoryMap .CreateError !File .MemoryMap {
const t : *Threaded = @ptrCast (@alignCast (userdata ));
const offset = options .offset ;
const len = options .len ;
if (!t .disable_memory_mapping ) {
if (createFileMap (file , options .protection , offset , options .populate , len )) |result | {
return result ;
} else |err | switch (err ) {
error .Unseekable , error .Canceled , error .AccessDenied => |e | return e ,
error .OperationUnsupported => {},
else => {
if (builtin .mode == .debug )
std .log .warn ("memory mapping failed with {t}, falling back to file operations" , .{err });
},
}
}
const gpa = t .allocator ;
const page_size = std .heap .pageSize ();
const alignment : Alignment = .fromByteUnits (page_size );
const memory = m : {
const ptr = gpa .rawAlloc (len , alignment , @returnAddress ()) orelse return error .OutOfMemory ;
break :m ptr [0 ..len ];
};
errdefer gpa .rawFree (memory , alignment , @returnAddress ());
if (!options .undefined_contents ) try mmSyncRead (file , memory , offset );
return .{
.file = file ,
.offset = offset ,
.memory = @alignCast (memory ),
.section = null ,
};
}