LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1126|回复: 3

S_ISLNK测试的问题(stat.h)

[复制链接]
发表于 2007-4-20 12:54:51 | 显示全部楼层 |阅读模式
[root@localhost work]# ll slink prog
-rwxr-xr-x    1 root     root        12752  4月 19 23:25 prog
lrwxrwxrwx    1 root     root            4  4月 20 12:44 slink -> prog

源文件file.c
#include <unistd.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <stdlib.h>
                                                                              
int main()
{
        int filedes;
        struct stat statbuf;
        unsigned short int modes;
        
        stat("slink",&statbuf);
        modes=statbuf.st_mode;
      
        printf("slink mode is %o \n",modes);
        printf("is link %d\n",S_ISLNK(modes));

}

gcc file.c -o file
./file
运行结果:
slink mode is 100755
is link 0
显示的竟然是prog文件的信息.
而不是链接文件slink的信息..
请高手解答.
 楼主| 发表于 2007-4-20 14:35:21 | 显示全部楼层
解决...不能用stat 用lstat..
回复 支持 反对

使用道具 举报

发表于 2007-4-20 21:10:48 | 显示全部楼层
请高手解答.
-----------
我觉得这样的话还是少说得好,
有些拒绝其他人回答的意思。
  ----------------
这个问题如果查阅过 unix高级编程 就会知道的,不一定要高手
回复 支持 反对

使用道具 举报

发表于 2007-4-20 21:33:10 | 显示全部楼层
Post by gvlr

这个问题如果查阅过 unix高级编程 就会知道的,不一定要高手

其实查查 stat(3) 的手册就可以了。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表