lseek()函数的用法

发布时间:2009-11-24 10:41    发布者:李宽
关键词: lseek , 函数 , 用法
在BT代码的缓冲管理中经常会看到这函数,功能是移动文件的读写指针,可以先在Linux的Sheel下看一下他的函数原型:

NAME
lseek - reposition read/write file offset

SYNOPSIS
#include <sys/types.h>
#include <unistd.h>

off_t lseek(int fd, off_t offset, int whence);

DESCRIPTION
The lseek() function repositions the offset of the open file associated
with the file descriptor fd to the argument  offset  according  to  the
directive whence as follows:

SEEK_SET
The offset is set to offset bytes.

SEEK_CUR
The offset is set to its current location plus offset bytes.

SEEK_END

参数说明:
fd为已打开的文件描述符;
off_t_offset为偏移量,它是根据下面的whence的取值;
whence有3种取值:
SEEK_SET 将读写位置指向文件头后增加offset个位移量;
SEEK_CUR 以目前的读写位置往后增加offset个位移量;
SEEK_END 将读写位置指向文件尾后增加offset个位移量;
但是有时候,在旧的代码中可能看到不是SEEK_XXX这样的参数,这是由于新旧值的原因,下面是他们的对应关系:
旧值                 新值
0                    SEEK_SET
1                    SEEK_CUR
2                    SEEK_END
L_SET             SEEK_SET
L_INCR            SEEK_CUR
L_XTND          SEEK_END

作者:阿吴网志 2009-11-23
本文地址:https://www.eechina.com/thread-5712-1-1.html     【打印本页】

本站部分文章为转载或网友发布,目的在于传递和分享信息,并不代表本网赞同其观点和对其真实性负责;文章版权归原作者及原出处所有,如涉及作品内容、版权和其它问题,我们将根据著作权人的要求,第一时间更正或删除。
您需要登录后才可以发表评论 登录 | 立即注册

厂商推荐

相关视频

关于我们  -  服务条款  -  使用指南  -  站点地图  -  友情链接  -  联系我们
电子工程网 © 版权所有   京ICP备16069177号 | 京公网安备11010502021702
快速回复 返回顶部 返回列表