Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1// Copyright (c) 2011 The LevelDB Authors. All rights reserved.2// Use of this source code is governed by a BSD-style license that can be3// found in the LICENSE file. See the AUTHORS file for names of contributors.5#include "leveldb/env.h"7namespace leveldb {9Env::~Env() = default;11Status Env::NewAppendableFile(const std::string& fname, WritableFile** result) {12return Status::NotSupported("NewAppendableFile", fname);13}15SequentialFile::~SequentialFile() = default;17RandomAccessFile::~RandomAccessFile() = default;19WritableFile::~WritableFile() = default;21Logger::~Logger() = default;23FileLock::~FileLock() = default;25void Log(Logger* info_log, const char* format, ...) {26if (info_log != nullptr) {27va_list ap;28va_start(ap, format);29info_log->Logv(format, ap);30va_end(ap);31}32}34static Status DoWriteStringToFile(Env* env, const Slice& data,35const std::string& fname, bool should_sync) {36WritableFile* file;37Status s = env->NewWritableFile(fname, &file);38if (!s.ok()) {39return s;40}41s = file->Append(data);42if (s.ok() && should_sync) {43s = file->Sync();44}45if (s.ok()) {46s = file->Close();47}48delete file; // Will auto-close if we did not close above49if (!s.ok()) {50env->DeleteFile(fname);51}52return s;53}55Status WriteStringToFile(Env* env, const Slice& data,56const std::string& fname) {57return DoWriteStringToFile(env, data, fname, false);58}60Status WriteStringToFileSync(Env* env, const Slice& data,61const std::string& fname) {62return DoWriteStringToFile(env, data, fname, true);63}65Status ReadFileToString(Env* env, const std::string& fname, std::string* data) {66data->clear();67SequentialFile* file;68Status s = env->NewSequentialFile(fname, &file);69if (!s.ok()) {70return s;71}72static const int kBufferSize = 8192;73char* space = new char[kBufferSize];74while (true) {75Slice fragment;76s = file->Read(kBufferSize, &fragment, space);77if (!s.ok()) {78break;79}80data->append(fragment.data(), fragment.size());81if (fragment.empty()) {82break;83}84}85delete[] space;86delete file;87return s;88}90EnvWrapper::~EnvWrapper() {}92} // namespace leveldb
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.