檔案I O相關函式

2021-06-08 09:22:35 字數 1665 閱讀 8413

1.open()系統呼叫

開啟乙個檔案返回檔案描述符

int open (const char *name, int flags);

int open (const char *name, int flags, mode_t mode);

2.creat()函式

int creat (const char *name, mode_t mode);

3.read()讀取檔案

ssize_t read (int fd, void *buf, size_t len);

4.write()寫檔案

ssize_t write (int fd, const void *buf, size_t count);

5.同步i/o

int fsync (int fd);//在驅動確認資料寫入之前不會返回

int fdatasync (int fd);//僅寫入資料不等待寫入完成

void sync (void);//對磁碟上的所有緩衝區進行同步

6.關閉檔案

int close (int fd);

7.用 lseek() 查詢

off_t lseek (int fd, off_t pos, int origin);

8.定位讀寫

ssize_t pread (int fd, void *buf, size_t count,off_t pos);

ssize_t pwrite (int fd, const void *buf, size_t count, off_t pos);

9.截短檔案

int truncate (const char *path, off_t len);

10.i/o多路復用

select()函式:

int select (int n,fd_set *readfds,fd_set *writefds,fd_set *exceptfds,struct timeval *timeout);

fd_clr(int fd, fd_set *set);

fd_isset(int fd, fd_set *set);

fd_set(int fd, fd_set *set);

fd_zero(fd_set *set);

timeval結構體定義:

struct timeval ;

pselect()函式:

int pselect (int n,fd_set *readfds,fd_set *writefds,fd_set *exceptfds,const struct timespec *timeout,const sigset_t *sigmask);

fd_clr(int fd, fd_set *set);

fd_isset(int fd, fd_set *set);

fd_set(int fd, fd_set *set);

fd_zero(fd_set *set);

timespec結構體定義:

struct timespec ;

poll()函式

int poll (struct pollfd *fds, unsigned int nfds,int timeout);

pollfd結構體定義:

struct pollfd ;

檔案I O相關函式

include 成功返回檔案描述符,出錯返回 1 int open const char path,int oflag,mode t mode int openat int fd,const char path,int oflag,mode t mode int creat const char p...

C 語言檔案I O相關函式

一 i o相關函式 函式描述 intopen const char path,int oflag,位於 標頭檔案 可以開啟或建立乙個檔案。引數見下方1 返回值 若成功,返回檔案描述符 若出錯,返回 1。intopenat int fd,const char path,int oflag,位於 標頭檔...

檔案I O函式

開啟或者建立檔案 open openat include int open const char path,int oflag,int openat int fd,const char path,int oflag,成功返回檔案描述符,失敗返回 1 oflag引數 o rdonly o wronly...