linux总结应用之四 系统调用函数

(一):creat 系统调用: 创建文件的系统调用                  

  调用方法:

         #include  <sys/types.h>

         #include  <sys/stat.h>

         #include  <fcntl.h>

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

          其中path是文件描述符,mode是文件的权限.

          完全等价于近代的open()调用

         fd = open(file,O_WRONLY|O_CREAT|O_TRUNC,mode);

       

(二):read系统调用:如果该文件是用O_RDONLY或O_RDWR标志打开的

         # include <sys/types.h>

         # include <unistd.h>

      

          int read(int fd,void *buf,size_t nbytes);

          其中fd是想要读的文件描述符,buf是指向内存块的指针,nbytes是要读的个数

 

(三);write系统调用:   

    # include <sys/types.h>

           # include <unistd.h>

                   

    int write(int fd,void *buf,size_t nbytes);

            注意:write写入的不是磁盘而是内存缓冲区。write不可能直接写入磁盘。

         

    fd = open(file,O_WRONLY|O_SYNC);

           O_SYNC这个标志的效果是使对特定的文件描述符write()系统调用

和相应的实际写磁盘同步,事实上,直到实际写磁盘已经完成,write()系统调用才返回。

  

原文地址:https://www.cnblogs.com/cliuwei/p/4748537.html