linux c 语言之--fseek(),fseeko(),fseeko64()讲解 (转载)

转载:http://blog.csdn.net/lemoncyb/article/details/16841317


fseek() 函数讲解:
函数定义:

int fseek(FILE *stream, long offset, int fromwhere);

 

int fseeko(FILE *stream, off_t offset, int fromwhere);

 

int fseeko64(FILE *stream, off64_t offset, int fromwhere);


参数:

stream:文件指针

 

fromwhere:偏移起始位置

 

offset:偏移量


功能:

函数设置文件指针stream的位置。如果执行成功,stream将指向以fromwhere(偏移起始位置:文件头0(SEEK_SET),当前位置1(SEEK_CUR),文件尾2(SEEK_END))为基准,偏移offset(指针偏移量)个字节的位置。如果执行失败(比如offset超过文件自身大小),则不改变stream指向的位置。

 

说明:这几个函数唯一的不同是offset的数据类型不同,相应的能够处理的偏移量的范围也就有大有小。


返回值:

成功,返回0,失败返回-1,并设置errno的值,可以用perror()函数输出错误。
fseek position the file(文件) position(位置) pointer(指针) for the file referenced by stream to the byte location calculated by offset.

 

posted @ 2018-09-19 15:47  张杨  阅读(3069)  评论(0编辑  收藏  举报