Skip to content

Commit 4f2e6c8

Browse files
author
MarcoFalke
committed
Squashed 'src/leveldb/' changes from 524b7e3..f545dfa
f545dfa Merge #18: Use utf-8 to decode filename f8e797a Use utf-8 to decode filename 2fc1148 Merge #14: Fixes to allow building with msvc. d6eab93 Fixes to allow building with msvc. git-subtree-dir: src/leveldb git-subtree-split: f545dfa
1 parent ec749b1 commit 4f2e6c8

File tree

3 files changed

+22
-12
lines changed

3 files changed

+22
-12
lines changed

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"

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>

util/env_win.cc

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

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

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

216-
std::string GetCurrentDir()
217-
{
218-
CHAR path[MAX_PATH];
219-
::GetModuleFileNameA(::GetModuleHandleA(NULL),path,MAX_PATH);
220-
*strrchr(path,'\\') = 0;
221-
return std::string(path);
222-
}
223-
224216
std::wstring GetCurrentDirW()
225217
{
226218
WCHAR path[MAX_PATH];
@@ -229,6 +221,13 @@ std::wstring GetCurrentDirW()
229221
return std::wstring(path);
230222
}
231223

224+
std::string GetCurrentDir()
225+
{
226+
std::string path;
227+
ToNarrowPath(GetCurrentDirW(), path);
228+
return path;
229+
}
230+
232231
std::string& ModifyPath(std::string& path)
233232
{
234233
if(path[0] == '/' || path[0] == '\\'){
@@ -764,14 +763,16 @@ uint64_t Win32Env::NowMicros()
764763
static Status CreateDirInner( const std::string& dirname )
765764
{
766765
Status sRet;
767-
DWORD attr = ::GetFileAttributes(dirname.c_str());
766+
std::wstring dirnameW;
767+
ToWidePath(dirname, dirnameW);
768+
DWORD attr = ::GetFileAttributesW(dirnameW.c_str());
768769
if (attr == INVALID_FILE_ATTRIBUTES) { // doesn't exist:
769770
std::size_t slash = dirname.find_last_of("\\");
770771
if (slash != std::string::npos){
771772
sRet = CreateDirInner(dirname.substr(0, slash));
772773
if (!sRet.ok()) return sRet;
773774
}
774-
BOOL result = ::CreateDirectory(dirname.c_str(), NULL);
775+
BOOL result = ::CreateDirectoryW(dirnameW.c_str(), NULL);
775776
if (result == FALSE) {
776777
sRet = Status::IOError(dirname, "Could not create directory.");
777778
return sRet;

0 commit comments

Comments
 (0)