2

現在のオフセットで開いているファイルを切り捨てる Linux API はありますか? lseek() の後に ftruncate() を実行できますが、システム コールを保存しようとしていました。

4

1 に答える 1

-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);
}
于 2014-02-06T12:21:38.257 に答える