当我的程序尝试处理stat()
包含特定 UTF-8 字符的文件时,该stat()
函数会返回错误。例如,我可以/tmp/surgateDlpMgQure/Özkul Gazete
用 vi 打开文件,但传递同一个文件会stat()
产生错误。系统区域设置为:
LANG=en_US.UTF-8
LC_CTYPE="en_US.UTF-8"
LC_COLLATE=C
LC_TIME="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_ALL=
我应该做些什么stat()
来理解 UTF-8 字符吗?
这是代码:
int main ()
{
struct stat s;
if (stat("/tmp/surgateDlpMgQure/Özkul Gazete", &s) == -1)
perror("stat");
switch (s.st_mode & S_IFMT) {
case S_IFBLK: printf("block device\n"); break;
case S_IFCHR: printf("character device\n"); break;
case S_IFDIR: printf("directory\n"); break;
case S_IFIFO: printf("FIFO/pipe\n"); break;
case S_IFLNK: printf("symlink\n"); break;
case S_IFREG: printf("regular file\n"); break;
case S_IFSOCK: printf("socket\n"); break;
default: printf("unknown?\n"); break;
}
return 0;
}