chdir/fchdir/getcwd
char *getcwd(char *buf, size_t size);
功能:获取当前进程的工作目录,工作目录是指当不加路径信息时,创建/打开时从那个目录下查找,
工作目录默认是程序所在的目录
int chdir(const char *path);
功能:修改进程的工作目录
返回值:成功返回0,失败返回-1
int fchdir(int fd);
功能:修改进程的工作目录
fd:被open打开的目录文件的fd
返回值:成功返回0,失败返回-1
opendir/fdopendir/closedir/readdir/rewinddir/telldir/seekdir
#include <dirent.h>
DIR *opendir(const char *name);
功能:打开一个目录流
返回值:目录流(链表)
DIR *fdopendir(int fd);
功能:使用文件描述符获取目录流,fd必须是目录文件的
int closedir(DIR *dirp);
功能:关闭目录流
struct dirent *readdir(DIR *dirp);
功能:从目录流中读取一个文件节点信息
struct dirent {
ino_t d_ino; /* inode number */i节点号
off_t d_off; /* offset to the next dirent */下一个文件结点信息的偏移量
unsigned short d_reclen; /* length of this record */当前文件结点信息的长度
unsigned char d_type; /* type of file; not supported by all file system types */文件类型
char d_name[256]; /* filename */文件名字
};
DT_CHR This is a character device.
DT_DIR This is a directory.
DT_FIFO This is a named pipe (FIFO).
DT_LNK This is a symbolic link.
DT_REG This is a regular file.
DT_SOCK This is a UNIX domain socket.
DT_UNKNOWN The file type is unknown.
int readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result);
void rewinddir(DIR *dirp);
功能:把目录流的位置指针调整到开头
long telldir(DIR *dirp);
功能:获取当前目录流的位置指针在第几结点
void seekdir(DIR *dirp, long offset);
功能:调整当前目录流的位置指针
offer:根据当前位置指针进行偏移