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()函数的更多相关文章

  1. lseek函数

    所有打开的文件都有一个当前文件偏移量(current file offset),以下简称为 cfo.cfo 通常是一个非负整数,用于表明文件开始处到文件当前位置的字节数.读写操作通常开始于 cfo,并 ...

  2. 《UNIX环境高级编程》笔记--read函数,write函数,lseek函数

    1.read函数 调用read函数从文件去读数据,函数定义如下: #include <unistd.h> ssize_t read(int filedes, void* buff, siz ...

  3. 文件I/O(不带缓冲)之lseek函数

    每个打开的文件都有一个与其相关联的“当前文件偏移量”(current file offset).它通常是一个非负整数,用以度量从文件开始处计算的字节数.通常,读.写操作都从当前文件偏移量处开始,并使偏 ...

  4. C语言lseek()函数:移动文件的读写位置

    相关函数:dup, open, fseek 头文件:#include <sys/types.h>    #include <unistd.h> 定义函数:off_t lseek ...

  5. Linux&C open creat read write lseek 函数用法总结

    一:五个函数的参数以及返回值. 函数                                 参数                      返回值     open (文件名,打开方式以及读 ...

  6. Linux&C open creat read write lseek 函数用法总结

    一:五个函数的参数以及返回值. 函数                                 参数                      返回值     open (文件名,打开方式以及读 ...

  7. lseek函数与文件空洞

    在UNIX/LINUX系统中,文件位移量可以大于文件的当前长度,这种情况下向文件中写入数据就会产生文件空洞(hole),这些没写入数据的文件空洞部分默认会被0填满.虽然这些文件空洞并没有实际的数据,但 ...

  8. 关于位图读取函数int Load_Bitmap_File的lseek问题。

    事情是这样的,本人在编译3D游戏编程大师技巧中的程序是遇到了一个关于位图读取函数int Load_Bitmap_File的lseek问题. 我使用以下位图读取函数读取位图事报错如下: int Load ...

  9. 函数名: lseek

    函数名: lseek 功 能: 移动文件读/写指针 头文件:#include <sys/types.h> #include <unistd.h> 用 法: off_t lsee ...

随机推荐

  1. Xamarin for Visual Studio 破解日志

    一.相关声明 本文涉及的 Xamarin 系列软件的版权为 Xamarin Inc. 所有 以本文涉及的思路和方法破解的软件,禁止用于商业用途 如无必要,学习和研究时最好以正版为准 团队或土豪等若觉得 ...

  2. (1)opengl-nehe 4种框架

    http://www.yakergong.net/nehe/ 这个网站还是opengl方面比较权威的,作者叫nehe 这东西估计是要先装个ndk,然后才能运行代码 先睡觉! 以下内容参考自http:/ ...

  3. spring 主题使用详解[转]

    在common_include_v2.jsp文件中,spring主题的使用: <link href="${staticPath }/<spring:theme code='sty ...

  4. Linux网络编程9——对TCP与UDP的简易封装2.0

    具体生成动态库的操作及使用该动态库的操作请参见上篇博文.以下仅仅列出改进版本的代码. 代码 my_socket.h #ifndef __MY_SOCKET_H__ #define __MY_SOCKE ...

  5. POJ2402/UVA 12050 Palindrome Numbers 数学思维

    A palindrome is a word, number, or phrase that reads the same forwards as backwards. For example,the ...

  6. 快速创建maven 工程:simple java工程,webapp

    http://www.cnblogs.com/buhaiqing/archive/2012/11/04/2754187.html 会从maven的Repository里查找所有支持的arche typ ...

  7. lintcode:Wiggle Sort

    Wiggle Sort Given an unsorted array nums, reorder it in-place such that nums[0] <= nums[1] >= ...

  8. android学习--radiogroup学习

    这个阶段在学习android的相关基本UI现将相关练习的代码粘贴在此便于后期学习之用(radio控件) 效果图:   main_layout.xml <?xml version="1. ...

  9. iOS开发swift--函数

    函数返回值 ---函数 // 自加函数 func Add(num : Int)->Int{ } //自减函数 func zj(num : Int)->Int{ } //定义返回函数类型 f ...

  10. Java学习笔记之:Java Map集合

    一.介绍 通常来说,Map是一个由键值对组成的数据结构,且在集合中每个键是唯一的. 二.笔记 /** * Map:接口. 不是collection的子类 key -value 键值对 key唯一不能重 ...