Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 61a560ae authored by Elliott Hughes's avatar Elliott Hughes Committed by Gerrit Code Review
Browse files

Merge "adb: win32: remove widen()/narrow() in favor of UTF8ToWide()/WideToUTF8()"

parents 5d75c9d9 d21dc825
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -28,7 +28,9 @@ ADB_COMMON_darwin_CFLAGS := \
# Define windows.h and tchar.h Unicode preprocessor symbols so that
# CreateFile(), _tfopen(), etc. map to versions that take wchar_t*, breaking the
# build if you accidentally pass char*. Fix by calling like:
# CreateFileW(widen(utf8).c_str()).
#   std::wstring path_wide;
#   if (!android::base::UTF8ToWide(path_utf8, &path_wide)) { /* error handling */ }
#   CreateFileW(path_wide.c_str());
ADB_COMMON_windows_CFLAGS := \
    -DUNICODE=1 -D_UNICODE=1 \

+3 −1
Original line number Diff line number Diff line
@@ -311,7 +311,9 @@ static int get_user_keyfilepath(char *filename, size_t len)
              SystemErrorCodeToString(hr).c_str());
            return -1;
        }
        home_str = narrow(path);
        if (!android::base::WideToUTF8(path, &home_str)) {
            return -1;
        }
        home = home_str.c_str();
    }
    format = "%s\\%s";
+6 −1
Original line number Diff line number Diff line
@@ -58,7 +58,12 @@ static std::string GetLogFilePath() {
              SystemErrorCodeToString(GetLastError()).c_str());
    }

    return narrow(temp_path) + log_name;
    std::string temp_path_utf8;
    if (!android::base::WideToUTF8(temp_path, &temp_path_utf8)) {
        fatal_errno("cannot convert temporary file path from UTF-16 to UTF-8");
    }

    return temp_path_utf8 + log_name;
}
#else
static const char kNullFileName[] = "/dev/null";
+1 −1
Original line number Diff line number Diff line
@@ -77,7 +77,7 @@ void LinePrinter::Print(string to_print, LineType type) {
    CONSOLE_SCREEN_BUFFER_INFO csbi;
    GetConsoleScreenBufferInfo(console_, &csbi);

    // TODO: const std::wstring to_print_wide = widen(to_print);
    // TODO: std::wstring to_print_wide; if (!android::base::UTF8ToWide(to_print, &to_print_wide)...
    // TODO: wstring ElideMiddle.
    to_print = ElideMiddle(to_print, static_cast<size_t>(csbi.dwSize.X));
    // We don't want to have the cursor spamming back and forth, so instead of
+4 −13
Original line number Diff line number Diff line
@@ -28,6 +28,9 @@

#include <string>

// Include this before open/unlink are defined as macros below.
#include <base/utf8.h>

/*
 * TEMP_FAILURE_RETRY is defined by some, but not all, versions of
 * <unistd.h>. (Alas, it is not as standard as we'd hoped!) So, if it's
@@ -72,7 +75,7 @@
#include <ws2tcpip.h>

#include <memory>   // unique_ptr
#include <string>   // Prototypes for narrow() and widen() use std::(w)string.
#include <string>

#include "fdevent.h"

@@ -342,18 +345,6 @@ inline void seekdir(DIR*, long) {
char* adb_strerror(int err);
#define strerror adb_strerror

// Convert from UTF-8 to UTF-16, typically used to convert char strings into
// wchar_t strings that can be passed to wchar_t-based OS and C Runtime APIs
// on Windows.
extern std::wstring widen(const std::string& utf8);
extern std::wstring widen(const char* utf8);

// Convert from UTF-16 to UTF-8, typically used to convert strings from OS and
// C Runtime APIs that return wchar_t, to a format for our char-based data
// structures.
extern std::string narrow(const std::wstring& utf16);
extern std::string narrow(const wchar_t* utf16);

// Helper class to convert UTF-16 argv from wmain() to UTF-8 args that can be
// passed to main().
class NarrowArgs {
Loading