码迷,mamicode.com
首页 > 其他好文 > 详细

lseek()函数

时间:2015-11-21 18:32:40      阅读:189      评论:0      收藏:0      [点我收藏+]

标签:

lseek()有个特殊的用途,确定文件是常规文件还是设备。
<pre lang="c" escaped="true">
off_t currpos;
ourrpos = lseek(fd, 0, SEEK_CUR);
if (ourrpos == -1)
{
printf("this is drive file");
}
</pre>
这种方法用来确定文件或者设备是否可以设置偏移量,常规文件都可以设置偏移量,而设备一般是不可以设置偏移量的,如果设备不支持lseek(),则lseek返回-1, 并将errno设备为ESPIPE.


<pre lang="c" escaped="true">
#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
The offset is set to the size of the file plus offset bytes.

</pre>

lseek()函数

标签:

原文地址:http://www.cnblogs.com/liweilijie/p/4984172.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!