authorgravatar for jens.goldberg@gmail.comJens Goldberg <jens.goldberg@gmail.com> 2020-09-03 07:49:18+00:00
committergravatar for jens.goldberg@gmail.comJens Goldberg <jens.goldberg@gmail.com> 2020-09-03 07:49:18+00:00
loge747d2ba172a086e6df831c854ebe7f92bf07cd0
treec9ba665dd60bc3a5e2e293139acb526339de4119
parent25f666330480a2391d1c06e1beab8d517a096e99

Add C declarations and tests for the sync functions


2 files changed, 25 insertions(+), 0 deletions(-)

lib/std/c.zig+5
...@@ -330,3 +330,8 @@ pub const FILE = @Type(.Opaque);...@@ -330,3 +330,8 @@ pub const FILE = @Type(.Opaque);
330pub extern "c" fn dlopen(path: [*:0]const u8, mode: c_int) ?*c_void;330pub extern "c" fn dlopen(path: [*:0]const u8, mode: c_int) ?*c_void;
331pub extern "c" fn dlclose(handle: *c_void) c_int;331pub extern "c" fn dlclose(handle: *c_void) c_int;
332pub extern "c" fn dlsym(handle: ?*c_void, symbol: [*:0]const u8) ?*c_void;332pub extern "c" fn dlsym(handle: ?*c_void, symbol: [*:0]const u8) ?*c_void;
333
334pub extern "c" fn sync() void;
335pub extern "c" fn syncfs(fd: c_int) c_int;
336pub extern "c" fn fsync(fd: c_int) c_int;
337pub extern "c" fn fdatasync(fd: c_int) c_int;
lib/std/os/test.zig+20
...@@ -555,3 +555,23 @@ test "signalfd" {...@@ -555,3 +555,23 @@ test "signalfd" {
555 return error.SkipZigTest;555 return error.SkipZigTest;
556 _ = std.os.signalfd;556 _ = std.os.signalfd;
557}557}
558
559test "sync" {
560 if (builtin.os.tag != .linux and builtin.os.tag != .windows)
561 return error.SkipZigTest;
562
563 var tmp = tmpDir(.{});
564 defer tmp.cleanup();
565
566 const test_out_file = "os_tmp_test";
567 const file = try tmp.dir.createFile(test_out_file, .{});
568 defer {
569 file.close();
570 tmp.dir.deleteFile(test_out_file) catch {};
571 }
572
573 try os.syncfs(file.handle);
574 try os.fsync(file.handle);
575 try os.fdatasync(file.handle);
576 os.sync();
577}