作者: 谢瑞阳 10225101483 徐翔宇 10225101535
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

77 行
1.6 KiB

  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 be
  3. // found in the LICENSE file. See the AUTHORS file for names of contributors.
  4. #include "leveldb/env.h"
  5. namespace leveldb {
  6. Env::~Env() {
  7. }
  8. SequentialFile::~SequentialFile() {
  9. }
  10. RandomAccessFile::~RandomAccessFile() {
  11. }
  12. WritableFile::~WritableFile() {
  13. }
  14. FileLock::~FileLock() {
  15. }
  16. void Log(Env* env, WritableFile* info_log, const char* format, ...) {
  17. va_list ap;
  18. va_start(ap, format);
  19. env->Logv(info_log, format, ap);
  20. va_end(ap);
  21. }
  22. Status WriteStringToFile(Env* env, const Slice& data,
  23. const std::string& fname) {
  24. WritableFile* file;
  25. Status s = env->NewWritableFile(fname, &file);
  26. if (!s.ok()) {
  27. return s;
  28. }
  29. s = file->Append(data);
  30. if (s.ok()) {
  31. s = file->Close();
  32. }
  33. delete file; // Will auto-close if we did not close above
  34. if (!s.ok()) {
  35. env->DeleteFile(fname);
  36. }
  37. return s;
  38. }
  39. Status ReadFileToString(Env* env, const std::string& fname, std::string* data) {
  40. data->clear();
  41. SequentialFile* file;
  42. Status s = env->NewSequentialFile(fname, &file);
  43. if (!s.ok()) {
  44. return s;
  45. }
  46. static const int kBufferSize = 8192;
  47. char* space = new char[kBufferSize];
  48. while (true) {
  49. Slice fragment;
  50. s = file->Read(kBufferSize, &fragment, space);
  51. if (!s.ok()) {
  52. break;
  53. }
  54. data->append(fragment.data(), fragment.size());
  55. if (fragment.empty()) {
  56. break;
  57. }
  58. }
  59. delete[] space;
  60. delete file;
  61. return s;
  62. }
  63. EnvWrapper::~EnvWrapper() {
  64. }
  65. }