ARM64系统上文件读取兼容性问题

问题描述 投票:0回答:0

我在基于 ARM64 的系统上读取文件时遇到问题,因为文件被截断并且只能读取部分内容。我能够在 linux x8664 上正确读取该文件。

这是在 linux x8664 上正确读取的内容以及 预期的输出。

签名内容 = 33303436303232313030633932326231656362623666663163323631313730616634333562396139613037353733366335633533356664373 762613132643064333132383937363732643032323130306135663337346366303262373034653032306533356139646662643936313365373830376366 3864643234333666666236306635373432373534343036303163

但在 ARM64 上读取相同的内容,则仅读取部分内容,其余内容被截断。 ARM64 上的实际输出 签名内容=3330343630323231303063393232623165636262366666316332363131373061663433356239613。 预期输出: 3330343630323231303063393232623165636262366666316332363131373061663433356239613961303735373336633563353335666437376261313 264306433313238393736373264303232313030613566333734636630326237303465303230653335613964666264393631336537383037636638646432 34333666666236306635373432373534343036303163

下面是在 Linux-x8664 和 ARM 64 上读取文件内容的函数,但不确定为什么在 ARM 64 上部分读取内容。

除此之外的文件内容仅在 Linux-x8664 系统上写入。

std::vector<char> signature;
std::ifstream signatureFile("/home/mohan/arjun.rpk/signature.txt");
if (!signatureFile)
{
    throw std::runtime_error("Error: Failed to read the signature from the file");
}

// Get the file size to allocate space in the vector
signatureFile.seekg(0, std::ios::end);
std::streampos fileSize = signatureFile.tellg();
signatureFile.seekg(0, std::ios::beg);

std::cout<<"filesize="<< fileSize <<std::endl;

// Resize the vector to the file size
signature.resize(fileSize);

// Read the data into the signature vector
signatureFile.read(signature.data(), fileSize);
signatureFile.close();

// Iterate and print the signature vector using std::for_each()
std::for_each(signature.begin(), signature.end(), [](char c) {
    std::cout << c;
});

我想知道为什么内容在 ARM64 上被截断,而相同的函数在 Linuxx8664 上可以正确读取内容。是否有任何有效的方式可以在任何架构上读取内容? Linuxx8664 和 ARM64 都是小端字节序,因此这里不存在字节顺序问题。我无法使用 boost 1_61 和 c++14 版本之外的版本,因此解决方案应该是 1_61 或更低版本。我检查了两个设备上都没有文件大小问题,也不存在权限问题。

c++ linux arm file-handling
© www.soinside.com 2019 - 2024. All rights reserved.