summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorcmumford <cmumford@google.com>2019-03-01 13:12:01 -0800
committerVictor Costan <pwnall@chromium.org>2019-03-01 18:00:35 -0800
commitc69d33b0ec3dad2a8063ad66da9d51a1d6309f4e (patch)
treeb3ef286b0a30952d87aebd111e161cda94b52563 /include
parentfe4494804f5e3a2e25485d32aeb0eb7d2f25732e (diff)
downloadleveldb-c69d33b0ec3dad2a8063ad66da9d51a1d6309f4e.tar.gz
Added native support for Windows.
This change adds a native Windows port (port_windows.h) and a Windows Env (WindowsEnv). Note1: "small" is defined when including <Windows.h> so some parameters were renamed to avoid conflict. Note2: leveldb::Env defines the method: "DeleteFile" which is also a constant defined when including <Windows.h>. The solution was to ensure this macro is defined in env.h which forces the function, when compiled, to be either DeleteFileA or DeleteFileW when building for MBCS or UNICODE respectively. This resolves #519 on GitHub. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=236364778
Diffstat (limited to 'include')
-rw-r--r--include/leveldb/env.h30
1 files changed, 30 insertions, 0 deletions
diff --git a/include/leveldb/env.h b/include/leveldb/env.h
index 59e2a6f..946ea98 100644
--- a/include/leveldb/env.h
+++ b/include/leveldb/env.h
@@ -20,6 +20,27 @@
#include "leveldb/export.h"
#include "leveldb/status.h"
+#if defined(_WIN32)
+// The leveldb::Env class below contains a DeleteFile method.
+// At the same time, <windows.h>, a fairly popular header
+// file for Windows applications, defines a DeleteFile macro.
+//
+// Without any intervention on our part, the result of this
+// unfortunate coincidence is that the name of the
+// leveldb::Env::DeleteFile method seen by the compiler depends on
+// whether <windows.h> was included before or after the LevelDB
+// headers.
+//
+// To avoid headaches, we undefined DeleteFile (if defined) and
+// redefine it at the bottom of this file. This way <windows.h>
+// can be included before this file (or not at all) and the
+// exported method will always be leveldb::Env::DeleteFile.
+#if defined(DeleteFile)
+#undef DeleteFile
+#define LEVELDB_DELETEFILE_UNDEFINED
+#endif // defined(DeleteFile)
+#endif // defined(_WIN32)
+
namespace leveldb {
class FileLock;
@@ -356,4 +377,13 @@ class LEVELDB_EXPORT EnvWrapper : public Env {
} // namespace leveldb
+// Redefine DeleteFile if necessary.
+#if defined(_WIN32) && defined(LEVELDB_DELETEFILE_UNDEFINED)
+#if defined(UNICODE)
+#define DeleteFile DeleteFileW
+#else
+#define DeleteFile DeleteFileA
+#endif // defined(UNICODE)
+#endif // defined(_WIN32) && defined(LEVELDB_DELETEFILE_UNDEFINED)
+
#endif // STORAGE_LEVELDB_INCLUDE_ENV_H_