关于文件查找位置的问题 [英] Question about file seeking position

查看:60
本文介绍了关于文件查找位置的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我之前的问题是关于原始数据的读写,但是出现了一个新问题,似乎没有止境....

My previous Question is about raw data reading and writing, but a new problem arised, it seems there is no ending....

问题是:lseek()fseek()之类的函数的参数均为4个字节.如果我想跨4G移动,那是不可能的.我知道在Win32中,有一个函数SetPointer(...,Hign, Low,....),该指针可以生成64个字节的指针,这正是我想要的.

The question is: the parameters of the functions like lseek() or fseek() are all 4 bytes. If i want to move a span over 4G, that is imposible. I know in Win32, there is a function SetPointer(...,Hign, Low,....), this pointers can generate 64 byte pointers, which is what i want.

但是如果我想在Linux或Unix中创建一个应用程序(创建文件或直接写 原始驱动器扇区),如何在4G上移动指针?

But if i want to create an app in Linux or Unix (create a file or directly write the raw drive sectors), How can I move to a pointer over 4G?

感谢,正在等待您的回复...

Thanx, Waiting for your replies...

推荐答案

lseek的offset参数的类型为off_t.在32位编译环境中,此类型默认为32位有符号整数-但是,如果您使用在所有系统包括之前定义的此宏进行编译,则:

The offset parameter of lseek is of type off_t. In 32-bit compilation environments, this type defaults to a 32-bit signed integer - however, if you compile with this macro defined before all system includes:

#define _FILE_OFFSET_BITS 64

...那么off_t将是64位带符号类型.

...then off_t will be a 64-bit signed type.

对于fseekfseeko函数是相同的,只是它使用off_t类型作为偏移量,这也使上述解决方案也可以使用它.

For fseek, the fseeko function is identical except that it uses the off_t type for the offset, which allows the above solution to work with it too.

这篇关于关于文件查找位置的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆