Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
是否有 Linux api 可以在当前偏移处截断打开的文件?我可以执行 lseek(),然后执行 ftruncate(),但试图保存系统调用。
ftell() 是你的朋友:
/* do operations on file, such as fread() or fwrite() */ curpos = ftell(filehandle); if (result = ftruncate(filehandle, curpos)) { /* handle the error condition, examine errno etc */ exit(errno); }