The filename is the byte string; regardless of locale or any other conventions you're using about how filenames should be encoded, the string you must pass to fopen
and to all functions taking filenames/pathnames is the exact byte string for how the file is named. For example if you have a file named ö.txt
in UTF-8 in NFC, and your locale is UTF-8 encoded and uses NFC, you can just write the name as ö.txt
and pass that to fopen
. If your locale is Latin-1 based, though, you can't pass the Latin-1 form of ö.txt
("\xf6.txt"
) to fopen
and expect it to succeed; that's a different byte string and thus a different filename. You would need to pass "\xc3\xb6.txt"
("ö.txt"
if you interpret that as Latin-1), the same byte string as the actual name.
This situation is very different from Windows, which you seem to be familiar with, where the filename is is a sequence of 16-bit units interpreted as UTF-16 (although AFAIK they need not actually be valid UTF-16) and filenames passed to fopen
, etc. are interpreted according to the current locale as Unicode characters which are then used to open/access the file based on its UTF-16 name.