diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2019-04-25 00:24:25 -0400 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2019-04-25 00:24:25 -0400 |
| commit | 17ffe166c286de5ff0ef4d67f60267abba5f6e12 (patch) | |
| tree | b76b7924fb16a2313721b7a294b04f75db621bcb /std | |
| parent | e1bf74fca3de7943b8f7c15be4da3dbc8e3da17e (diff) | |
| download | zig-17ffe166c286de5ff0ef4d67f60267abba5f6e12.tar.gz zig-17ffe166c286de5ff0ef4d67f60267abba5f6e12.zip | |
add preliminary windows support to std.io.COutStream
Diffstat (limited to 'std')
| -rw-r--r-- | std/c.zig | 2 | ||||
| -rw-r--r-- | std/io.zig | 3 | ||||
| -rw-r--r-- | std/io/c_out_stream.zig | 4 | ||||
| -rw-r--r-- | std/io/test.zig (renamed from std/io_test.zig) | 13 |
4 files changed, 20 insertions, 2 deletions
@@ -13,6 +13,8 @@ pub use switch (builtin.os) { // TODO https://github.com/ziglang/zig/issues/265 on this whole file pub const FILE = @OpaqueType(); +pub extern "c" fn fopen(filename: [*]const u8, modes: [*]const u8) ?*FILE; +pub extern "c" fn fclose(stream: *FILE) c_int; pub extern "c" fn fwrite(ptr: [*]const u8, size_of_type: usize, item_count: usize, stream: *FILE) usize; pub extern "c" fn fread(ptr: [*]u8, size_of_type: usize, item_count: usize, stream: *FILE) usize; diff --git a/std/io.zig b/std/io.zig index 5ad35c91fb..48cec478e4 100644 --- a/std/io.zig +++ b/std/io.zig @@ -1092,6 +1092,7 @@ test "io.readLineSliceFrom" { pub const Packing = enum { /// Pack data to byte alignment Byte, + /// Pack data to bit alignment Bit, }; @@ -1454,6 +1455,6 @@ pub fn Serializer(comptime endian: builtin.Endian, comptime packing: Packing, co test "import io tests" { comptime { - _ = @import("io_test.zig"); + _ = @import("io/test.zig"); } } diff --git a/std/io/c_out_stream.zig b/std/io/c_out_stream.zig index 398668979e..c66b342f1e 100644 --- a/std/io/c_out_stream.zig +++ b/std/io/c_out_stream.zig @@ -24,6 +24,10 @@ pub const COutStream = struct { const self = @fieldParentPtr(COutStream, "stream", out_stream); const amt_written = std.c.fwrite(bytes.ptr, 1, bytes.len, self.c_file); if (amt_written == bytes.len) return; + // TODO errno on windows. should we have a posix layer for windows? + if (builtin.os == .windows) { + return error.InputOutput; + } const errno = std.c._errno().*; switch (errno) { 0 => unreachable, diff --git a/std/io_test.zig b/std/io/test.zig index d6f2264a56..07a3c0e8dd 100644 --- a/std/io_test.zig +++ b/std/io/test.zig @@ -1,4 +1,4 @@ -const std = @import("std.zig"); +const std = @import("../std.zig"); const io = std.io; const meta = std.meta; const trait = std.trait; @@ -589,3 +589,14 @@ test "Deserializer bad data" { try testBadData(.Big, .Bit); try testBadData(.Little, .Bit); } + +test "c out stream" { + if (!builtin.link_libc) return error.SkipZigTest; + + const filename = c"tmp_io_test_file.txt"; + const out_file = std.c.fopen(filename, c"w") orelse return error.UnableToOpenTestFile; + defer std.os.deleteFileC(filename) catch {}; + + const out_stream = &io.COutStream.init(out_file).stream; + try out_stream.print("hi: {}\n", i32(123)); +} |
