chromium/base/files/file_util.cc

// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/40284755): Remove this and spanify to fix the errors.
#pragma allow_unsafe_buffers
#endif

#include "base/files/file_util.h"

#include <string_view>

#include "base/task/sequenced_task_runner.h"
#include "build/build_config.h"

#if BUILDFLAG(IS_WIN)
#include <io.h>
#endif
#include <stdio.h>

#include <fstream>
#include <limits>
#include <memory>
#include <utility>
#include <vector>

#include "base/bit_cast.h"
#include "base/check_op.h"
#include "base/containers/contains.h"
#include "base/containers/span.h"
#include "base/files/file_enumerator.h"
#include "base/files/file_path.h"
#include "base/functional/function_ref.h"
#include "base/notreached.h"
#include "base/posix/eintr_wrapper.h"
#include "base/ranges/algorithm.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/task/bind_post_task.h"
#include "base/threading/scoped_blocking_call.h"

#if BUILDFLAG(IS_WIN)
#include <windows.h>
#endif

namespace base {

namespace {

#if !BUILDFLAG(IS_WIN)

void RunAndReply(OnceCallback<bool()> action_callback,
                 OnceCallback<void(bool)> reply_callback) {}

#endif  // !BUILDFLAG(IS_WIN)

bool ReadStreamToSpanWithMaxSize(
    FILE* stream,
    size_t max_size,
    FunctionRef<span<uint8_t>(size_t)> resize_span) {}

}  // namespace

#if !BUILDFLAG(IS_WIN)

OnceClosure GetDeleteFileCallback(const FilePath& path,
                                  OnceCallback<void(bool)> reply_callback) {}

OnceClosure GetDeletePathRecursivelyCallback(
    const FilePath& path,
    OnceCallback<void(bool)> reply_callback) {}

#endif  // !BUILDFLAG(IS_WIN)

int64_t ComputeDirectorySize(const FilePath& root_path) {}

bool Move(const FilePath& from_path, const FilePath& to_path) {}

bool CopyFileContents(File& infile, File& outfile) {}

bool ContentsEqual(const FilePath& filename1, const FilePath& filename2) {}

bool TextContentsEqual(const FilePath& filename1, const FilePath& filename2) {}

bool ReadStreamToString(FILE* stream, std::string* contents) {}

bool ReadStreamToStringWithMaxSize(FILE* stream,
                                   size_t max_size,
                                   std::string* contents) {}

std::optional<std::vector<uint8_t>> ReadFileToBytes(const FilePath& path) {}

bool ReadFileToString(const FilePath& path, std::string* contents) {}

bool ReadFileToStringWithMaxSize(const FilePath& path,
                                 std::string* contents,
                                 size_t max_size) {}

bool IsDirectoryEmpty(const FilePath& dir_path) {}

bool CreateTemporaryFile(FilePath* path) {}

ScopedFILE CreateAndOpenTemporaryStream(FilePath* path) {}

bool CreateDirectory(const FilePath& full_path) {}

bool GetFileSize(const FilePath& file_path, int64_t* file_size) {}

bool TouchFile(const FilePath& path,
               const Time& last_accessed,
               const Time& last_modified) {}

bool CloseFile(FILE* file) {}

bool TruncateFile(FILE* file) {}

std::optional<uint64_t> ReadFile(const FilePath& filename,
                                 span<uint8_t> buffer) {}

int ReadFile(const FilePath& filename, char* data, int max_size) {}

bool WriteFile(const FilePath& filename, std::string_view data) {}

FilePath GetUniquePath(const FilePath& path) {}

FilePath GetUniquePathWithSuffixFormat(const FilePath& path,
                                       cstring_view suffix_format) {}

}  // namespace base