Zig 0.17.0-dev (Split by item) This is an example of documentation generated by
ZigDoc , an alternative to Zig's built-in
Auto Doc feature. See also
examples in other modes/formats . The project being documented here (as the example) is the Zig standard library.
std › zig › system › detectAndroidApiLevel Private Function detectAndroidApiLevel Doc Source Private Function std.zig.system.detectAndroidApiLevel
fn detectAndroidApiLevel (io : Io ) !u32 Params File zig/system.zig: 1148
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195 fn detectAndroidApiLevel (io : Io ) !u32 {
comptime if (builtin .os .tag != .linux ) unreachable ;
var child = try std .process .spawn (io , .{
.argv = &.{
"/system/bin/getprop" ,
"ro.build.version.sdk" ,
},
.stdin = .ignore ,
.stdout = .pipe ,
.stderr = .ignore ,
});
errdefer child .kill (io );
// PROP_VALUE_MAX is 92, output is value + newline.
// Currently API levels are two-digit numbers, but we want to make sure we never read a partial value.
var stdout_buf : [92 + 1 ]u8 = undefined ;
var reader = child .stdout .?.readerStreaming (io , &.{});
const n = try reader .interface .readSliceShort (&stdout_buf );
const api_level = std .fmt .parseInt (u32 , stdout_buf [0 .. n - 1 ], 10 ) catch |e | {
std .log .err (
"Could not parse API level, unexpected getprop output '{s}' ({s})" ,
.{ stdout_buf [0 .. n - 1 ], @errorName (e ) },
);
return error .ApiLevelQueryFailed ;
};
switch (try child .wait (io )) {
.exited => |code | if (code != 0 ) {
std .log .err ("getprop terminated abnormally with exit code: {d}" , .{code });
return error .ApiLevelQueryFailed ;
},
.signal => |sig | {
std .log .err ("getprop terminated abnormally with signal: {t}" , .{sig });
return error .ApiLevelQueryFailed ;
},
.stopped => |sig | {
std .log .err ("getprop stopped abnormally with signal: {t}" , .{sig });
return error .ApiLevelQueryFailed ;
},
.unknown => {
std .log .err ("getprop terminated abnormally" , .{});
return error .ApiLevelQueryFailed ;
},
}
return api_level ;
}