Linux 文件管理 不带缓冲区的I/O的操作

来源:互联网 发布:js jsonarray remove 编辑:程序博客网 时间:2024/05/28 19:24
1.creat
 函数的作用: 创建一个文件;
 函数的原型: int  creat(const char *pathname, mode_t mode);
 文件头:  #include <sys/types.h>
       #include <sys/stat.h>
       #include <fcntl.h>
 返回值:成功:新的文件描述符;
         出错:  -1
         
     创建几个函数:file_creat.c的函数的编写;
     
2. open
函数的作用:打开一个文件;
函数的原型:
int  open(const char *pahtname, int flags);
int  open(const char *pahtname, int flags, mode_t mode);
返回值:文件描述符---成功;出错:-1;
flags:
参数:
O_RDONLY
  O_WRONLY;
O_RDWR;
    O_CREAT:  如果原来折耳根文件不存在,那么有这个参数就可以创建这个文件;
    O_APPEND:原来有内容,则会自动保留文件内容,自动向下读写;
    O_TRUNC:  文件存在,有内容,文件清空;
    
 
 3. read
 函数的作用: 从打开的文件中读取数据
 函数的原型:ssize_t  read(int fd, void *buf,  size_t count);
 包含的头文件: #include  <unistd.h>
  
返回值:正常是实际读到的字节数;
       如果是在文件结束或者是无数据,返回0;
       出错,-1;
 4. write
 函数的作用: 向打开的文件中写数据
 函数的原型: ssize_t   write(int fd, const void *buf, size_t count);
 头文件:  #include <unistd.h>
    
 返回值:  成功会返回实际写入的字节数;
          出错:-1;
          
4. lseek
函数的功能:进行文件定位
函数的原型:  int lseek(int fd, offset_t  offset, int whence);
函数的参数:fd:
           offset: 指针的微调,在指定的指针向前移动为负, 向后为正;
           whence:  SEEK_SET:放在文件头
            SEEK_CUR:当前的位置;
            SEEK_END:  文件尾;
             
  返回值:返回文件当前指针到文件开始的地方有多少字节;
  出错-1;
0 0
原创粉丝点击