leveldb-ruby 0.10 → 0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (116) hide show
  1. data/ext/leveldb/extconf.rb +2 -6
  2. data/ext/leveldb/leveldb.cc +377 -33
  3. data/ext/leveldb/platform.rb +83 -0
  4. data/leveldb/Makefile +29 -28
  5. data/leveldb/build_detect_platform +23 -4
  6. data/leveldb/db/builder.cc +1 -1
  7. data/leveldb/db/builder.h +1 -1
  8. data/leveldb/db/corruption_test.cc +1 -1
  9. data/leveldb/db/db_bench.cc +2 -2
  10. data/leveldb/db/db_impl.cc +8 -16
  11. data/leveldb/db/db_impl.h +1 -1
  12. data/leveldb/db/db_iter.cc +1 -1
  13. data/leveldb/db/db_iter.h +1 -1
  14. data/leveldb/db/db_test.cc +180 -9
  15. data/leveldb/db/dbformat.cc +9 -7
  16. data/leveldb/db/dbformat.h +2 -2
  17. data/leveldb/db/dbformat_test.cc +1 -1
  18. data/leveldb/db/filename.cc +6 -2
  19. data/leveldb/db/filename.h +1 -1
  20. data/leveldb/db/filename_test.cc +1 -1
  21. data/leveldb/db/log_format.h +2 -2
  22. data/leveldb/db/log_reader.cc +2 -2
  23. data/leveldb/db/log_reader.h +2 -2
  24. data/leveldb/db/log_test.cc +2 -2
  25. data/leveldb/db/log_writer.cc +2 -2
  26. data/leveldb/db/log_writer.h +2 -2
  27. data/leveldb/db/memtable.cc +1 -1
  28. data/leveldb/db/memtable.h +1 -1
  29. data/leveldb/db/repair.cc +2 -2
  30. data/leveldb/db/skiplist.h +1 -1
  31. data/leveldb/db/skiplist_test.cc +1 -1
  32. data/leveldb/db/snapshot.h +1 -1
  33. data/leveldb/db/table_cache.cc +1 -1
  34. data/leveldb/db/table_cache.h +1 -1
  35. data/leveldb/db/version_edit.cc +1 -1
  36. data/leveldb/db/version_edit.h +1 -1
  37. data/leveldb/db/version_edit_test.cc +1 -1
  38. data/leveldb/db/version_set.cc +39 -14
  39. data/leveldb/db/version_set.h +1 -1
  40. data/leveldb/db/version_set_test.cc +1 -1
  41. data/leveldb/db/write_batch.cc +2 -2
  42. data/leveldb/db/write_batch_internal.h +1 -1
  43. data/leveldb/db/write_batch_test.cc +1 -1
  44. data/leveldb/helpers/memenv/memenv.cc +374 -0
  45. data/leveldb/helpers/memenv/memenv.h +20 -0
  46. data/leveldb/helpers/memenv/memenv_test.cc +232 -0
  47. data/leveldb/include/leveldb/cache.h +1 -1
  48. data/leveldb/include/leveldb/comparator.h +1 -1
  49. data/leveldb/include/leveldb/db.h +1 -1
  50. data/leveldb/include/leveldb/env.h +1 -1
  51. data/leveldb/include/leveldb/iterator.h +1 -1
  52. data/leveldb/include/leveldb/options.h +1 -1
  53. data/leveldb/include/leveldb/slice.h +1 -1
  54. data/leveldb/include/leveldb/status.h +1 -1
  55. data/leveldb/include/leveldb/table.h +1 -1
  56. data/leveldb/include/leveldb/table_builder.h +1 -1
  57. data/leveldb/include/leveldb/write_batch.h +1 -1
  58. data/leveldb/port/atomic_pointer.h +2 -2
  59. data/leveldb/port/port_android.cc +2 -2
  60. data/leveldb/port/port_android.h +2 -2
  61. data/leveldb/port/port_example.h +2 -2
  62. data/leveldb/port/port_posix.cc +2 -2
  63. data/leveldb/port/port_posix.h +11 -3
  64. data/leveldb/table/block.cc +1 -1
  65. data/leveldb/table/block.h +1 -1
  66. data/leveldb/table/block_builder.cc +1 -1
  67. data/leveldb/table/block_builder.h +1 -1
  68. data/leveldb/table/format.cc +1 -1
  69. data/leveldb/table/format.h +1 -1
  70. data/leveldb/table/iterator.cc +2 -2
  71. data/leveldb/table/merger.cc +2 -2
  72. data/leveldb/table/merger.h +1 -1
  73. data/leveldb/table/table.cc +1 -1
  74. data/leveldb/table/table_builder.cc +1 -1
  75. data/leveldb/table/table_test.cc +3 -3
  76. data/leveldb/table/two_level_iterator.cc +2 -2
  77. data/leveldb/table/two_level_iterator.h +1 -1
  78. data/leveldb/util/arena.cc +1 -1
  79. data/leveldb/util/arena.h +1 -1
  80. data/leveldb/util/arena_test.cc +1 -1
  81. data/leveldb/util/cache.cc +1 -1
  82. data/leveldb/util/cache_test.cc +1 -1
  83. data/leveldb/util/coding.cc +1 -1
  84. data/leveldb/util/coding.h +1 -1
  85. data/leveldb/util/coding_test.cc +1 -1
  86. data/leveldb/util/comparator.cc +7 -4
  87. data/leveldb/util/crc32c.cc +2 -2
  88. data/leveldb/util/crc32c.h +2 -2
  89. data/leveldb/util/crc32c_test.cc +2 -2
  90. data/leveldb/util/env.cc +17 -3
  91. data/leveldb/util/env_posix.cc +2 -2
  92. data/leveldb/util/env_test.cc +13 -11
  93. data/leveldb/util/hash.cc +1 -1
  94. data/leveldb/util/histogram.cc +1 -1
  95. data/leveldb/util/histogram.h +1 -1
  96. data/leveldb/util/logging.cc +1 -1
  97. data/leveldb/util/logging.h +1 -1
  98. data/leveldb/util/mutexlock.h +1 -1
  99. data/leveldb/util/options.cc +1 -1
  100. data/leveldb/util/posix_logger.h +1 -1
  101. data/leveldb/util/random.h +1 -1
  102. data/leveldb/util/status.cc +1 -1
  103. data/leveldb/util/testharness.cc +2 -2
  104. data/leveldb/util/testharness.h +2 -2
  105. data/leveldb/util/testutil.cc +2 -2
  106. data/leveldb/util/testutil.h +2 -2
  107. data/lib/leveldb.rb +34 -2
  108. metadata +7 -13
  109. data/leveldb/port/port_chromium.cc +0 -80
  110. data/leveldb/port/port_chromium.h +0 -97
  111. data/leveldb/port/port_osx.cc +0 -50
  112. data/leveldb/port/port_osx.h +0 -125
  113. data/leveldb/port/sha1_portable.cc +0 -298
  114. data/leveldb/port/sha1_portable.h +0 -25
  115. data/leveldb/port/sha1_test.cc +0 -39
  116. data/leveldb/util/env_chromium.cc +0 -612
@@ -0,0 +1,20 @@
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
+
5
+ #ifndef STORAGE_LEVELDB_HELPERS_MEMENV_MEMENV_H_
6
+ #define STORAGE_LEVELDB_HELPERS_MEMENV_MEMENV_H_
7
+
8
+ namespace leveldb {
9
+
10
+ class Env;
11
+
12
+ // Returns a new environment that stores its data in memory and delegates
13
+ // all non-file-storage tasks to base_env. The caller must delete the result
14
+ // when it is no longer needed.
15
+ // *base_env must remain live while the result is in use.
16
+ Env* NewMemEnv(Env* base_env);
17
+
18
+ } // namespace leveldb
19
+
20
+ #endif // STORAGE_LEVELDB_HELPERS_MEMENV_MEMENV_H_
@@ -0,0 +1,232 @@
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
+
5
+ #include "helpers/memenv/memenv.h"
6
+
7
+ #include "db/db_impl.h"
8
+ #include "leveldb/db.h"
9
+ #include "leveldb/env.h"
10
+ #include "util/testharness.h"
11
+ #include <string>
12
+ #include <vector>
13
+
14
+ namespace leveldb {
15
+
16
+ class MemEnvTest {
17
+ public:
18
+ Env* env_;
19
+
20
+ MemEnvTest()
21
+ : env_(NewMemEnv(Env::Default())) {
22
+ }
23
+ ~MemEnvTest() {
24
+ delete env_;
25
+ }
26
+ };
27
+
28
+ TEST(MemEnvTest, Basics) {
29
+ uint64_t file_size;
30
+ WritableFile* writable_file;
31
+ std::vector<std::string> children;
32
+
33
+ ASSERT_OK(env_->CreateDir("/dir"));
34
+
35
+ // Check that the directory is empty.
36
+ ASSERT_TRUE(!env_->FileExists("/dir/non_existent"));
37
+ ASSERT_TRUE(!env_->GetFileSize("/dir/non_existent", &file_size).ok());
38
+ ASSERT_OK(env_->GetChildren("/dir", &children));
39
+ ASSERT_EQ(0, children.size());
40
+
41
+ // Create a file.
42
+ ASSERT_OK(env_->NewWritableFile("/dir/f", &writable_file));
43
+ delete writable_file;
44
+
45
+ // Check that the file exists.
46
+ ASSERT_TRUE(env_->FileExists("/dir/f"));
47
+ ASSERT_OK(env_->GetFileSize("/dir/f", &file_size));
48
+ ASSERT_EQ(0, file_size);
49
+ ASSERT_OK(env_->GetChildren("/dir", &children));
50
+ ASSERT_EQ(1, children.size());
51
+ ASSERT_EQ("f", children[0]);
52
+
53
+ // Write to the file.
54
+ ASSERT_OK(env_->NewWritableFile("/dir/f", &writable_file));
55
+ ASSERT_OK(writable_file->Append("abc"));
56
+ delete writable_file;
57
+
58
+ // Check for expected size.
59
+ ASSERT_OK(env_->GetFileSize("/dir/f", &file_size));
60
+ ASSERT_EQ(3, file_size);
61
+
62
+ // Check that renaming works.
63
+ ASSERT_TRUE(!env_->RenameFile("/dir/non_existent", "/dir/g").ok());
64
+ ASSERT_OK(env_->RenameFile("/dir/f", "/dir/g"));
65
+ ASSERT_TRUE(!env_->FileExists("/dir/f"));
66
+ ASSERT_TRUE(env_->FileExists("/dir/g"));
67
+ ASSERT_OK(env_->GetFileSize("/dir/g", &file_size));
68
+ ASSERT_EQ(3, file_size);
69
+
70
+ // Check that opening non-existent file fails.
71
+ SequentialFile* seq_file;
72
+ RandomAccessFile* rand_file;
73
+ ASSERT_TRUE(!env_->NewSequentialFile("/dir/non_existent", &seq_file).ok());
74
+ ASSERT_TRUE(!seq_file);
75
+ ASSERT_TRUE(!env_->NewRandomAccessFile("/dir/non_existent", &rand_file).ok());
76
+ ASSERT_TRUE(!rand_file);
77
+
78
+ // Check that deleting works.
79
+ ASSERT_TRUE(!env_->DeleteFile("/dir/non_existent").ok());
80
+ ASSERT_OK(env_->DeleteFile("/dir/g"));
81
+ ASSERT_TRUE(!env_->FileExists("/dir/g"));
82
+ ASSERT_OK(env_->GetChildren("/dir", &children));
83
+ ASSERT_EQ(0, children.size());
84
+ ASSERT_OK(env_->DeleteDir("/dir"));
85
+ }
86
+
87
+ TEST(MemEnvTest, ReadWrite) {
88
+ WritableFile* writable_file;
89
+ SequentialFile* seq_file;
90
+ RandomAccessFile* rand_file;
91
+ Slice result;
92
+ char scratch[100];
93
+
94
+ ASSERT_OK(env_->CreateDir("/dir"));
95
+
96
+ ASSERT_OK(env_->NewWritableFile("/dir/f", &writable_file));
97
+ ASSERT_OK(writable_file->Append("hello "));
98
+ ASSERT_OK(writable_file->Append("world"));
99
+ delete writable_file;
100
+
101
+ // Read sequentially.
102
+ ASSERT_OK(env_->NewSequentialFile("/dir/f", &seq_file));
103
+ ASSERT_OK(seq_file->Read(5, &result, scratch)); // Read "hello".
104
+ ASSERT_EQ(0, result.compare("hello"));
105
+ ASSERT_OK(seq_file->Skip(1));
106
+ ASSERT_OK(seq_file->Read(1000, &result, scratch)); // Read "world".
107
+ ASSERT_EQ(0, result.compare("world"));
108
+ ASSERT_OK(seq_file->Read(1000, &result, scratch)); // Try reading past EOF.
109
+ ASSERT_EQ(0, result.size());
110
+ ASSERT_OK(seq_file->Skip(100)); // Try to skip past end of file.
111
+ ASSERT_OK(seq_file->Read(1000, &result, scratch));
112
+ ASSERT_EQ(0, result.size());
113
+ delete seq_file;
114
+
115
+ // Random reads.
116
+ ASSERT_OK(env_->NewRandomAccessFile("/dir/f", &rand_file));
117
+ ASSERT_OK(rand_file->Read(6, 5, &result, scratch)); // Read "world".
118
+ ASSERT_EQ(0, result.compare("world"));
119
+ ASSERT_OK(rand_file->Read(0, 5, &result, scratch)); // Read "hello".
120
+ ASSERT_EQ(0, result.compare("hello"));
121
+ ASSERT_OK(rand_file->Read(10, 100, &result, scratch)); // Read "d".
122
+ ASSERT_EQ(0, result.compare("d"));
123
+
124
+ // Too high offset.
125
+ ASSERT_TRUE(!rand_file->Read(1000, 5, &result, scratch).ok());
126
+ delete rand_file;
127
+ }
128
+
129
+ TEST(MemEnvTest, Locks) {
130
+ FileLock* lock;
131
+
132
+ // These are no-ops, but we test they return success.
133
+ ASSERT_OK(env_->LockFile("some file", &lock));
134
+ ASSERT_OK(env_->UnlockFile(lock));
135
+ }
136
+
137
+ TEST(MemEnvTest, Misc) {
138
+ std::string test_dir;
139
+ ASSERT_OK(env_->GetTestDirectory(&test_dir));
140
+ ASSERT_TRUE(!test_dir.empty());
141
+
142
+ WritableFile* writable_file;
143
+ ASSERT_OK(env_->NewWritableFile("/a/b", &writable_file));
144
+
145
+ // These are no-ops, but we test they return success.
146
+ ASSERT_OK(writable_file->Sync());
147
+ ASSERT_OK(writable_file->Flush());
148
+ ASSERT_OK(writable_file->Close());
149
+ delete writable_file;
150
+ }
151
+
152
+ TEST(MemEnvTest, LargeWrite) {
153
+ const size_t kWriteSize = 300 * 1024;
154
+ char* scratch = new char[kWriteSize * 2];
155
+
156
+ std::string write_data;
157
+ for (size_t i = 0; i < kWriteSize; ++i) {
158
+ write_data.append(1, static_cast<char>(i));
159
+ }
160
+
161
+ WritableFile* writable_file;
162
+ ASSERT_OK(env_->NewWritableFile("/dir/f", &writable_file));
163
+ ASSERT_OK(writable_file->Append("foo"));
164
+ ASSERT_OK(writable_file->Append(write_data));
165
+ delete writable_file;
166
+
167
+ SequentialFile* seq_file;
168
+ Slice result;
169
+ ASSERT_OK(env_->NewSequentialFile("/dir/f", &seq_file));
170
+ ASSERT_OK(seq_file->Read(3, &result, scratch)); // Read "foo".
171
+ ASSERT_EQ(0, result.compare("foo"));
172
+
173
+ size_t read = 0;
174
+ std::string read_data;
175
+ while (read < kWriteSize) {
176
+ ASSERT_OK(seq_file->Read(kWriteSize - read, &result, scratch));
177
+ read_data.append(result.data(), result.size());
178
+ read += result.size();
179
+ }
180
+ ASSERT_TRUE(write_data == read_data);
181
+ delete seq_file;
182
+ delete [] scratch;
183
+ }
184
+
185
+ TEST(MemEnvTest, DBTest) {
186
+ Options options;
187
+ options.create_if_missing = true;
188
+ options.env = env_;
189
+ DB* db;
190
+
191
+ const Slice keys[] = {Slice("aaa"), Slice("bbb"), Slice("ccc")};
192
+ const Slice vals[] = {Slice("foo"), Slice("bar"), Slice("baz")};
193
+
194
+ ASSERT_OK(DB::Open(options, "/dir/db", &db));
195
+ for (size_t i = 0; i < 3; ++i) {
196
+ ASSERT_OK(db->Put(WriteOptions(), keys[i], vals[i]));
197
+ }
198
+
199
+ for (size_t i = 0; i < 3; ++i) {
200
+ std::string res;
201
+ ASSERT_OK(db->Get(ReadOptions(), keys[i], &res));
202
+ ASSERT_TRUE(res == vals[i]);
203
+ }
204
+
205
+ Iterator* iterator = db->NewIterator(ReadOptions());
206
+ iterator->SeekToFirst();
207
+ for (size_t i = 0; i < 3; ++i) {
208
+ ASSERT_TRUE(iterator->Valid());
209
+ ASSERT_TRUE(keys[i] == iterator->key());
210
+ ASSERT_TRUE(vals[i] == iterator->value());
211
+ iterator->Next();
212
+ }
213
+ ASSERT_TRUE(!iterator->Valid());
214
+ delete iterator;
215
+
216
+ DBImpl* dbi = reinterpret_cast<DBImpl*>(db);
217
+ ASSERT_OK(dbi->TEST_CompactMemTable());
218
+
219
+ for (size_t i = 0; i < 3; ++i) {
220
+ std::string res;
221
+ ASSERT_OK(db->Get(ReadOptions(), keys[i], &res));
222
+ ASSERT_TRUE(res == vals[i]);
223
+ }
224
+
225
+ delete db;
226
+ }
227
+
228
+ } // namespace leveldb
229
+
230
+ int main(int argc, char** argv) {
231
+ return leveldb::test::RunAllTests();
232
+ }
@@ -94,6 +94,6 @@ class Cache {
94
94
  void operator=(const Cache&);
95
95
  };
96
96
 
97
- }
97
+ } // namespace leveldb
98
98
 
99
99
  #endif // STORAGE_LEVELDB_UTIL_CACHE_H_
@@ -58,6 +58,6 @@ class Comparator {
58
58
  // must not be deleted.
59
59
  extern const Comparator* BytewiseComparator();
60
60
 
61
- }
61
+ } // namespace leveldb
62
62
 
63
63
  #endif // STORAGE_LEVELDB_INCLUDE_COMPARATOR_H_
@@ -155,6 +155,6 @@ Status DestroyDB(const std::string& name, const Options& options);
155
155
  // on a database that contains important information.
156
156
  Status RepairDB(const std::string& dbname, const Options& options);
157
157
 
158
- }
158
+ } // namespace leveldb
159
159
 
160
160
  #endif // STORAGE_LEVELDB_INCLUDE_DB_H_
@@ -318,6 +318,6 @@ class EnvWrapper : public Env {
318
318
  Env* target_;
319
319
  };
320
320
 
321
- }
321
+ } // namespace leveldb
322
322
 
323
323
  #endif // STORAGE_LEVELDB_INCLUDE_ENV_H_
@@ -95,6 +95,6 @@ extern Iterator* NewEmptyIterator();
95
95
  // Return an empty iterator with the specified status.
96
96
  extern Iterator* NewErrorIterator(const Status& status);
97
97
 
98
- }
98
+ } // namespace leveldb
99
99
 
100
100
  #endif // STORAGE_LEVELDB_INCLUDE_ITERATOR_H_
@@ -182,6 +182,6 @@ struct WriteOptions {
182
182
  }
183
183
  };
184
184
 
185
- }
185
+ } // namespace leveldb
186
186
 
187
187
  #endif // STORAGE_LEVELDB_INCLUDE_OPTIONS_H_
@@ -103,7 +103,7 @@ inline int Slice::compare(const Slice& b) const {
103
103
  return r;
104
104
  }
105
105
 
106
- }
106
+ } // namespace leveldb
107
107
 
108
108
 
109
109
  #endif // STORAGE_LEVELDB_INCLUDE_SLICE_H_
@@ -95,6 +95,6 @@ inline void Status::operator=(const Status& s) {
95
95
  }
96
96
  }
97
97
 
98
- }
98
+ } // namespace leveldb
99
99
 
100
100
  #endif // STORAGE_LEVELDB_INCLUDE_STATUS_H_
@@ -65,6 +65,6 @@ class Table {
65
65
  void operator=(const Table&);
66
66
  };
67
67
 
68
- }
68
+ } // namespace leveldb
69
69
 
70
70
  #endif // STORAGE_LEVELDB_INCLUDE_TABLE_H_
@@ -86,6 +86,6 @@ class TableBuilder {
86
86
  void operator=(const TableBuilder&);
87
87
  };
88
88
 
89
- }
89
+ } // namespace leveldb
90
90
 
91
91
  #endif // STORAGE_LEVELDB_INCLUDE_TABLE_BUILDER_H_
@@ -59,6 +59,6 @@ class WriteBatch {
59
59
  // Intentionally copyable
60
60
  };
61
61
 
62
- }
62
+ } // namespace leveldb
63
63
 
64
64
  #endif // STORAGE_LEVELDB_INCLUDE_WRITE_BATCH_H_
@@ -138,7 +138,7 @@ class AtomicPointer {
138
138
  #undef ARCH_CPU_X86_FAMILY
139
139
  #undef ARCH_CPU_ARM_FAMILY
140
140
 
141
- } // namespace leveldb::port
142
- } // namespace leveldb
141
+ } // namespace port
142
+ } // namespace leveldb
143
143
 
144
144
  #endif // PORT_ATOMIC_POINTER_H_
@@ -60,5 +60,5 @@ void CondVar::SignalAll() {
60
60
  PthreadCall("broadcast", pthread_cond_broadcast(&cv_));
61
61
  }
62
62
 
63
- }
64
- }
63
+ } // namespace port
64
+ } // namespace leveldb
@@ -150,7 +150,7 @@ inline bool GetHeapProfile(void (*func)(void*, const char*, int), void* arg) {
150
150
  return false;
151
151
  }
152
152
 
153
- }
154
- }
153
+ } // namespace port
154
+ } // namespace leveldb
155
155
 
156
156
  #endif // STORAGE_LEVELDB_PORT_PORT_ANDROID_H_
@@ -119,7 +119,7 @@ extern bool Snappy_Uncompress(const char* input_data, size_t input_length,
119
119
  // The concatenation of all "data[0,n-1]" fragments is the heap profile.
120
120
  extern bool GetHeapProfile(void (*func)(void*, const char*, int), void* arg);
121
121
 
122
- }
123
- }
122
+ } // namespace port
123
+ } // namespace leveldb
124
124
 
125
125
  #endif // STORAGE_LEVELDB_PORT_PORT_EXAMPLE_H_
@@ -46,5 +46,5 @@ void CondVar::SignalAll() {
46
46
  PthreadCall("broadcast", pthread_cond_broadcast(&cv_));
47
47
  }
48
48
 
49
- }
50
- }
49
+ } // namespace port
50
+ } // namespace leveldb
@@ -7,7 +7,7 @@
7
7
  #ifndef STORAGE_LEVELDB_PORT_PORT_POSIX_H_
8
8
  #define STORAGE_LEVELDB_PORT_PORT_POSIX_H_
9
9
 
10
- #if defined(OS_MACOSX) || defined(OS_FREEBSD)
10
+ #if defined(OS_MACOSX)
11
11
  #include <machine/endian.h>
12
12
  #elif defined(OS_SOLARIS)
13
13
  #include <sys/isa_defs.h>
@@ -16,6 +16,10 @@
16
16
  #else
17
17
  #define BIG_ENDIAN
18
18
  #endif
19
+ #elif defined(OS_FREEBSD) || defined(OS_OPENBSD) || defined(OS_NETBSD) ||\
20
+ defined(OS_DRAGONFLYBSD)
21
+ #include <sys/types.h>
22
+ #include <sys/endian.h>
19
23
  #else
20
24
  #include <endian.h>
21
25
  #endif
@@ -33,13 +37,17 @@
33
37
  #define IS_LITTLE_ENDIAN (__BYTE_ORDER == __LITTLE_ENDIAN)
34
38
  #endif
35
39
 
36
- #if defined(OS_MACOSX) || defined(OS_SOLARIS) || defined(OS_FREEBSD)
40
+ #if defined(OS_MACOSX) || defined(OS_SOLARIS) || defined(OS_FREEBSD) ||\
41
+ defined(OS_NETBSD) || defined(OS_OPENBSD) || defined(OS_DRAGONFLYBSD)
42
+ // Use fread/fwrite/fflush on platforms without _unlocked variants
37
43
  #define fread_unlocked fread
38
44
  #define fwrite_unlocked fwrite
39
45
  #define fflush_unlocked fflush
40
46
  #endif
41
47
 
42
- #if defined(OS_MACOSX) || defined(OS_FREEBSD)
48
+ #if defined(OS_MACOSX) || defined(OS_FREEBSD) ||\
49
+ defined(OS_OPENBSD) || defined(OS_DRAGONFLYBSD)
50
+ // Use fsync() on platforms without fdatasync()
43
51
  #define fdatasync fsync
44
52
  #endif
45
53
 
@@ -260,4 +260,4 @@ Iterator* Block::NewIterator(const Comparator* cmp) {
260
260
  }
261
261
  }
262
262
 
263
- }
263
+ } // namespace leveldb