forked from lite-xl/lite-xl
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make system.* functions support UTF8 filenames (lite-xl#1042)
* make system.* functions support UTF8 filenames * move utfconv.h into ifdef guard * fix wrong null check
- Loading branch information
1 parent
06aafae
commit 8b6b2a9
Showing
1 changed file
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#ifndef MBSEC_H | ||
#define MBSEC_H | ||
|
||
#ifdef _WIN32 | ||
|
||
#include <stdlib.h> | ||
#include <windows.h> | ||
|
||
#define UTFCONV_ERROR_INVALID_CONVERSION "Input contains invalid byte sequences." | ||
|
||
LPWSTR utfconv_utf8towc(const char *str) { | ||
LPWSTR output; | ||
int len; | ||
|
||
// len includes \0 | ||
len = MultiByteToWideChar(CP_UTF8, 0, str, -1, NULL, 0); | ||
if (len == 0) | ||
return NULL; | ||
|
||
output = (LPWSTR) malloc(sizeof(WCHAR) * len); | ||
if (output == NULL) | ||
return NULL; | ||
|
||
len = MultiByteToWideChar(CP_UTF8, 0, str, -1, output, len); | ||
if (len == 0) { | ||
free(output); | ||
return NULL; | ||
} | ||
|
||
return output; | ||
} | ||
|
||
char *utfconv_wctoutf8(LPCWSTR str) { | ||
char *output; | ||
int len; | ||
|
||
// len includes \0 | ||
len = WideCharToMultiByte(CP_UTF8, 0, str, -1, NULL, 0, NULL, NULL); | ||
if (len == 0) | ||
return NULL; | ||
|
||
output = (char *) malloc(sizeof(char) * len); | ||
if (output == NULL) | ||
return NULL; | ||
|
||
len = WideCharToMultiByte(CP_UTF8, 0, str, -1, output, len, NULL, NULL); | ||
if (len == 0) { | ||
free(output); | ||
return NULL; | ||
} | ||
|
||
return output; | ||
} | ||
|
||
#endif | ||
|
||
#endif |