Squashed 'src/leveldb/' changes from 524b7e36a8..f545dfabff
f545dfabff Merge #18: Use utf-8 to decode filename f8e797a058 Use utf-8 to decode filename 2fc114812a Merge #14: Fixes to allow building with msvc. d6eab93138 Fixes to allow building with msvc. git-subtree-dir: src/leveldb git-subtree-split: f545dfabff4c2e9836efed094dba99a34fbc6b88
This commit is contained in:
parent
ec749b1bcd
commit
4f2e6c8b88
3 changed files with 22 additions and 12 deletions
2
db/c.cc
2
db/c.cc
|
@ -5,7 +5,9 @@
|
||||||
#include "leveldb/c.h"
|
#include "leveldb/c.h"
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#ifndef WIN32
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#endif
|
||||||
#include "leveldb/cache.h"
|
#include "leveldb/cache.h"
|
||||||
#include "leveldb/comparator.h"
|
#include "leveldb/comparator.h"
|
||||||
#include "leveldb/db.h"
|
#include "leveldb/db.h"
|
||||||
|
|
|
@ -32,9 +32,16 @@
|
||||||
#define STORAGE_LEVELDB_PORT_PORT_WIN_H_
|
#define STORAGE_LEVELDB_PORT_PORT_WIN_H_
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
|
#if !(_MSC_VER >= 1900)
|
||||||
#define snprintf _snprintf
|
#define snprintf _snprintf
|
||||||
|
#endif
|
||||||
#define close _close
|
#define close _close
|
||||||
#define fread_unlocked _fread_nolock
|
#define fread_unlocked _fread_nolock
|
||||||
|
#ifdef _WIN64
|
||||||
|
#define ssize_t int64_t
|
||||||
|
#else
|
||||||
|
#define ssize_t int32_t
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
|
@ -203,24 +203,16 @@ public:
|
||||||
|
|
||||||
void ToWidePath(const std::string& value, std::wstring& target) {
|
void ToWidePath(const std::string& value, std::wstring& target) {
|
||||||
wchar_t buffer[MAX_PATH];
|
wchar_t buffer[MAX_PATH];
|
||||||
MultiByteToWideChar(CP_ACP, 0, value.c_str(), -1, buffer, MAX_PATH);
|
MultiByteToWideChar(CP_UTF8, 0, value.c_str(), -1, buffer, MAX_PATH);
|
||||||
target = buffer;
|
target = buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ToNarrowPath(const std::wstring& value, std::string& target) {
|
void ToNarrowPath(const std::wstring& value, std::string& target) {
|
||||||
char buffer[MAX_PATH];
|
char buffer[MAX_PATH];
|
||||||
WideCharToMultiByte(CP_ACP, 0, value.c_str(), -1, buffer, MAX_PATH, NULL, NULL);
|
WideCharToMultiByte(CP_UTF8, 0, value.c_str(), -1, buffer, MAX_PATH, NULL, NULL);
|
||||||
target = buffer;
|
target = buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string GetCurrentDir()
|
|
||||||
{
|
|
||||||
CHAR path[MAX_PATH];
|
|
||||||
::GetModuleFileNameA(::GetModuleHandleA(NULL),path,MAX_PATH);
|
|
||||||
*strrchr(path,'\\') = 0;
|
|
||||||
return std::string(path);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::wstring GetCurrentDirW()
|
std::wstring GetCurrentDirW()
|
||||||
{
|
{
|
||||||
WCHAR path[MAX_PATH];
|
WCHAR path[MAX_PATH];
|
||||||
|
@ -229,6 +221,13 @@ std::wstring GetCurrentDirW()
|
||||||
return std::wstring(path);
|
return std::wstring(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string GetCurrentDir()
|
||||||
|
{
|
||||||
|
std::string path;
|
||||||
|
ToNarrowPath(GetCurrentDirW(), path);
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
std::string& ModifyPath(std::string& path)
|
std::string& ModifyPath(std::string& path)
|
||||||
{
|
{
|
||||||
if(path[0] == '/' || path[0] == '\\'){
|
if(path[0] == '/' || path[0] == '\\'){
|
||||||
|
@ -764,14 +763,16 @@ uint64_t Win32Env::NowMicros()
|
||||||
static Status CreateDirInner( const std::string& dirname )
|
static Status CreateDirInner( const std::string& dirname )
|
||||||
{
|
{
|
||||||
Status sRet;
|
Status sRet;
|
||||||
DWORD attr = ::GetFileAttributes(dirname.c_str());
|
std::wstring dirnameW;
|
||||||
|
ToWidePath(dirname, dirnameW);
|
||||||
|
DWORD attr = ::GetFileAttributesW(dirnameW.c_str());
|
||||||
if (attr == INVALID_FILE_ATTRIBUTES) { // doesn't exist:
|
if (attr == INVALID_FILE_ATTRIBUTES) { // doesn't exist:
|
||||||
std::size_t slash = dirname.find_last_of("\\");
|
std::size_t slash = dirname.find_last_of("\\");
|
||||||
if (slash != std::string::npos){
|
if (slash != std::string::npos){
|
||||||
sRet = CreateDirInner(dirname.substr(0, slash));
|
sRet = CreateDirInner(dirname.substr(0, slash));
|
||||||
if (!sRet.ok()) return sRet;
|
if (!sRet.ok()) return sRet;
|
||||||
}
|
}
|
||||||
BOOL result = ::CreateDirectory(dirname.c_str(), NULL);
|
BOOL result = ::CreateDirectoryW(dirnameW.c_str(), NULL);
|
||||||
if (result == FALSE) {
|
if (result == FALSE) {
|
||||||
sRet = Status::IOError(dirname, "Could not create directory.");
|
sRet = Status::IOError(dirname, "Could not create directory.");
|
||||||
return sRet;
|
return sRet;
|
||||||
|
|
Loading…
Reference in a new issue