# File stat in zig 0.16-dev

**URL:** <https://ziggit.dev/t/file-stat-in-zig-0-16-dev/14426>\
**Category:** Help\
**Tags:** language, learning, standard-library\
**Created:** [February 24, 2026, 10:06am UTC](https://ziggit.dev/t/file-stat-in-zig-0-16-dev/14426 "2026-02-24T10:06:22Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![here-Leslie-Lau](https://ziggit.dev/user_avatar/ziggit.dev/here-leslie-lau/32/7826_2.png) [@here-Leslie-Lau](https://ziggit.dev/u/here-Leslie-Lau)\
**Post date:** [February 24, 2026, 10:06am UTC](https://ziggit.dev/t/file-stat-in-zig-0-16-dev/14426/1 "2026-02-24T10:06:22Z")

</div>

how do I get the uid and gid of a file? I’ve searched through the official documentation but still don’t quite understand how to do it.

---

<div class="post-metadata">

**Author:** ![vulpesx](https://ziggit.dev/user_avatar/ziggit.dev/vulpesx/32/3989_2.png) [@vulpesx](https://ziggit.dev/u/vulpesx)\
**Post date:** [February 24, 2026, 10:49am UTC](https://ziggit.dev/t/file-stat-in-zig-0-16-dev/14426/2 "2026-02-24T10:49:59Z")

</div>

You have to drop to platform specific APIs, Io doesn’t provide it because that information isn’t available on all supported platforms.

> I think?? it might change in the future

Since `std.posix` has been nuked, you have to go even lower to `std.os.your_os_here`.

Assuming you’re on linux:

```zig
const linux = std.os.linux;

var statx: linux.Statx = undefined;
// there is a `BASIC_STATS` decl which includes uid, gid and other common stats
const errno = linux.errno(linux.statx(io_file.handle, "", linux.AT.EMPTY_PATH, .{ .GID = true, .UID = true }, &statx));
switch (errno) {
    .SUCCESS => {},
    .ACCES => {},
    .BADF => {},
    .FAULT => {},
    .INVAL => {},
    .LOOP => {},
    .NAMETOOLONG => {},
    .NOENT => {},
    .NOMEM => {},
    .NOTDIR => {},
    // no other errors are possible
    else => unreachable,
}
// only these are filled due to the mask passed
const uid, const gid = .{ statx.uid, statx.gid };

```

---

<div class="post-metadata">

**Author:** ![floooh](https://ziggit.dev/user_avatar/ziggit.dev/floooh/32/2989_2.png) [@floooh](https://ziggit.dev/u/floooh)\
**Post date:** [February 24, 2026, 10:51am UTC](https://ziggit.dev/t/file-stat-in-zig-0-16-dev/14426/3 "2026-02-24T10:51:30Z")

</div>

My guess is that you’ll need to go through `std.os.linux.statx()` (e.g. [Zig Documentation](https://ziglang.org/documentation/master/std/#std.os.linux.statx) which populates a `StatX` struct: [Zig Documentation](https://ziglang.org/documentation/master/std/#std.os.linux.Statx), and this has uid and gid).

It’s probably not part of the generic `std.Io` interface because `uid` and `gid` are not portable.

---

<div class="post-metadata">

**Author:** ![miagi](https://ziggit.dev/user_avatar/ziggit.dev/miagi/32/6745_2.png) [@miagi](https://ziggit.dev/u/miagi)\
**Post date:** [February 25, 2026, 6:33am UTC](https://ziggit.dev/t/file-stat-in-zig-0-16-dev/14426/4 "2026-02-25T06:33:47Z")

</div>

In case you need to get and set, there is now`std.Io.File.Permissions`. You have `setPermissions()` function as well.

---

<div class="post-metadata">

**Author:** ![here-Leslie-Lau](https://ziggit.dev/user_avatar/ziggit.dev/here-leslie-lau/32/7826_2.png) [@here-Leslie-Lau](https://ziggit.dev/u/here-Leslie-Lau)\
**Post date:** [February 25, 2026, 7:04am UTC](https://ziggit.dev/t/file-stat-in-zig-0-16-dev/14426/5 "2026-02-25T07:04:49Z")

</div>

Hi, @vulpesx @floooh .

I used `std.os.linux.statx` and it solved the problem; I can now correctly retrieve the required data on Linux.

On macOS, I use `std.c.fstat`.

Thank~
