Skip to content

Commit 139108a

Browse files
laanwjPastaPastaPasta
authored andcommitted
Merge bitcoin#15270: Pull leveldb subtree
4f2e6c8 Squashed 'src/leveldb/' changes from 524b7e3..f545dfa (MarcoFalke) Pull request description: Some windows-related fixes. Sanity check with: ``` git fetch https://github.com/bitcoin-core/leveldb ./test/lint/git-subtree-check.sh src/leveldb Tree-SHA512: ff94907ff3075b81cffb733129673a9bfd2abbe84240686b29274382b64b4e5845880236458043d6db0332bf70d12942d9c0e68b4fffab43931103d224cb59d4
1 parent ce0118b commit 139108a

File tree

3 files changed

+22
-12
lines changed

3 files changed

+22
-12
lines changed

src/leveldb/db/c.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
#include "leveldb/c.h"
66

77
#include <stdlib.h>
8+
#ifndef WIN32
89
#include <unistd.h>
10+
#endif
911
#include "leveldb/cache.h"
1012
#include "leveldb/comparator.h"
1113
#include "leveldb/db.h"

src/leveldb/port/port_win.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,16 @@
3232
#define STORAGE_LEVELDB_PORT_PORT_WIN_H_
3333

3434
#ifdef _MSC_VER
35+
#if !(_MSC_VER >= 1900)
3536
#define snprintf _snprintf
37+
#endif
3638
#define close _close
3739
#define fread_unlocked _fread_nolock
40+
#ifdef _WIN64
41+
#define ssize_t int64_t
42+
#else
43+
#define ssize_t int32_t
44+
#endif
3845
#endif
3946

4047
#include <string>

src/leveldb/util/env_win.cc

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -200,24 +200,16 @@ class Win32Env : public Env
200200

201201
void ToWidePath(const std::string& value, std::wstring& target) {
202202
wchar_t buffer[MAX_PATH];
203-
MultiByteToWideChar(CP_ACP, 0, value.c_str(), -1, buffer, MAX_PATH);
203+
MultiByteToWideChar(CP_UTF8, 0, value.c_str(), -1, buffer, MAX_PATH);
204204
target = buffer;
205205
}
206206

207207
void ToNarrowPath(const std::wstring& value, std::string& target) {
208208
char buffer[MAX_PATH];
209-
WideCharToMultiByte(CP_ACP, 0, value.c_str(), -1, buffer, MAX_PATH, NULL, NULL);
209+
WideCharToMultiByte(CP_UTF8, 0, value.c_str(), -1, buffer, MAX_PATH, NULL, NULL);
210210
target = buffer;
211211
}
212212

213-
std::string GetCurrentDir()
214-
{
215-
CHAR path[MAX_PATH];
216-
::GetModuleFileNameA(::GetModuleHandleA(NULL),path,MAX_PATH);
217-
*strrchr(path,'\\') = 0;
218-
return std::string(path);
219-
}
220-
221213
std::wstring GetCurrentDirW()
222214
{
223215
WCHAR path[MAX_PATH];
@@ -226,6 +218,13 @@ std::wstring GetCurrentDirW()
226218
return std::wstring(path);
227219
}
228220

221+
std::string GetCurrentDir()
222+
{
223+
std::string path;
224+
ToNarrowPath(GetCurrentDirW(), path);
225+
return path;
226+
}
227+
229228
std::string& ModifyPath(std::string& path)
230229
{
231230
if(path[0] == '/' || path[0] == '\\'){
@@ -761,14 +760,16 @@ uint64_t Win32Env::NowMicros()
761760
static Status CreateDirInner( const std::string& dirname )
762761
{
763762
Status sRet;
764-
DWORD attr = ::GetFileAttributes(dirname.c_str());
763+
std::wstring dirnameW;
764+
ToWidePath(dirname, dirnameW);
765+
DWORD attr = ::GetFileAttributesW(dirnameW.c_str());
765766
if (attr == INVALID_FILE_ATTRIBUTES) { // doesn't exist:
766767
std::size_t slash = dirname.find_last_of("\\");
767768
if (slash != std::string::npos){
768769
sRet = CreateDirInner(dirname.substr(0, slash));
769770
if (!sRet.ok()) return sRet;
770771
}
771-
BOOL result = ::CreateDirectory(dirname.c_str(), NULL);
772+
BOOL result = ::CreateDirectoryW(dirnameW.c_str(), NULL);
772773
if (result == FALSE) {
773774
sRet = Status::IOError(dirname, "Could not create directory.");
774775
return sRet;

0 commit comments

Comments
 (0)