| author | |
| committer | |
| log | 7a3f0a55d9a481f260935f26426ee4508d44cb18 |
| tree | 7795b31e616664f46c12e32c0dea599b685f10a6 |
| parent | 1829c093032764ef397a02d0d7512254f5bb4ad0 |
5 files changed, 21 insertions(+), 10 deletions(-)
std/debug/index.zig+2| ... | ... | @@ -1078,6 +1078,8 @@ pub const DebugInfo = switch (builtin.os) { |
| 1078 | 1078 | self.elf.close(); |
| 1079 | 1079 | } |
| 1080 | 1080 | }, |
| 1081 | builtin.Os.freebsd => struct.{ | |
| 1082 | }, | |
| 1081 | 1083 | else => @compileError("Unsupported OS"), |
| 1082 | 1084 | }; |
| 1083 | 1085 |
std/heap.zig+3-3| ... | ... | @@ -69,7 +69,7 @@ pub const DirectAllocator = struct.{ |
| 69 | 69 | const self = @fieldParentPtr(DirectAllocator, "allocator", allocator); |
| 70 | 70 | |
| 71 | 71 | switch (builtin.os) { |
| 72 | Os.linux, Os.macosx, Os.ios => { | |
| 72 | Os.linux, Os.macosx, Os.ios, Os.freebsd => { | |
| 73 | 73 | const p = os.posix; |
| 74 | 74 | const alloc_size = if (alignment <= os.page_size) n else n + alignment; |
| 75 | 75 | const addr = p.mmap(null, alloc_size, p.PROT_READ | p.PROT_WRITE, p.MAP_PRIVATE | p.MAP_ANONYMOUS, -1, 0); |
| ... | ... | @@ -120,7 +120,7 @@ pub const DirectAllocator = struct.{ |
| 120 | 120 | const self = @fieldParentPtr(DirectAllocator, "allocator", allocator); |
| 121 | 121 | |
| 122 | 122 | switch (builtin.os) { |
| 123 | Os.linux, Os.macosx, Os.ios => { | |
| 123 | Os.linux, Os.macosx, Os.ios, Os.freebsd => { | |
| 124 | 124 | if (new_size <= old_mem.len) { |
| 125 | 125 | const base_addr = @ptrToInt(old_mem.ptr); |
| 126 | 126 | const old_addr_end = base_addr + old_mem.len; |
| ... | ... | @@ -165,7 +165,7 @@ pub const DirectAllocator = struct.{ |
| 165 | 165 | const self = @fieldParentPtr(DirectAllocator, "allocator", allocator); |
| 166 | 166 | |
| 167 | 167 | switch (builtin.os) { |
| 168 | Os.linux, Os.macosx, Os.ios => { | |
| 168 | Os.linux, Os.macosx, Os.ios, Os.freebsd => { | |
| 169 | 169 | _ = os.posix.munmap(@ptrToInt(bytes.ptr), bytes.len); |
| 170 | 170 | }, |
| 171 | 171 | Os.windows => { |
std/os/file.zig+3-3| ... | ... | @@ -229,7 +229,7 @@ pub const File = struct.{ |
| 229 | 229 | |
| 230 | 230 | pub fn seekForward(self: File, amount: isize) !void { |
| 231 | 231 | switch (builtin.os) { |
| 232 | Os.linux, Os.macosx, Os.ios => { | |
| 232 | Os.linux, Os.macosx, Os.ios, Os.freebsd => { | |
| 233 | 233 | const result = posix.lseek(self.handle, amount, posix.SEEK_CUR); |
| 234 | 234 | const err = posix.getErrno(result); |
| 235 | 235 | if (err > 0) { |
| ... | ... | @@ -260,7 +260,7 @@ pub const File = struct.{ |
| 260 | 260 | |
| 261 | 261 | pub fn seekTo(self: File, pos: usize) !void { |
| 262 | 262 | switch (builtin.os) { |
| 263 | Os.linux, Os.macosx, Os.ios => { | |
| 263 | Os.linux, Os.macosx, Os.ios, Os.freebsd => { | |
| 264 | 264 | const ipos = try math.cast(isize, pos); |
| 265 | 265 | const result = posix.lseek(self.handle, ipos, posix.SEEK_SET); |
| 266 | 266 | const err = posix.getErrno(result); |
| ... | ... | @@ -294,7 +294,7 @@ pub const File = struct.{ |
| 294 | 294 | |
| 295 | 295 | pub fn getPos(self: File) !usize { |
| 296 | 296 | switch (builtin.os) { |
| 297 | Os.linux, Os.macosx, Os.ios => { | |
| 297 | Os.linux, Os.macosx, Os.ios, Os.freebsd => { | |
| 298 | 298 | const result = posix.lseek(self.handle, 0, posix.SEEK_CUR); |
| 299 | 299 | const err = posix.getErrno(result); |
| 300 | 300 | if (err > 0) { |
std/os/index.zig+3-3| ... | ... | @@ -3,7 +3,7 @@ const builtin = @import("builtin"); |
| 3 | 3 | const Os = builtin.Os; |
| 4 | 4 | const is_windows = builtin.os == Os.windows; |
| 5 | 5 | const is_posix = switch (builtin.os) { |
| 6 | builtin.Os.linux, builtin.Os.macosx => true, | |
| 6 | builtin.Os.linux, builtin.Os.macosx, builtin.Os.freebsd => true, | |
| 7 | 7 | else => false, |
| 8 | 8 | }; |
| 9 | 9 | const os = @This(); |
| ... | ... | @@ -42,7 +42,7 @@ pub const time = @import("time.zig"); |
| 42 | 42 | |
| 43 | 43 | pub const page_size = 4 * 1024; |
| 44 | 44 | pub const MAX_PATH_BYTES = switch (builtin.os) { |
| 45 | Os.linux, Os.macosx, Os.ios => posix.PATH_MAX, | |
| 45 | Os.linux, Os.macosx, Os.ios, Os.freebsd => posix.PATH_MAX, | |
| 46 | 46 | // Each UTF-16LE character may be expanded to 3 UTF-8 bytes. |
| 47 | 47 | // If it would require 4 UTF-8 bytes, then there would be a surrogate |
| 48 | 48 | // pair in the UTF-16LE, and we (over)account 3 bytes for it that way. |
| ... | ... | @@ -103,7 +103,7 @@ const math = std.math; |
| 103 | 103 | /// library implementation. |
| 104 | 104 | pub fn getRandomBytes(buf: []u8) !void { |
| 105 | 105 | switch (builtin.os) { |
| 106 | Os.linux => while (true) { | |
| 106 | Os.linux, Os.freebsd => while (true) { | |
| 107 | 107 | // TODO check libc version and potentially call c.getrandom. |
| 108 | 108 | // See #397 |
| 109 | 109 | const errno = posix.getErrno(posix.getrandom(buf.ptr, buf.len, 0)); |
std/os/path.zig+10-1| ... | ... | @@ -1161,7 +1161,7 @@ pub fn realC(out_buffer: *[os.MAX_PATH_BYTES]u8, pathname: [*]const u8) RealErro |
| 1161 | 1161 | const pathname_w = try windows_util.cStrToPrefixedFileW(pathname); |
| 1162 | 1162 | return realW(out_buffer, pathname_w); |
| 1163 | 1163 | }, |
| 1164 | Os.macosx, Os.ios, Os.freebsd => { | |
| 1164 | Os.macosx, Os.ios => { | |
| 1165 | 1165 | // TODO instead of calling the libc function here, port the implementation to Zig |
| 1166 | 1166 | const err = posix.getErrno(posix.realpath(pathname, out_buffer)); |
| 1167 | 1167 | switch (err) { |
| ... | ... | @@ -1188,6 +1188,15 @@ pub fn realC(out_buffer: *[os.MAX_PATH_BYTES]u8, pathname: [*]const u8) RealErro |
| 1188 | 1188 | |
| 1189 | 1189 | return os.readLinkC(out_buffer, proc_path.ptr); |
| 1190 | 1190 | }, |
| 1191 | Os.freebsd => { // XXX requires fdescfs | |
| 1192 | const fd = try os.posixOpenC(pathname, posix.O_PATH | posix.O_NONBLOCK | posix.O_CLOEXEC, 0); | |
| 1193 | defer os.close(fd); | |
| 1194 | ||
| 1195 | var buf: ["/dev/fd/-2147483648".len]u8 = undefined; | |
| 1196 | const proc_path = fmt.bufPrint(buf[0..], "/dev/fd/{}\x00", fd) catch unreachable; | |
| 1197 | ||
| 1198 | return os.readLinkC(out_buffer, proc_path.ptr); | |
| 1199 | }, | |
| 1191 | 1200 | else => @compileError("TODO implement os.path.real for " ++ @tagName(builtin.os)), |
| 1192 | 1201 | } |
| 1193 | 1202 | } |