authorgravatar for greg@unrelenting.technologyGreg V <greg@unrelenting.technology> 2018-10-17 18:01:00+03:00
committergravatar for greg@unrelenting.technologyGreg V <greg@unrelenting.technology> 2018-10-20 15:15:01+03:00
log7a3f0a55d9a481f260935f26426ee4508d44cb18
tree7795b31e616664f46c12e32c0dea599b685f10a6
parent1829c093032764ef397a02d0d7512254f5bb4ad0

Add freebsd to more things


5 files changed, 21 insertions(+), 10 deletions(-)

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