zoukankan      html  css  js  c++  java
  • 文件IO函数

    SYNOPSIS
           #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);
     
           int creat(const char *pathname, mode_t mode);
     
     Given a pathname for a file, open() returns a file descriptor,
     
     The argument flags must include one  of  the  following  access  modes:
           O_RDONLY,  O_WRONLY,  or  O_RDWR.  These request opening the file read-
           only, write-only, or read/write, respectively.
     
      O_EXCL Ensure that this call creates the file: if this flag  is  speci‐
                  fied  in  conjunction with O_CREAT, and pathname already exists,
                  then open() will fail.
    RETURN VALUE
           open() and creat() return the new file descriptor, or -1  if  an  error
           occurred (in which case, errno is set appropriately).
     
     
        #include <unistd.h>
     
           int close(int fd);
    RETURN VALUE
           close()  returns  zero on success.  On error, -1 is returned, and errno
           is set appropriately.
     
     #include <unistd.h>
     
           ssize_t read(int fd, void *buf, size_t count);
    DESCRIPTION
           read()  attempts to read up to count bytes from file descriptor fd into
           the buffer starting at buf.
     
    RETURN VALUE
           On success, the number of bytes read is returned (zero indicates end of
           file), and the file position is advanced by this number.  It is not  an
           error  if  this  number  is smaller than the number of bytes requested;
           this may happen for example because fewer bytes are actually  available
           right  now  (maybe  because we were close to end-of-file, or because we
           are reading from a pipe, or from a terminal),  or  because  read()  was
           interrupted  by  a  signal.  On error, -1 is returned, and errno is set
           appropriately.  In this case it is left unspecified  whether  the  file
           position (if any) changes.
     
     
    SYNOPSIS
           #include <unistd.h>
     
           ssize_t write(int fd, const void *buf, size_t count);
     
    DESCRIPTION
           write()  writes  up  to  count bytes from the buffer pointed buf to the
           file referred to by the file descriptor fd.
    RETURN VALUE
           On  success,  the  number  of bytes written is returned (zero indicates
           nothing was written).  On error, -1  is  returned,  and  errno  is  set
           appropriately.
     
    SYNOPSIS
           #include <sys/types.h>
           #include <unistd.h>
     
           off_t lseek(int fd, off_t offset, int whence);
     
    DESCRIPTION
           The lseek() function repositions the offset of the open file associated
           with the file descriptor fd to the argument  offset  according  to  the
           directive whence as follows:
     
           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.
     
    RETURN VALUE
           Upon successful completion, lseek() returns the resulting offset  loca‐
           tion  as  measured  in bytes from the beginning of the file.  On error,
           the value (off_t) -1 is returned and  errno  is  set  to  indicate  the
           error.
     
  • 相关阅读:
    gulp使用技巧-删除node_modules文件夹,解决目录层次太深删除报错的问题
    PHP学习-链接数据库
    教程笔记《JavaScript深入浅出》
    读书笔记《高性能网站建设指南》之雅虎军规
    CSS3边框图片-像素虚边的问题
    WebStorm设置手机测试服务器-局域网内其他设备访问
    gulp的安装和使用
    H5canvas赛车游戏-基于lufylegend引擎
    WebStorm设置左侧菜单栏背景色和样式
    基于jquery的-获取短信验证码-倒计时
  • 原文地址:https://www.cnblogs.com/smile-at-you/p/3359411.html
Copyright © 2011-2022 走看看