Truncate file at front

前端 未结 7 875
耶瑟儿~
耶瑟儿~ 2020-12-09 09:48

A problem I was working on recently got me to wishing that I could lop off the front of a file. Kind of like a “truncate at front,” if you will. Truncating a file at the bac

7条回答
  •  伪装坚强ぢ
    2020-12-09 10:31

    may can achieve this goal in two steps

    long fileLength; //file total length
    long reserveLength; //reserve length until the file ending
    int fd; //file open for read & write
    
    sendfile(fd, fd, fileLength-reserveLength, reserveLength);
    ftruncate(fd, reserveLength);
    

提交回复
热议问题