telldir
来源:互联网 发布:超市广播软件 编辑:程序博客网 时间:2024/04/29 21:48
关函数:open, opendir, closedir, rewinddir, seekdir, readdir, scandir
头文件:#include <dirent.h>
定义函数:off_t telldir(DIR *dir);
函数说明:telldir()返回参数dir 目录流目前的读取位置. 此返回值代表距离目录文件开头的偏移量返回值返回下个读取位置, 有错误发生时返回-1.
错误代码:EBADF 参数dir 为无效的目录流。
范例
#include <sys/types.h>
#include <dirent.h>
#include <unistd.h>
main()
{
DIR *dir;
struct dirent *ptr;
int offset;
dir = opendir("/etc/rc.d");
while((ptr = readdir(dir)) != NULL)
{
offset = telldir (dir);
printf("d_name : %s offset :%d\n", ptr->d_name, offset);
}
closedir(dir);
}
执行结果:
d_name : . offset :12
d_name : .. offset :24
d_name : init.d offset 40
d_name : rc0.d offset :56
d_name : rc1.d offset :72
d_name : rc2.d offset :88
d_name : rc3.d offset :104
d_name : rc4.d offset :120
d_name : rc5.d offset :136
d_name : rc6.d offset :152
d_name : rc offset :164
d_name : rc.local offset :180
d_name : rc.sysinit offset :4096
头文件:#include <dirent.h>
定义函数:off_t telldir(DIR *dir);
函数说明:telldir()返回参数dir 目录流目前的读取位置. 此返回值代表距离目录文件开头的偏移量返回值返回下个读取位置, 有错误发生时返回-1.
错误代码:EBADF 参数dir 为无效的目录流。
范例
#include <sys/types.h>
#include <dirent.h>
#include <unistd.h>
main()
{
DIR *dir;
struct dirent *ptr;
int offset;
dir = opendir("/etc/rc.d");
while((ptr = readdir(dir)) != NULL)
{
offset = telldir (dir);
printf("d_name : %s offset :%d\n", ptr->d_name, offset);
}
closedir(dir);
}
执行结果:
d_name : . offset :12
d_name : .. offset :24
d_name : init.d offset 40
d_name : rc0.d offset :56
d_name : rc1.d offset :72
d_name : rc2.d offset :88
d_name : rc3.d offset :104
d_name : rc4.d offset :120
d_name : rc5.d offset :136
d_name : rc6.d offset :152
d_name : rc offset :164
d_name : rc.local offset :180
d_name : rc.sysinit offset :4096
0 0
- telldir
- opendir,closedir,readdir ,telldir的·使用详解及例子
- opendir、readdir、rewinddir、closedir、telldir、seekdir、stat函数和DIR、dirent、stat结构体详解
- Linux中读取目录: opendir,fdopendir,readdir,rewinddir,closedir,telldir,seekdir
- 10Linux服务器编程之:opendir()函数,readdir()函数,rewinddir()函数,telldir()函数和seekdir()函数,closedir()函数
- linux目录相关函数opendir、readdir、rewinddir、closedir、telldir、seekdir、stat函数和DIR、dirent、stat结构体详解
- symlink
- 第十五周项目一“内部”寻内幕之单步调试
- 计算几何_圆与多边形面积交
- Pro/TOOLKIT入门教程汇总
- 使用js判断访问者是否为移动设备
- telldir
- hdu 4772
- PHP基础篇--PHP类名、函数名、变量大小写敏感问题
- truncate
- About surface shader
- Maximum Depth of Binary Tree
- 读《H.264_mpeg-4_part_10_white_paper》后感
- umask
- 浅谈代码分层:构建模块化程序