I have a large C++ project that was originally developed on Windows for drawing, parsing, and processing drawings. Due to historical reasons, this project was initially designed to support GBK encoding only on Simplified Chinese systems. As a result, a significant number of resources such as drawings and configuration files are encoded in GBK.
Now, I want to run this project on Linux while maintaining compatibility with the existing drawings and other resource files. The program interacts with the Linux API, which expects UTF-8 encoding for reading and writing. I have tried performing encoding conversion in various places where character encoding is involved, but the workload is significant, and it is challenging to ensure complete internal encoding uniformity within the program.
Here is an abstract code to explain what my program wants to do:
struct MySheet{
char *gbkSubSheet;
int otherAttributes;
};
int main()
{
// Assuming this is a drawing sheet created by the user, which contains path information for some sub files
// Due to historical reasons, these drawings stored path information in the form of C strings
char subSheetFromUserInput[512] = "gbkPathOfSubSheet";
MySheet mySheetFromWindow;
mySheetFromWindow.gbkSubSheet = subSheetFromUserInput;
// I want the same code to run properly on both Windows and Linux systems
// Because the program must be compatible with existing drawings and able to cross platforms
FILE* fp = fopen(mySheetFromWindow.gbkSubSheet, "r");
/* ... read the sheet ... */
fclose(fp);
//===================================================
// The following approach is not what I want
// because there are many similar places in the code that require GBK encoding
FILE* fp = fopen(gbkToUTF8(mySheetFromWindow.gbkSubSheet), "r");
/* ... read the sheet ... */
fclose(fp);
return 0;
}
Is there a way to make the program run in a GBK environment on Linux, where interfaces like fopen, access, mkdir, getcwd, and others related to character encoding api accept GBK encoding?