Chinaunix首页 | 论坛 | 博客
  • 博客访问: 344052
  • 博文数量: 60
  • 博客积分: 1570
  • 博客等级: 上尉
  • 技术积分: 620
  • 用 户 组: 普通用户
  • 注册时间: 2009-11-02 23:37
文章分类

全部博文(60)

文章存档

2012年(2)

2010年(2)

2009年(56)

分类: LINUX

2009-11-19 23:47:20

1. symlink 函数创建一个符号链接:
 

#include <unistd.h>
int symlink(const char *actualpath, const char *sympath);
                                     Returns: 0 if OK, -1 on error

   该函数创建了一个指向 actualpath 的新目录项 sympath, 在创建此符号链接时,并不要求 actualpath 已经存在。并且, actualpath 和 sympath 并不需要位于同一文件系统中。
 

2.readlink 函数打开链接本身,并读该链接中的名字。(不跟随符号链接)

#include <unistd.h>
ssize_t readlink(const char* restrict pathname, char *restrict buf, size_t bufsize);

                   Returns: number of bytes read if OK, -1 on error

    此函数组合了 open、read 和 close的所有操作。如果此函数成功执行,则它返回读入buf 的字节数。

注意:在 buf 中返回的符号链接的内容不以 null 字符终止,所以,在调用这个函数前,最好将 buf 中内容清零。

阅读(2360) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~