开发者

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

I am using getenv("HOME") 开发者_如何学Pythonin 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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜