diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2018-06-16 17:01:23 -0400 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2018-06-16 17:01:23 -0400 |
| commit | 48de57d8248d9203b44d28d7749b5d7c1a00deba (patch) | |
| tree | 149fb86d959501ecb2e5e2aac7f688265f729ba6 /std/io.zig | |
| parent | b3a3e2094e8b88e40eecf65d29f39af10442bde4 (diff) | |
| download | zig-48de57d8248d9203b44d28d7749b5d7c1a00deba.tar.gz zig-48de57d8248d9203b44d28d7749b5d7c1a00deba.zip | |
add basic std lib code for loading dynamic libraries
this is going to only work for very basic libraries;
I plan to slowly add more features over time to support more
complicated libraries
Diffstat (limited to 'std/io.zig')
| -rw-r--r-- | std/io.zig | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/std/io.zig b/std/io.zig index a603d0cf5e..cfe1a7f585 100644 --- a/std/io.zig +++ b/std/io.zig @@ -242,11 +242,16 @@ pub fn writeFile(allocator: *mem.Allocator, path: []const u8, data: []const u8) /// On success, caller owns returned buffer. pub fn readFileAlloc(allocator: *mem.Allocator, path: []const u8) ![]u8 { + return readFileAllocAligned(allocator, path, @alignOf(u8)); +} + +/// On success, caller owns returned buffer. +pub fn readFileAllocAligned(allocator: *mem.Allocator, path: []const u8, comptime A: u29) ![]align(A) u8 { var file = try File.openRead(allocator, path); defer file.close(); const size = try file.getEndPos(); - const buf = try allocator.alloc(u8, size); + const buf = try allocator.alignedAlloc(u8, A, size); errdefer allocator.free(buf); var adapter = FileInStream.init(&file); |
