欢迎使用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);  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值