lseek

标准C库: 
    #include <stdio.h>
    int fseek(FILE *stream, long offset, int whence);
Linux库:
    #include <sys/types.h>
    #include <unistd.h>   
    off_t lseek(int fd, off_t offset, int whence);
        参数:
        - fd:文件描述符得到,通过open得到
        - offset:偏移量
        - whence:
            SEEK_SET:设置文件指针偏移量
            SEEK_CUR:当前位置+第二个参数offset的值
            SEEK_END:设置偏移量:文件的大小+offset的值
    返回值:返回文件的位置

    作用:
    - 移动文件指针到头文件
      lseek(fd,0,SEEk_SET);
    - 获取当前文件指针的位置
      lseek(fd,0,SEEK_CUR);
    - 获取文件长度
      lseek(fd,0,SEEK_END);
    - 扩展文件长度,当前文件10b,11b,增加文件100个字节
      lseek(fd,100,SEEK_END);

posted @ 2023-02-08 16:59  小秦同学在上学  阅读(91)  评论(0编辑  收藏  举报