Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

icu: accept share directory for icudtl.dat #487

Merged
merged 1 commit into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/core/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,12 @@ std::wstring ExpandUserFromString(const wchar_t* path, size_t path_len);

bool GetExecutablePath(std::string* exe_path);
#ifdef _WIN32
bool GetExecutablePathW(std::wstring* exe_path);
bool GetExecutablePath(std::wstring* exe_path);
#endif

void SetExecutablePath(const std::string& exe_path);
#ifdef _WIN32
void SetExecutablePathW(const std::wstring& exe_path);
void SetExecutablePath(const std::wstring& exe_path);
#endif

bool Net_ipv6works();
Expand All @@ -166,7 +166,7 @@ ssize_t ReadFileToBuffer(const std::string& path, char* buf, size_t buf_len);
ssize_t WriteFileWithBuffer(const std::string& path, const char* buf, size_t buf_len);
PlatformFile OpenReadFile(const std::string &path);
#ifdef _WIN32
PlatformFile OpenReadFileW(const std::wstring& path);
PlatformFile OpenReadFile(const std::wstring& path);
#endif

#ifdef HAVE_TCMALLOC
Expand Down
27 changes: 9 additions & 18 deletions src/core/utils_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -658,36 +658,27 @@ bool IsWindowsVersionBNOrGreater(int wMajorVersion,
static std::string main_exe_path = "UNKNOWN";

bool GetExecutablePath(std::string* exe_path) {
DWORD len;
std::wstring wexe_path;
exe_path->clear();
// Windows XP: The string is truncated to nSize characters and is not
// null-terminated.
exe_path->resize(_MAX_PATH + 1, '\0');
len = ::GetModuleFileNameA(nullptr, const_cast<char*>(exe_path->data()),
_MAX_PATH);
exe_path->resize(len);

// A zero return value indicates a failure other than insufficient space.

// Insufficient space is determined by a return value equal to the size of
// the buffer passed in.
if (len == 0 || len == _MAX_PATH) {
PLOG(WARNING) << "Internal error: GetModuleFileNameA failed";
*exe_path = main_exe_path;
if (!GetExecutablePath(&wexe_path)) {
return false;
}
*exe_path = SysWideToUTF8(wexe_path);

return true;
}

bool GetExecutablePathW(std::wstring* exe_path) {
bool GetExecutablePath(std::wstring* exe_path) {
DWORD len;
exe_path->clear();
// Windows XP: The string is truncated to nSize characters and is not
// null-terminated.
exe_path->resize(_MAX_PATH + 1, L'\0');
len = ::GetModuleFileNameW(nullptr, const_cast<wchar_t*>(exe_path->data()),
_MAX_PATH);
// If the function succeeds, the return value is the length of the string
// that is copied to the buffer, in characters,
// not including the terminating null character.
exe_path->resize(len);

// A zero return value indicates a failure other than insufficient space.
Expand All @@ -711,7 +702,7 @@ void SetExecutablePath(const std::string& exe_path) {
absl::flags_internal::SetProgramInvocationName(new_exe_path);
}

void SetExecutablePathW(const std::wstring& exe_path) {
void SetExecutablePath(const std::wstring& exe_path) {
main_exe_path = SysWideToUTF8(exe_path);

std::string new_exe_path;
Expand Down Expand Up @@ -763,7 +754,7 @@ PlatformFile OpenReadFile(const std::string &path) {
FILE_SHARE_READ, nullptr, OPEN_EXISTING, 0, nullptr);
}

PlatformFile OpenReadFileW(const std::wstring &path) {
PlatformFile OpenReadFile(const std::wstring &path) {
return ::CreateFileW(path.c_str(), GENERIC_READ,
FILE_SHARE_READ, nullptr, OPEN_EXISTING, 0, nullptr);
}
Expand Down
15 changes: 7 additions & 8 deletions src/i18n/icu_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ wchar_t g_debug_icu_pf_filename[_MAX_PATH];
// No need to change the filename in multiple places (gyp files, windows
// build pkg configurations, etc). 'l' stands for Little Endian.
// This variable is exported through the header file.
#ifdef _WIN32
const wchar_t kIcuDataFileName[] = L"icudtl.dat";
#else
const char kIcuDataFileName[] = "icudtl.dat";
#endif

// Time zone data loading.

Expand Down Expand Up @@ -111,16 +115,12 @@ void LazyInitIcuDataFile() {
#endif // !defined(__APPLE__)
#else // 0
#ifdef _WIN32
std::wstring exe_path;
CHECK(GetExecutablePathW(&exe_path));
std::filesystem::path exe_dir = std::filesystem::path(exe_path).parent_path();
std::wstring data_path = exe_dir / SysUTF8ToWide(kIcuDataFileName);
PlatformFile pf = OpenReadFileW(data_path);
std::wstring exe_path, data_path;
#else // _WIN32
std::string exe_path;
std::string exe_path, data_path;
#endif // _WIN32
CHECK(GetExecutablePath(&exe_path));
std::filesystem::path exe_dir = std::filesystem::path(exe_path).parent_path();
std::string data_path;
PlatformFile pf = kInvalidPlatformFile;
#ifdef __APPLE__
data_path = exe_dir.parent_path() / "Resources" / kIcuDataFileName;
Expand All @@ -134,7 +134,6 @@ void LazyInitIcuDataFile() {
data_path = exe_dir / kIcuDataFileName;
pf = OpenReadFile(data_path);
}
#endif // _WIN32
#endif // 0
if (pf != kInvalidPlatformFile) {
// TODO(brucedawson): http://crbug.com/445616.
Expand Down
4 changes: 2 additions & 2 deletions src/win32/utils_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -761,8 +761,8 @@ static std::wstring GetAutoStartCmdline() {
std::wstring cmdline;

/* turn on auto start */
if (!GetExecutablePathW(&cmdline)) {
LOG(FATAL) << "GetExecutablePathW failed";
if (!GetExecutablePath(&cmdline)) {
LOG(FATAL) << "GetExecutablePath failed";
}

ss << L"\"" << cmdline << L"\" --background";
Expand Down
Loading