C 在unix系统上确定符号链接
我试图使用函数S_ISLNKfile.st_mode检查某个文件是符号链接还是目录或常规文件。但是,当我用符号链接文件检查它时,它似乎不起作用 这是我的密码:C 在unix系统上确定符号链接,c,C,我试图使用函数S_ISLNKfile.st_mode检查某个文件是符号链接还是目录或常规文件。但是,当我用符号链接文件检查它时,它似乎不起作用 这是我的密码: if(S_ISDIR(fileStat.st_mode)) { // DIR - display files in the directory printf(" DIR ");
if(S_ISDIR(fileStat.st_mode))
{
// DIR - display files in the directory
printf(" DIR ");
fileType = 2;
}else if(S_ISLNK(fileStat.st_mode)){
// LNK - display the name of the file the link is pointing to
printf(" LNK ");
fileType = 3;
}else{
// Display general info only
printf(" REG ");
fileType = 1;
}
对目录的检查工作正常,但是当我在symlink文件上运行程序时,它显示为常规文件。有人知道我可能做错了什么吗?统计链接的目标。如果要确定文件是否为符号链接,请使用lstat:
lstat与stat相同,只是如果path是一个符号链接,那么该链接本身是stat-ed的,而不是它所引用的文件
统计链接的目标。如果要确定文件是否为符号链接,请使用lstat:
lstat与stat相同,只是如果path是一个符号链接,那么该链接本身是stat-ed的,而不是它所引用的文件