| author | |
| committer | |
| log | d2059f907b037d0495c820290b1062df3781567f |
| tree | f5d619186ab73aa563de221fdd08738fcda14c03 |
| parent | 09b8f3eb5f661e682495dd5800db9f9b4237227d |
| signature |
2 files changed, 19 insertions(+), 0 deletions(-)
File.zig+13| ... | ... | @@ -170,3 +170,16 @@ pub const Kind = enum { |
| 170 | 170 | unix_socket, |
| 171 | 171 | unknown, |
| 172 | 172 | }; |
| 173 | ||
| 174 | /// Maps file content into memory with a single syscall. | |
| 175 | /// If length is null it will also call stat. | |
| 176 | pub fn mmap(self: File) ![]const u8 { | |
| 177 | return sys.mmap( | |
| 178 | null, | |
| 179 | (try self.stat()).size, | |
| 180 | sys.PROT.READ, | |
| 181 | sys.MAP.PRIVATE, | |
| 182 | @intFromEnum(self.fd), | |
| 183 | 0, | |
| 184 | ); | |
| 185 | } |
nfs.zig+6| ... | ... | @@ -36,3 +36,9 @@ pub fn stderr() File { |
| 36 | 36 | pub fn memfd_create(name: [*:0]const u8, flags: c_uint) !File { |
| 37 | 37 | return .{ .fd = @enumFromInt(try sys.memfd_create(name, flags)) }; |
| 38 | 38 | } |
| 39 | ||
| 40 | /// Free a region of memory allocated with mmap. | |
| 41 | /// Any error calling munmap is ignored. | |
| 42 | pub fn munmap(region: []const u8) void { | |
| 43 | return sys.munmap(region.ptr, region.len) catch {}; | |
| 44 | } |