zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit e747d2ba172a086e6df831c854ebe7f92bf07cd0 (tree)
parent 25f666330480a2391d1c06e1beab8d517a096e99
Author: Jens Goldberg <jens.goldberg@gmail.com>
Date:   Thu,  3 Sep 2020 07:49:18 +0000

Add C declarations and tests for the sync functions

Diffstat:
Mlib/std/c.zig | 5+++++
Mlib/std/os/test.zig | 20++++++++++++++++++++
2 files changed, 25 insertions(+), 0 deletions(-)

diff --git a/lib/std/c.zig b/lib/std/c.zig @@ -330,3 +330,8 @@ pub const FILE = @Type(.Opaque); pub extern "c" fn dlopen(path: [*:0]const u8, mode: c_int) ?*c_void; pub extern "c" fn dlclose(handle: *c_void) c_int; pub extern "c" fn dlsym(handle: ?*c_void, symbol: [*:0]const u8) ?*c_void; + +pub extern "c" fn sync() void; +pub extern "c" fn syncfs(fd: c_int) c_int; +pub extern "c" fn fsync(fd: c_int) c_int; +pub extern "c" fn fdatasync(fd: c_int) c_int; diff --git a/lib/std/os/test.zig b/lib/std/os/test.zig @@ -555,3 +555,23 @@ test "signalfd" { return error.SkipZigTest; _ = std.os.signalfd; } + +test "sync" { + if (builtin.os.tag != .linux and builtin.os.tag != .windows) + return error.SkipZigTest; + + var tmp = tmpDir(.{}); + defer tmp.cleanup(); + + const test_out_file = "os_tmp_test"; + const file = try tmp.dir.createFile(test_out_file, .{}); + defer { + file.close(); + tmp.dir.deleteFile(test_out_file) catch {}; + } + + try os.syncfs(file.handle); + try os.fsync(file.handle); + try os.fdatasync(file.handle); + os.sync(); +}