特殊文件的操作-Linux C

时间:2014-09-03 11:02:16   收藏:0   阅读:258

1.

目录文件

在Linux下目录也是用文件来描述的特殊文件

 

创建文件夹

#include<sys/types.h>
#include<sys/stat.h>
int mkdir(const char *pathname,mode_t mode);

删除文件夹(目录必须是空目录)

#include<unistd.h>
int rmdir(const char *pathname);

 

#include<sys/types.h>
#include<dirent.h>

//打开目录
DIR *opendir(const char *pathname);

//关闭目录
int closedir(DIR *dp);

//读取目录文件
struct dirent *readdir(DIR *dp);
#include<unistd.h>

//更改目录
int chdir(const char *pathname);
int fchdir(int fd);

//获取目录名
char *getcwd(char *buf,size_t size);

 

2.

链接文件的操作

硬链接:

#include<unistd.h>

//硬链接要求链接文件和源文件必须在同一文件系统中
int link(const char *pathname1,const char *pathname2);

//删除链接
int unlink(const char *pathname);

#include<stdio.h>

//解除链接
int remove(const char *pathname);

 

符号链接;

#include<unistd.h>

//创建符号链接
int symlink(const char *actualpath,const char *sympath);

//打开链接并获取链接名字
int readlink(const char *pathname,char *buf,int bufsize);

 

3.

管道文件:

#include<stdio.h>
int pipe(int filedes[2]);

通常用于进程间通信

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!