mirror of
https://pdfium.googlesource.com/pdfium
synced 2026-07-31 22:26:36 +08:00
Introduce safe, container-templated span-based I/O wrappers. Helps centralize some UNSAFE_BUFFERS() usage. -- Add spanread/spanwrite overloads for FILE*. -- Add spanread/spanwrite overloads for POSIX file descriptors. -- Add spanread/spanwrite overloads for Windows HANDLE. -- Change FileAccessIface::Write() signature to return bool. -- Update image_diff, write.cc, file_util, and cfx_folderfontinfo. -- Update CFX_FileAccess_Posix to use FD wrappers. -- Update CFX_FileAccess_Windows to use HANDLE wrappers. -- Update TemporaryFileTest to use safe spanwrite wrapper. -- Add unit tests for all overloads in span_util_unittest.cpp. Note that CFX_FileAccess_Posix changes may have fixed a latent error underflow bug in the process. Change-Id: Ic2c4088d364be0a2f38c5d30854a61fdacc6c69d Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/149030 Commit-Queue: Tom Sepez <tsepez@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org>
37 lines
824 B
C++
37 lines
824 B
C++
// Copyright 2026 The PDFium Authors
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
#include "testing/temporary_file_test.h"
|
|
|
|
#include <fcntl.h>
|
|
#include <unistd.h>
|
|
|
|
#include "core/fxcrt/span_io.h"
|
|
|
|
TemporaryFileTest::TemporaryFileTest() = default;
|
|
|
|
TemporaryFileTest::~TemporaryFileTest() = default;
|
|
|
|
void TemporaryFileTest::SetUp() {
|
|
temp_name_ = testing::TempDir();
|
|
temp_name_ += "/pdfium_empty_XXXXXX";
|
|
fd_ = mkstemp(temp_name_.data());
|
|
ASSERT_GE(fd_, 0);
|
|
}
|
|
|
|
void TemporaryFileTest::TearDown() {
|
|
if (fd_ != -1) {
|
|
close(fd_);
|
|
}
|
|
unlink(temp_name_.c_str());
|
|
}
|
|
|
|
void TemporaryFileTest::WriteAndClose(pdfium::span<const uint8_t> data) {
|
|
if (!data.empty()) {
|
|
EXPECT_EQ(fxcrt::spanwrite(data, fd_), data.size());
|
|
}
|
|
close(fd_);
|
|
fd_ = -1;
|
|
}
|