Add C declarations and tests for the sync functions

This commit is contained in:
Jens Goldberg 2020-09-03 07:49:18 +00:00
parent 25f6663304
commit e747d2ba17
2 changed files with 25 additions and 0 deletions

View File

@ -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;

View File

@ -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();
}