Reputation: 563
I'm working with internationalized filenames in my C-program. There's particularly my piece of code where I create file with Chinese symbol:
int fd = open("/tmp/⺴", O_WRONLY | O_CREAT | O_TRUNC);
This function works well and file is created in spite that my system locale is Russian (LANG=ru_RU.UTF-8).
Why is this file created while my locale seems to not support codes of Chinese symbols? In this case what's the field which is influenced by system locale?
Upvotes: 1
Views: 272
Reputation:
The open(2)
function is a just a wrapper for the open
system call -- and and does nothing else that putting the arguments in the right registers, performing the system call and retrieving its return value.
And the kernel doesn't know or care about locales at all.
Specifically, in the path
argument of open(2)
the only bytes which have special significance are 47 (/
) which separates path elements and 0 (the NUL byte) which terminates it.
Neither the kernel not most filesystems will prevent you from creating files with names which are malformed utf-8 or any binary garbage -- for the kernel they're just bytes.
Also, the kernel isn't doing any unicode normalization or handling of confusables:
$ echo > ∕еtс∕раsswd; touch hó hó
$ ls
hó hó ∕еtс∕раsswd
Upvotes: 3