2

前回の質問は生データの読み書きについてですが、新たな問題が発生しました。

lseek()問題は、 orのような関数のパラメータfseek()がすべて 4 バイトであることです。4G でスパンを移動したい場合、それは不可能です。私はWin32で関数があることを知っていますSetPointer(...,Hign, Low,....)。このポインターは64バイトのポインターを生成できます。これは私が望むものです。

しかし、Linux または Unix でアプリを作成したい場合 (ファイルを作成するか、未加工のドライブ セクターに直接書き込みます)、どうすれば 4G 経由でポインターに移動できますか?

ありがとう、あなたの返事を待っています...

4

3 に答える 3

6

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

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

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.

于 2009-11-06T11:52:45.800 に答える
5

4 バイトの符号なし整数は、最大 4294967295 の値を表すことができます。つまり、4G を超えて移動したい場合は、lseek64() を使用する必要があります。さらに、fgetpos() および fsetpos() を使用して、ファイル内の位置を変更できます。

于 2009-11-06T09:38:48.127 に答える
2

Windows では、_lseeki64()Linux ではを使用しlseek64()ます。

lseek64()次のようにして、両方のシステムで使用することをお勧めします。

#ifdef _WIN32
#include <io.h>
#define lseek64 _lseeki64
#else
#include <unistd.h>
#endif

それだけです。

于 2009-11-14T15:41:16.283 に答える