From 83301fc2a11fce5b6ceb4ad238b8c10cf1b27f47 Mon Sep 17 00:00:00 2001 From: Thomas Gamper Date: Thu, 8 Jun 2023 10:18:15 +0200 Subject: [PATCH] mz_os.h - fix indentation; mz_os_win32.c - adjust for utf8 strings to be represented by char*; test_encoding.cc - remove useless cast --- mz_os.h | 2 +- mz_os_win32.c | 24 ++++++++++++------------ test/test_encoding.cc | 2 +- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/mz_os.h b/mz_os.h index bec115b..ad6ea4f 100644 --- a/mz_os.h +++ b/mz_os.h @@ -107,7 +107,7 @@ wchar_t *mz_os_unicode_string_create(const char *string, int32_t encoding); void mz_os_unicode_string_delete(wchar_t **string); /* Delete a unicode string that was created */ -char *mz_os_utf8_string_create(const char *string, int32_t encoding); +char *mz_os_utf8_string_create(const char *string, int32_t encoding); /* Create a utf8 string from a string with another encoding */ void mz_os_utf8_string_delete(char **string); diff --git a/mz_os_win32.c b/mz_os_win32.c index 1c438fc..2010d98 100644 --- a/mz_os_win32.c +++ b/mz_os_win32.c @@ -58,18 +58,18 @@ void mz_os_unicode_string_delete(wchar_t **string) { } } -uint8_t *mz_os_utf8_string_create(const char *string, int32_t encoding) { +char *mz_os_utf8_string_create(const char *string, int32_t encoding) { wchar_t *string_wide = NULL; - uint8_t *string_utf8 = NULL; + char *string_utf8 = NULL; uint32_t string_utf8_size = 0; string_wide = mz_os_unicode_string_create(string, encoding); if (string_wide) { string_utf8_size = WideCharToMultiByte(CP_UTF8, 0, string_wide, -1, NULL, 0, NULL, NULL); - string_utf8 = (uint8_t *)calloc(string_utf8_size + 1, sizeof(wchar_t)); + string_utf8 = (char *)calloc(string_utf8_size + 1, sizeof(char)); if (string_utf8) - WideCharToMultiByte(CP_UTF8, 0, string_wide, -1, (char *)string_utf8, string_utf8_size, NULL, NULL); + WideCharToMultiByte(CP_UTF8, 0, string_wide, -1, string_utf8, string_utf8_size, NULL, NULL); mz_os_unicode_string_delete(&string_wide); } @@ -77,22 +77,22 @@ uint8_t *mz_os_utf8_string_create(const char *string, int32_t encoding) { return string_utf8; } -uint8_t *mz_os_utf8_string_create_from_unicode(const wchar_t *string, int32_t encoding) { - uint8_t *string_utf8 = NULL; +char *mz_os_utf8_string_create_from_unicode(const wchar_t *string, int32_t encoding) { + char *string_utf8 = NULL; uint32_t string_utf8_size = 0; MZ_UNUSED(encoding); string_utf8_size = WideCharToMultiByte(CP_UTF8, 0, string, -1, NULL, 0, NULL, NULL); - string_utf8 = (uint8_t *)calloc(string_utf8_size + 1, sizeof(wchar_t)); + string_utf8 = (char *)calloc(string_utf8_size + 1, sizeof(char)); if (string_utf8) - WideCharToMultiByte(CP_UTF8, 0, string, -1, (char *)string_utf8, string_utf8_size, NULL, NULL); + WideCharToMultiByte(CP_UTF8, 0, string, -1, string_utf8, string_utf8_size, NULL, NULL); return string_utf8; } -void mz_os_utf8_string_delete(uint8_t **string) { +void mz_os_utf8_string_delete(char **string) { if (string) { free(*string); *string = NULL; @@ -563,7 +563,7 @@ int32_t mz_os_read_symlink(const char *path, char *target_path, int32_t max_targ int32_t target_path_len = 0; int32_t target_path_idx = 0; int32_t err = MZ_OK; - uint8_t *target_path_utf8 = NULL; + char *target_path_utf8 = NULL; if (!path) return MZ_PARAM_ERROR; @@ -609,10 +609,10 @@ int32_t mz_os_read_symlink(const char *path, char *target_path, int32_t max_targ target_path_utf8 = mz_os_utf8_string_create_from_unicode(target_path_wide, MZ_ENCODING_UTF8); if (target_path_utf8) { - strncpy(target_path, (const char *)target_path_utf8, max_target_path - 1); + strncpy(target_path, target_path_utf8, max_target_path - 1); target_path[max_target_path - 1] = 0; /* Ensure directories have slash at the end so we can recreate them later */ - if (mz_os_is_dir((const char *)target_path_utf8) == MZ_OK) + if (mz_os_is_dir(target_path_utf8) == MZ_OK) mz_path_append_slash(target_path, max_target_path, MZ_PATH_SLASH_PLATFORM); mz_os_utf8_string_delete(&target_path_utf8); } else { diff --git a/test/test_encoding.cc b/test/test_encoding.cc index 610307d..de8be89 100644 --- a/test/test_encoding.cc +++ b/test/test_encoding.cc @@ -18,7 +18,7 @@ TEST(os, utf8_unicode_string) { char *utf8_string = mz_os_utf8_string_create(test_string, MZ_ENCODING_CODEPAGE_950); ASSERT_NE(utf8_string, nullptr); #if defined(_WIN32) - wchar_t *unicode_string = mz_os_unicode_string_create((const char *)utf8_string, MZ_ENCODING_UTF8); + wchar_t *unicode_string = mz_os_unicode_string_create(utf8_string, MZ_ENCODING_UTF8); ASSERT_NE(unicode_string, nullptr); mz_os_unicode_string_delete(&unicode_string); #endif