简体   繁体   中英

Linux/Unix: Non-ascii characters in home directory?

I am using getenv("HOME") in C to get the user's home directory in order to read/write a settings file. But is it possible that the home directory filename could contain characters that cannot be represented as an 8 bit char? (for example, unicode or UTF-8 encoded)

Does this differ for various varieties of Linux and *BSD?

Thanks in advance...

Yes, it is possible that the string could be UTF-8; however, the value of $HOME must then be a valid UTF-8 string and the string will only contain complete valid UTF-8 characters. Note that UTF-8 simply uses most (but not all; it omits 0xC0, 0xC1, 0xF5..0xFF) of the possible 8-bit chararacter values. That means you don't have to worry very much about it unless you want to. In particular, UTF-8 only uses a zero byte to indicate U+0000, which is equivalent to ASCII NUL or '\\0' and is encoded in a single byte (value 0).

The conclusion doesn't vary across platforms; different systems may make it more or less difficult to create home directories that need non-ASCII UTF-8 characters.

See also: SO 164430

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM