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) {
10781078 self.elf.close();
10791079 }
10801080 },
1081 builtin.Os.freebsd => struct.{
1082 },
10811083 else => @compileError("Unsupported OS"),
10821084};
10831085
std/heap.zig+3-3
......@@ -69,7 +69,7 @@ pub const DirectAllocator = struct.{
6969 const self = @fieldParentPtr(DirectAllocator, "allocator", allocator);
7070
7171 switch (builtin.os) {
72 Os.linux, Os.macosx, Os.ios => {
72 Os.linux, Os.macosx, Os.ios, Os.freebsd => {
7373 const p = os.posix;
7474 const alloc_size = if (alignment <= os.page_size) n else n + alignment;
7575 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.{
120120 const self = @fieldParentPtr(DirectAllocator, "allocator", allocator);
121121
122122 switch (builtin.os) {
123 Os.linux, Os.macosx, Os.ios => {
123 Os.linux, Os.macosx, Os.ios, Os.freebsd => {
124124 if (new_size <= old_mem.len) {
125125 const base_addr = @ptrToInt(old_mem.ptr);
126126 const old_addr_end = base_addr + old_mem.len;
......@@ -165,7 +165,7 @@ pub const DirectAllocator = struct.{
165165 const self = @fieldParentPtr(DirectAllocator, "allocator", allocator);
166166
167167 switch (builtin.os) {
168 Os.linux, Os.macosx, Os.ios => {
168 Os.linux, Os.macosx, Os.ios, Os.freebsd => {
169169 _ = os.posix.munmap(@ptrToInt(bytes.ptr), bytes.len);
170170 },
171171 Os.windows => {
std/os/file.zig+3-3
......@@ -229,7 +229,7 @@ pub const File = struct.{
229229
230230 pub fn seekForward(self: File, amount: isize) !void {
231231 switch (builtin.os) {
232 Os.linux, Os.macosx, Os.ios => {
232 Os.linux, Os.macosx, Os.ios, Os.freebsd => {
233233 const result = posix.lseek(self.handle, amount, posix.SEEK_CUR);
234234 const err = posix.getErrno(result);
235235 if (err > 0) {
......@@ -260,7 +260,7 @@ pub const File = struct.{
260260
261261 pub fn seekTo(self: File, pos: usize) !void {
262262 switch (builtin.os) {
263 Os.linux, Os.macosx, Os.ios => {
263 Os.linux, Os.macosx, Os.ios, Os.freebsd => {
264264 const ipos = try math.cast(isize, pos);
265265 const result = posix.lseek(self.handle, ipos, posix.SEEK_SET);
266266 const err = posix.getErrno(result);
......@@ -294,7 +294,7 @@ pub const File = struct.{
294294
295295 pub fn getPos(self: File) !usize {
296296 switch (builtin.os) {
297 Os.linux, Os.macosx, Os.ios => {
297 Os.linux, Os.macosx, Os.ios, Os.freebsd => {
298298 const result = posix.lseek(self.handle, 0, posix.SEEK_CUR);
299299 const err = posix.getErrno(result);
300300 if (err > 0) {
std/os/index.zig+3-3
......@@ -3,7 +3,7 @@ const builtin = @import("builtin");
33const Os = builtin.Os;
44const is_windows = builtin.os == Os.windows;
55const is_posix = switch (builtin.os) {
6 builtin.Os.linux, builtin.Os.macosx => true,
6 builtin.Os.linux, builtin.Os.macosx, builtin.Os.freebsd => true,
77 else => false,
88};
99const os = @This();
......@@ -42,7 +42,7 @@ pub const time = @import("time.zig");
4242
4343pub const page_size = 4 * 1024;
4444pub 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,
4646 // Each UTF-16LE character may be expanded to 3 UTF-8 bytes.
4747 // If it would require 4 UTF-8 bytes, then there would be a surrogate
4848 // pair in the UTF-16LE, and we (over)account 3 bytes for it that way.
......@@ -103,7 +103,7 @@ const math = std.math;
103103/// library implementation.
104104pub fn getRandomBytes(buf: []u8) !void {
105105 switch (builtin.os) {
106 Os.linux => while (true) {
106 Os.linux, Os.freebsd => while (true) {
107107 // TODO check libc version and potentially call c.getrandom.
108108 // See #397
109109 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
11611161 const pathname_w = try windows_util.cStrToPrefixedFileW(pathname);
11621162 return realW(out_buffer, pathname_w);
11631163 },
1164 Os.macosx, Os.ios, Os.freebsd => {
1164 Os.macosx, Os.ios => {
11651165 // TODO instead of calling the libc function here, port the implementation to Zig
11661166 const err = posix.getErrno(posix.realpath(pathname, out_buffer));
11671167 switch (err) {
......@@ -1188,6 +1188,15 @@ pub fn realC(out_buffer: *[os.MAX_PATH_BYTES]u8, pathname: [*]const u8) RealErro
11881188
11891189 return os.readLinkC(out_buffer, proc_path.ptr);
11901190 },
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 },
11911200 else => @compileError("TODO implement os.path.real for " ++ @tagName(builtin.os)),
11921201 }
11931202}