4 ms·
UTF-8 support for filenames would be a great start, to support windows filenames in a multiplatform way in C!
by Aardwolf 5y ago
UTF-8 support for filenames would be a great start, to support windows filenames in a multiplatform way in C!
- cryptonector 5y agoBut what do you care how they file names are stored on disk, as long as you can read directories and traverse paths using UTF-8?
- Aardwolf 5y agoThe only standard C functions that manage files use zero terminated byte strings as filenames. I'm not saying C made a great design choice here either, but the combination of this and Windows using UTF-16 makes it impossible to write code that can open a file that works on both windows, and other OSes, without OS-specific #ifdefs
- gary_0 5y agoThere is a lot of C/C++ code out there that breaks with Windows unicode filenames, although most mature software projects don't just naively use fopen. Some C libraries allow you to use UTF-8 filenames for all platforms and do the right thing internally, and I'm a big fan of that.
- account42 5y agoFilenames are tricky. You need to interpret them for display and when interfacing with other systems but fudamentally, they are not Unicode strings on either Windows or Linux but rather sequences of WCHAR or char respectively (with some restrictions). That means that a UTF-8 API can never support the full range of filenames that might be present on a valid Windows filesystem. But you can have eat your cake and have it to by having that API accept WTF-8 [0] which is a superset of UTF-8 that is specifically designed for this kind of interopability. [0] https://simonsapin.github.io/wtf-8/ https://simonsapin.github.io/wtf-8/