小组成员:谢瑞阳、徐翔宇
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

82 satır
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. Logger::~Logger() {
  15. }
  16. FileLock::~FileLock() {
  17. }
  18. void Log(Logger* info_log, const char* format, ...) {
  19. if (info_log != NULL) {
  20. va_list ap;
  21. va_start(ap, format);
  22. info_log->Logv(format, ap);
  23. va_end(ap);
  24. }
  25. }
  26. Status WriteStringToFile(Env* env, const Slice& data,
  27. const std::string& fname) {
  28. WritableFile* file;
  29. Status s = env->NewWritableFile(fname, &file);
  30. if (!s.ok()) {
  31. return s;
  32. }
  33. s = file->Append(data);
  34. if (s.ok()) {
  35. s = file->Close();
  36. }
  37. delete file; // Will auto-close if we did not close above
  38. if (!s.ok()) {
  39. env->DeleteFile(fname);
  40. }
  41. return s;
  42. }
  43. Status ReadFileToString(Env* env, const std::string& fname, std::string* data) {
  44. data->clear();
  45. SequentialFile* file;
  46. Status s = env->NewSequentialFile(fname, &file);
  47. if (!s.ok()) {
  48. return s;
  49. }
  50. static const int kBufferSize = 8192;
  51. char* space = new char[kBufferSize];
  52. while (true) {
  53. Slice fragment;
  54. s = file->Read(kBufferSize, &fragment, space);
  55. if (!s.ok()) {
  56. break;
  57. }
  58. data->append(fragment.data(), fragment.size());
  59. if (fragment.empty()) {
  60. break;
  61. }
  62. }
  63. delete[] space;
  64. delete file;
  65. return s;
  66. }
  67. EnvWrapper::~EnvWrapper() {
  68. }
  69. }