标题: 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
#include <stdio.h>;
int main()
{
char buf[256];
int len;
len = readlink("ee", buf, sizeof(buf));
if (len >; -1) {
buf[len] = '\0';
printf("ee link from :%s\n", buf);
}
return 0;
}
复制代码
#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!