pub const ArchiveMemberHeader = extern struct name: [16]u8Left-justified '/' terminated member name
date: [12]u8Left-justified ASCII decimal: seconds since January 1st, 1970
user_id: [6]u8Left-justified ASCII decimal: user id
group_id: [6]u8Left-justified ASCII decimal: group id
file_mode: [8]u8Left-justified ASCII octal: file mode
size: [10]u8Left-justified ASCII decimal: size of the member following this header, not including the size of this header.
end_of_header: [2]u8The literal string '\n'
pub fn parseName(self: *const ArchiveMemberHeader, opt_longnames: ?[]const u8) ![]const u8Extracts the name of the member by either reading it directly from the header, or by finding it inside the longnames member, if provided.
fn parseField(field: []const u8, T: type, base: u8) !Tpub fn parseDate(self: *const ArchiveMemberHeader) !u40pub fn parseUserId(self: *const ArchiveMemberHeader) !u20pub fn parseGroupId(self: *const ArchiveMemberHeader) !u20pub fn parseFileMode(self: *const ArchiveMemberHeader) !u20pub fn parseSize(self: *const ArchiveMemberHeader) !u342010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093pub const ArchiveMemberHeader = extern struct {
/// Left-justified '/' terminated member name
name: [16]u8,
/// Left-justified ASCII decimal: seconds since January 1st, 1970
date: [12]u8,
/// Left-justified ASCII decimal: user id
user_id: [6]u8,
/// Left-justified ASCII decimal: group id
group_id: [6]u8,
/// Left-justified ASCII octal: file mode
file_mode: [8]u8,
/// Left-justified ASCII decimal: size of the member following this header,
/// not including the size of this header.
size: [10]u8,
/// The literal string '`\n'
end_of_header: [2]u8,
/// Extracts the name of the member by either reading it directly from
/// the header, or by finding it inside the longnames member, if provided.
pub fn parseName(
self: *const ArchiveMemberHeader,
opt_longnames: ?[]const u8,
) ![]const u8 {
const trim = std.mem.trimEnd(u8, &self.name, &.{' '});
if (trim.len == 0) return error.BadName;
return if (trim[0] == '/') name: {
if (trim.len == 1 or
trim.len == 2 and trim[1] == '/')
break :name trim;
const offset = std.fmt.parseUnsigned(u50, trim[1..], 10) catch
return error.BadName;
if (opt_longnames) |longnames| {
if (offset >= longnames.len) return error.BadName;
break :name std.mem.sliceTo(longnames[@intCast(offset)..], 0);
} else return error.NoLongNames;
} else if (trim[trim.len - 1] == '/')
trim[0 .. trim.len - 1]
else
return error.BadName;
}
fn parseField(field: []const u8, T: type, base: u8) !T {
if (std.mem.allEqual(u8, field, ' ')) return 0;
if (field[0] == '-')
return @bitCast(try std.fmt.parseInt(
@Int(.signed, @typeInfo(T).int.bits),
std.mem.trimEnd(u8, field, &.{' '}),
base,
));
return std.fmt.parseUnsigned(T, std.mem.trimEnd(u8, field, &.{' '}), base);
}
pub fn parseDate(self: *const ArchiveMemberHeader) !u40 {
return parseField(&self.date, u40, 10);
}
pub fn parseUserId(self: *const ArchiveMemberHeader) !u20 {
return parseField(&self.user_id, u20, 10);
}
pub fn parseGroupId(self: *const ArchiveMemberHeader) !u20 {
return parseField(&self.group_id, u20, 10);
}
pub fn parseFileMode(self: *const ArchiveMemberHeader) !u20 {
return parseField(&self.group_id, u20, 8);
}
pub fn parseSize(self: *const ArchiveMemberHeader) !u34 {
return parseField(&self.size, u34, 10);
}
pub const Kind = enum {
first_linker,
second_linker,
longnames,
coff,
import,
};
}