简体   繁体   English

Linux / Unix:主目录中是否包含非ASCII字符?

[英]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. 我在C中使用getenv(“ HOME”)来获取用户的主目录,以便读取/写入设置文件。 But is it possible that the home directory filename could contain characters that cannot be represented as an 8 bit char? 但是主目录文件名是否可能包含无法表示为8位字符的字符? (for example, unicode or UTF-8 encoded) (例如,Unicode或UTF-8编码)

Does this differ for various varieties of Linux and *BSD? 对于各种Linux和* BSD,这是否有所不同?

Thanks in advance... 提前致谢...

Yes, it is possible that the string could be UTF-8; 是的,字符串可能是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. 但是,$ HOME的值必须是有效的UTF-8字符串,并且该字符串将仅包含完整的有效UTF-8字符。 Note that UTF-8 simply uses most (but not all; it omits 0xC0, 0xC1, 0xF5..0xFF) of the possible 8-bit chararacter values. 请注意,UTF-8仅使用了大多数(但不全部;它省略了0xC0、0xC1、0xF5..0xFF)可能的8位字符值。 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). 特别是,UTF-8仅使用零字节来表示U + 0000,它等效于ASCII NUL或'\\0'并且被编码为单个字节(值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. 不同的系统可能会或多或少使创建需要非ASCII UTF-8字符的主目录变得困难。

See also: SO 164430 另请参阅: SO 164430

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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