diff options
| author | Rocknest <35231115+Rocknest@users.noreply.github.com> | 2019-10-17 01:57:29 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-10-17 01:57:29 +0300 |
| commit | 40d53a7bc5ef18607266790e99fa693ba4344645 (patch) | |
| tree | 7e124a713889646e4e55c77e5d70d621fc572e6e /lib/std/os/linux/test.zig | |
| parent | c95a9e978582ca96bf5462c6bfdd40b934e9ba92 (diff) | |
| parent | 700bb19a9053e236df6a9f15d435c427391e3ecf (diff) | |
| download | zig-40d53a7bc5ef18607266790e99fa693ba4344645.tar.gz zig-40d53a7bc5ef18607266790e99fa693ba4344645.zip | |
Merge branch 'master' into docs-local
Diffstat (limited to 'lib/std/os/linux/test.zig')
| -rw-r--r-- | lib/std/os/linux/test.zig | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/lib/std/os/linux/test.zig b/lib/std/os/linux/test.zig index 97bbcc402d..e089a02445 100644 --- a/lib/std/os/linux/test.zig +++ b/lib/std/os/linux/test.zig @@ -44,3 +44,35 @@ test "timer" { // TODO implicit cast from *[N]T to [*]T err = linux.epoll_wait(@intCast(i32, epoll_fd), @ptrCast([*]linux.epoll_event, &events), 8, -1); } + +const File = std.fs.File; + +test "statx" { + const tmp_file_name = "just_a_temporary_file.txt"; + var file = try File.openWrite(tmp_file_name); + defer { + file.close(); + std.fs.deleteFile(tmp_file_name) catch {}; + } + + var statx_buf: linux.Statx = undefined; + switch (linux.getErrno(linux.statx(file.handle, c"", linux.AT_EMPTY_PATH, linux.STATX_BASIC_STATS, &statx_buf))) { + 0 => {}, + // The statx syscall was only introduced in linux 4.11 + linux.ENOSYS => return error.SkipZigTest, + else => unreachable, + } + + var stat_buf: linux.Stat = undefined; + switch (linux.getErrno(linux.fstatat(file.handle, c"", &stat_buf, linux.AT_EMPTY_PATH))) { + 0 => {}, + else => unreachable, + } + + expect(stat_buf.mode == statx_buf.mode); + expect(@bitCast(u32, stat_buf.uid) == statx_buf.uid); + expect(@bitCast(u32, stat_buf.gid) == statx_buf.gid); + expect(@bitCast(u64, i64(stat_buf.size)) == statx_buf.size); + expect(@bitCast(u64, i64(stat_buf.blksize)) == statx_buf.blksize); + expect(@bitCast(u64, i64(stat_buf.blocks)) == statx_buf.blocks); +} |
