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

Support for non-English characters as input path #62

Open
l3lackShark opened this issue Aug 30, 2020 · 6 comments
Open

Support for non-English characters as input path #62

l3lackShark opened this issue Aug 30, 2020 · 6 comments

Comments

@l3lackShark
Copy link

I'm using oppai as a library for my project and if the user's Windows username contains non-English characters, the fopen() function will result in an I/O error. This might be what I'm looking for, but I'm not very well experienced with C... Is this something that I have to deal with on my own or can it be fixed within the scope of this project?
image

@omkelderman
Copy link

omkelderman commented Aug 30, 2020

ok so I did some random testing, conciser this extremely simple C program:

#include <stdio.h>
int main(int argc, char* argv[])
{
	for (int i = 0; i < argc; ++i)
	{
		printf("%i -> %s\n", i, argv[i]);
	}
}

that resulted in:

then I changed the code to this:

#include <stdio.h>

int wmain(int argc, wchar_t* argv[])
{
	for(int i=0; i<argc; ++i)
	{
		wprintf(L"%i -> %ws\n", i, argv[i]);
	}
}

got literally the same result.

But, once you start debugging, there is a difference!
the first program:

the second program:

notice how with the first thing, there are literal question mark characters in the place of the non-english things, with the second program that is not the case and the string-data is fine there, there it is just the output that gets fucked (which results in the same apparent result).

As for opening a file, if you have a wchar_t* string, you can do so with _wfopen (which takes a wchar_t* string instead of a char* string), which returns a FILE* so all the read and close code should be the same. So putting the fopen in a platform macro is ez, but the problem here is that also the main function needs to be changed to support this (ofc only on windows), and then all the commandline data is suddenly a wchar_t* string which makes everything else probably slightly fucked

so uuh. yeeee, windows sucks lol

@Francesco149
Copy link
Owner

yea this looks like a windows specific issue, might be solvable by explicitly setting locale or something. will test eventually

@Francesco149
Copy link
Owner

doing setlocale(LC_CTYPE, ".UTF-8") might work if you wanna test on your own.

@Francesco149
Copy link
Owner

ehh this turns out to be a bit more complicated and messy. need to use _wmain instead of main and convert between utf-8 and utf-16 i guess

@Wieku
Copy link

Wieku commented Nov 1, 2020

I had similar problem in my program, but with BASS library. Windows only support UTF-16 paths. I resolved it by adding a simple converter that launches only under Windows:
https://github.com/Wieku/danser-go/blob/master/framework/bass/bass_util.c

@l3lackShark
Copy link
Author

Was able to fix this on my own. My implementation is ugly, so if someone picks up the solution and makes a PR out of it that would be highly appreciated. l3lackShark/gosumemory@0630d5d#diff-788c0375f94352a09cb71054e8f4e45b4897d0a49eac28e85c799f9f1549a9a5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants