@@ -21,6 +21,33 @@ pub fn getErrno(rc: var) u16 {
21
21
}
22
22
}
23
23
24
+ /// The return type is `type` to force comptime function call execution.
25
+ /// TODO: https://github.com/ziglang/zig/issues/425
26
+ /// If not linking libc, returns struct{pub const ok = false;}
27
+ /// If linking musl libc, returns struct{pub const ok = true;}
28
+ /// If linking gnu libc (glibc), the `ok` value will be true if the target
29
+ /// version is greater than or equal to `glibc_version`.
30
+ /// If linking a libc other than these, returns `false`.
31
+ pub fn versionCheck (glibc_version : builtin.Version ) type {
32
+ return struct {
33
+ pub const ok = blk : {
34
+ if (! builtin .link_libc ) break :blk false ;
35
+ switch (builtin .abi ) {
36
+ .musl , .musleabi , .musleabihf = > break :blk true ,
37
+ .gnu , .gnuabin32 , .gnuabi64 , .gnueabi , .gnueabihf , .gnux32 = > {
38
+ const ver = builtin .glibc_version orelse break :blk false ;
39
+ if (ver .major < glibc_version .major ) break :blk false ;
40
+ if (ver .major > glibc_version .major ) break :blk true ;
41
+ if (ver .minor < glibc_version .minor ) break :blk false ;
42
+ if (ver .minor > glibc_version .minor ) break :blk true ;
43
+ break :blk ver .patch >= glibc_version .patch ;
44
+ },
45
+ else = > break :blk false ,
46
+ }
47
+ };
48
+ };
49
+ }
50
+
24
51
// TODO https://github.com/ziglang/zig/issues/265 on this whole file
25
52
26
53
pub extern "c" fn fopen (filename : [* ]const u8 , modes : [* ]const u8 ) ? * FILE ;
0 commit comments