Linux 是否有Unix系统调用以截断当前偏移量处的文件
是否有Linux api在当前偏移量截断打开的文件? 我可以先执行lseek(),然后执行ftruncate(),但我试图保存一个系统调用。ftell()是您的朋友:Linux 是否有Unix系统调用以截断当前偏移量处的文件,linux,file,unix,Linux,File,Unix,是否有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,
/* 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);
}
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);
}
ftruncate以字节为单位获取一个
off\t
,但是ftell
不一定返回一个以字节为单位的偏移量。你是正确的,我应该指定使用ftello()。ftruncate以字节为单位获取一个off\t
,但是ftell
不一定返回一个以字节为单位的偏移量。你是正确的,我应该指定ftello()的用法。