Chinaunix

标题: How to get the name of the file pointed to by symbolic link [打印本页]

作者: cs    时间: 2003-03-19 10:38
标题: How to get the name of the file pointed to by symbolic link
as title,
how do do it in c language?
is there any system function can be invoked?

Thanks
作者: 无双    时间: 2003-03-19 12:49
标题: How to get the name of the file pointed to by symbolic link
stat  lstat 函数
作者: haosheng    时间: 2003-03-19 21:08
提示: 作者被禁止或删除 内容自动屏蔽
作者: cs    时间: 2003-03-20 10:58
标题: How to get the name of the file pointed to by symbolic link
you might misunderstood my means, what you do is just
to check whether  the file is a symbolic link, but what I
want to know is how to get the file name(including the whole path)
of the file that pointed to by the symbolic link, for example:

the symbolic link  is '/home/cs/temp/test_slink',  and it is
pointed to '/home/cs/share/test', then, in c func, how  do we
know that '/home/cs/temp/test_slink' is pointed to '/home/cs/share/test'?

thanks!
作者: stevenyi    时间: 2003-03-21 00:11
标题: How to get the name of the file pointed to by symbolic link
i catch what you mean. but i dont know how to do it
作者: gadfly    时间: 2003-03-21 12:18
标题: How to get the name of the file pointed to by symbolic link
U can use readlink.

#ll ee
lrwxrwxrwx    1 gadfly      gadfly             2  3月 20 13:20 ee ->; bb

getlink.c


  1. #include <stdio.h>;

  2. int main()
  3. {

  4.         char buf[256];
  5.         int len;

  6.         len = readlink("ee", buf, sizeof(buf));
  7.         if (len >; -1) {
  8.                 buf[len] = '\0';
  9.                 printf("ee link from :%s\n", buf);
  10.         }
  11.         return 0;
  12. }
复制代码


#gcc -o getlink getlink.c

./getlink
ee link from :bb
作者: cs    时间: 2003-03-21 13:41
标题: How to get the name of the file pointed to by symbolic link
thanks gadfly!




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2