是否有Unix系统调用以截断当前偏移量的文件

时间:2013-10-16 14:04:54

标签: linux file unix

是否有Linux api截断当前偏移量的打开文件? 我可以执行lseek(),然后执行ftruncate(),但是尝试保存系统调用。

1 个答案:

答案 0 :(得分:-1)

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);
}