系统接口:fseek、fsetpos 和 fstat 函数详解
1. fseek 函数
1.1 基本信息
- 名称 :fseek, fseeko — 重新定位流中的文件位置指示器
- 头文件 :
#include <stdio.h>
- 函数原型 :
int fseek(FILE *stream, long offset, int whence);
int fseeko(FILE *stream, off_t offset, int whence);
1.2 功能描述
fseek 函数用于设置由 stream
指向的流的文件位置指示器。若发生读写错误,将设置流的错误指示器,并且 fseek 函数会失败。新的位置(除了使用 open_wmemstream()
打开的流以宽字符为单位测量外,其他以字节为单位)是通过将 offset
加到 whence
指定的位置得到的。 whence
有三种取值:
- SEEK_SET
:文件开头
- SEEK_CUR
:文件位置指示器的当前值
- SEEK_END <