aboutsummaryrefslogtreecommitdiff
path: root/lib/std/os/linux
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2019-10-16 17:11:22 -0400
committerGitHub <noreply@github.com>2019-10-16 17:11:22 -0400
commit312880f10243b3074c3f176fbea6b9994e733f56 (patch)
tree440391f85a19f8414c0e49218f62c697fbb6db17 /lib/std/os/linux
parent3af2202ea4a5950541ee369a005f8e4484d544ab (diff)
parentead9630c135b86c77de9774635f7b5c55ce62f41 (diff)
downloadzig-312880f10243b3074c3f176fbea6b9994e733f56.tar.gz
zig-312880f10243b3074c3f176fbea6b9994e733f56.zip
Merge pull request #3439 from LemonBoy/statx
Add support for the statx syscall
Diffstat (limited to 'lib/std/os/linux')
-rw-r--r--lib/std/os/linux/test.zig32
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..3782bc3301 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.stx_mode);
+ expect(@bitCast(u32, stat_buf.uid) == statx_buf.stx_uid);
+ expect(@bitCast(u32, stat_buf.gid) == statx_buf.stx_gid);
+ expect(@bitCast(u64, i64(stat_buf.size)) == statx_buf.stx_size);
+ expect(@bitCast(u64, i64(stat_buf.blksize)) == statx_buf.stx_blksize);
+ expect(@bitCast(u64, i64(stat_buf.blocks)) == statx_buf.stx_blocks);
+}