【发布时间】:2016-11-04 18:33:14
【问题描述】:
如果可以保证seek后有数据要写入,那么使用fseek在文件开头保留字节是否安全?例如:
// reserve space
fseek(f, 4096, SEEK_SET);
// ...
// write some data after the reserved space
fwrite(buf, 1, bufsize, f);
// go back to the reserved space (to update it)
rewind(f);
// ...
我注意到它可以在 Windows 上运行,但是其他平台呢?有什么需要注意的问题吗?
【问题讨论】:
-
它在 Unix 上不保留空间。在您写入并刷新输出之前,文件实际上不会发生任何事情。
标签: c io cross-platform fseek