繁体   English   中英

fseek(fp, 0, SEEK_CUR) 的副作用是什么

[英]what are the side-effects of fseek(fp, 0, SEEK_CUR)

据推测,这条线应该没有效果; 从当前位置寻找 0 个字节。 但是,我在一些遗留代码中找到了这条线,没有这条线,似乎什么都不起作用——即使在 python 中,具有等效的 fp.seek(0, os.SEEK_CUR)

它只是一个缓冲的东西,还是更深层次的东西?

C 标准规定,在对同一文件句柄的读取写入之间进行更改时,您必须寻找。 C11 7.21.5.3p7

  1. 当以更新模式打开文件时( '+'作为上述模式参数值列表中的第二个或第三个字符),输入和 output 都可以在关联的 stream 上执行。 However, output shall not be directly followed by input without an intervening call to the fflush function or to a file positioning function ( fseek , fsetpos , or rewind ), and input shall not be directly followed by output without an intervening call to a file positioning function,除非输入操作遇到文件结束。 [...]

C 标准修订版C11 7.21.9.2p5fseek的所有副作用:

  1. After determining the new position, a successful call to the fseek function undoes any effects of the ungetc function on the stream, clears the end-of-file indicator for the stream, and then establishes the new position. 成功调用fseek后,更新 stream 的下一个操作可能是输入或 output。

并非所有这些都适用于 Python 3,因为 Python 3 实际上会尽可能绕过 C stdio; Python 也没有暴露ungetc Python 2 文件是标准输入输出流的更薄包装。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM