mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-06 02:55:49 +03:00
LibArchive: Move method implementations away from header
This commit is contained in:
parent
3038edab00
commit
d0eb376520
Notes:
sideshowbarker
2024-07-18 17:56:28 +09:00
Author: https://github.com/boricj Commit: https://github.com/SerenityOS/serenity/commit/d0eb376520d Pull-request: https://github.com/SerenityOS/serenity/pull/7189 Reviewed-by: https://github.com/linusg
@ -1,4 +1,5 @@
|
||||
set(SOURCES
|
||||
Tar.cpp
|
||||
TarStream.cpp
|
||||
Zip.cpp
|
||||
)
|
||||
|
33
Userland/Libraries/LibArchive/Tar.cpp
Normal file
33
Userland/Libraries/LibArchive/Tar.cpp
Normal file
@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright (c) 2020, Peter Elliott <pelliott@ualberta.ca>
|
||||
* Copyright (c) 2021, Idan Horowitz <idan.horowitz@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "Tar.h"
|
||||
|
||||
namespace Archive {
|
||||
|
||||
unsigned TarFileHeader::expected_checksum() const
|
||||
{
|
||||
auto checksum = 0u;
|
||||
const u8* u8_this = reinterpret_cast<const u8*>(this);
|
||||
const u8* u8_m_checksum = reinterpret_cast<const u8*>(&m_checksum);
|
||||
for (auto i = 0u; i < sizeof(TarFileHeader); ++i) {
|
||||
if (u8_this + i >= u8_m_checksum && u8_this + i < u8_m_checksum + sizeof(m_checksum)) {
|
||||
checksum += ' ';
|
||||
} else {
|
||||
checksum += u8_this[i];
|
||||
}
|
||||
}
|
||||
return checksum;
|
||||
}
|
||||
|
||||
void TarFileHeader::calculate_checksum()
|
||||
{
|
||||
memset(m_checksum, ' ', sizeof(m_checksum));
|
||||
VERIFY(String::formatted("{:06o}", expected_checksum()).copy_characters_to_buffer(m_checksum, sizeof(m_checksum)));
|
||||
}
|
||||
|
||||
}
|
@ -113,24 +113,4 @@ size_t TarFileHeader::get_tar_field(const char (&field)[N])
|
||||
return value;
|
||||
}
|
||||
|
||||
unsigned TarFileHeader::expected_checksum() const
|
||||
{
|
||||
auto checksum = 0u;
|
||||
const u8* u8_this = reinterpret_cast<const u8*>(this);
|
||||
const u8* u8_m_checksum = reinterpret_cast<const u8*>(&m_checksum);
|
||||
for (auto i = 0u; i < sizeof(TarFileHeader); ++i) {
|
||||
if (u8_this + i >= u8_m_checksum && u8_this + i < u8_m_checksum + sizeof(m_checksum)) {
|
||||
checksum += ' ';
|
||||
} else {
|
||||
checksum += u8_this[i];
|
||||
}
|
||||
}
|
||||
return checksum;
|
||||
}
|
||||
|
||||
void TarFileHeader::calculate_checksum()
|
||||
{
|
||||
memset(m_checksum, ' ', sizeof(m_checksum));
|
||||
VERIFY(String::formatted("{:06o}", expected_checksum()).copy_characters_to_buffer(m_checksum, sizeof(m_checksum)));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user