mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 20:12:57 +01:00
be2e16f33a
8847ce44e0713350a6d3524f62eaeb10ba548bae util: add missing include and fix function signature (Cory Fields) Pull request description: ping hebasto Discovered while testing pre-compiled header support with CMake: https://github.com/theuni/bitcoin/commits/cmake-pch-poc. Compilation of that branch fails without this fix and succeeds with it. Similar to the fix in #27144. The problem of having a default argument in the definition was masked by the missing include. Using PCH forces that include, so we end up with the compiler error we should've been getting all along. ACKs for top commit: fanquake: ACK 8847ce44e0713350a6d3524f62eaeb10ba548bae Tree-SHA512: 5eb9a6691ee37cbc5033a48aedcbf5c93af3b234614ae14c3fcc858f1ee505f630ad68f8bbb69ffa280080c8d0f91451362cb3819290b741ce906b2b3224a622
50 lines
1.4 KiB
C++
50 lines
1.4 KiB
C++
// Copyright (c) 2015-2020 The Bitcoin Core developers
|
|
// Copyright (c) 2017 The Zcash developers
|
|
// Distributed under the MIT software license, see the accompanying
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
#include <util/readwritefile.h>
|
|
|
|
#include <fs.h>
|
|
|
|
#include <limits>
|
|
#include <stdio.h>
|
|
#include <string>
|
|
#include <utility>
|
|
|
|
std::pair<bool,std::string> ReadBinaryFile(const fs::path &filename, size_t maxsize)
|
|
{
|
|
FILE *f = fsbridge::fopen(filename, "rb");
|
|
if (f == nullptr)
|
|
return std::make_pair(false,"");
|
|
std::string retval;
|
|
char buffer[128];
|
|
do {
|
|
const size_t n = fread(buffer, 1, sizeof(buffer), f);
|
|
// Check for reading errors so we don't return any data if we couldn't
|
|
// read the entire file (or up to maxsize)
|
|
if (ferror(f)) {
|
|
fclose(f);
|
|
return std::make_pair(false,"");
|
|
}
|
|
retval.append(buffer, buffer+n);
|
|
} while (!feof(f) && retval.size() <= maxsize);
|
|
fclose(f);
|
|
return std::make_pair(true,retval);
|
|
}
|
|
|
|
bool WriteBinaryFile(const fs::path &filename, const std::string &data)
|
|
{
|
|
FILE *f = fsbridge::fopen(filename, "wb");
|
|
if (f == nullptr)
|
|
return false;
|
|
if (fwrite(data.data(), 1, data.size(), f) != data.size()) {
|
|
fclose(f);
|
|
return false;
|
|
}
|
|
if (fclose(f) != 0) {
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|