Skip to content

Commit 31a736e

Browse files
committed
Add uname
1 parent f015d2c commit 31a736e

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@ namespace [std.os.linux](https://ziglang.org/documentation/master/std/#std.os.li
1818
| [pipe.zig](src/pipe.zig) | [pipe](https://ziglang.org/documentation/master/std/#std.os.linux.pipe) [read](https://ziglang.org/documentation/master/std/#std.os.linux.read) [write](https://ziglang.org/documentation/master/std/#std.os.linux.write) |
1919
| [symlink.zig](src/symlink.zig) | [symlink](https://ziglang.org/documentation/master/std/#std.os.linux.symlink) [readlink](https://ziglang.org/documentation/master/std/#std.os.linux.readlink) |
2020
| [ushare.zig](src/ushare.zig) | [getuid](https://ziglang.org/documentation/master/std/#std.os.linux.getuid) [unshare](https://ziglang.org/documentation/master/std/#std.os.linux.unshare) |
21+
| [uname.zig](src/uname.zig) | [uname](https://ziglang.org/documentation/master/std/#std.os.linux.uname) |
2122

2223
## Usage
2324
* Install [zig >= 0.13](https://ziglang.org/download/)
24-
* Build Only
25+
* Build Only. You will have binaries in `zig-out/bin`.
2526
```sh
2627
zig build
2728
```

src/uname.zig

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const std = @import("std");
2+
3+
const mem = std.mem;
4+
const meta = std.meta;
5+
const stdout = std.io.getStdOut().writer();
6+
const linux = std.os.linux;
7+
8+
pub fn main() !void {
9+
// demostrate to get a complex struct by linux call
10+
11+
var uts: linux.utsname = undefined;
12+
13+
const rc = linux.uname(&uts);
14+
try stdout.print("rc of uname is {d}\n", .{rc});
15+
try stdout.print("uts[{}] printed in raw mode {}\n", .{ @TypeOf(uts), uts });
16+
17+
// iterate over fields of struct
18+
inline for (meta.fields(@TypeOf(uts))) |f| {
19+
try stdout.print("{s}: {s}\n", .{ f.name, @as(f.type, @field(uts, f.name)) });
20+
}
21+
}

0 commit comments

Comments
 (0)