欢迎使用CSDN-markdown编辑器

Unix系统API汇集

fileno: 将文件指针转换成文件描述符
       int fileno(FILE *stream);
fdopen: 将文件描述符转换成文件指针
       FILE *fdopen(int fd, const char *mode);
#include <sys/types.h> 
#include <sys/stat.h> 
#include <fcntl.h> 
int open(const char *pathname, int flags);  
int open(const char *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, const void *buf, size_t count);  
返回值:
   错误: -1
   什么都没做: 0

int 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(const char *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 */  
    unsigned short d_reclen;    /* length of this record */  
    unsigned char  d_type;      /* type of file; not supported by all filesystem types */  
    char           d_name[256]; /* filename */  
};  

int closedir(DIR *dirp);  

int mkdir(const char *pathname, mode_t mode);  

int rmdir(const char *pathname);  

Chmod, fchmod更改权限
int chmod(const char *path, mode_t mode);  
int fchmod(int fd, mode_t mode);  

chown,fchown更改文件所有者/所属组
int chown(const char *path, uid_t owner, gid_t group);  
int fchown(int fd, uid_t owner, gid_t group);  

你可能感兴趣的:(欢迎使用CSDN-markdown编辑器)