Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 是否有Unix系统调用以截断当前偏移量处的文件_Linux_File_Unix - Fatal编程技术网

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

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,

是否有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);
}
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()的用法。