#include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> int open(constchar *pathname, int flags);
int open(constchar *pathname, int flags, mode_t mode);
#include <unistd.h> int close(int fd);
ssize_t read(int fd, void *buf, size_t count);
返回值:
错误: -1
到达文件尾: 0
成功: 返回从文件复制到规定缓冲区的字节数
ssize_t write(int fd, constvoid *buf, size_t count);
返回值:
错误: -1
什么都没做: 0int fsync(int fd);
off_t lseek(int fd, off_t offset, int whence);
返回值: 新的文件偏移值;
Whence取值:
SEEK_SET
The offset is set to offset bytes.
SEEK_CUR
The offset is set to its current location plus offset bytes.
SEEK_END
The offset is set to the size of the file plus offset bytes.
#include <sys/types.h> #include <dirent.h>
DIR *opendir(constchar *name);
返回值:
成功: 返回目录指针;
失败: 返回NULL;
struct dirent *readdir(DIR *dirp);
返回值:
成功: 返回一个指向dirent结构的指针, 它包含指定目录的下一个连接的细节;
没有更多连接时, 返回0;
struct dirent
{
ino_t d_ino; /* inode number */
off_t d_off; /* not an offset; see NOTES */unsignedshort d_reclen; /* length of this record */unsignedchar d_type; /* type of file; not supported
by all filesystem types */char d_name[256]; /* filename */
};
int closedir(DIR *dirp);
int mkdir(constchar *pathname, mode_t mode);
int rmdir(constchar *pathname);
Chmod, fchmod更改权限
int chmod(constchar *path, mode_t mode);
int fchmod(int fd, mode_t mode);
chown,fchown更改文件所有者/所属组
int chown(constchar *path, uid_t owner, gid_t group);
int fchown(int fd, uid_t owner, gid_t group);