[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: ftell, fgetpos, etc.



Hendrik Boom <hendrik@topoi.pooq.com> writes:

[...]

> What I don't know is how to seek around the file in a machine-independent
> manner, and avoid future headaches.

[...]

> (a) use fgetpos and fsetpos
>   This will presumably do random access to anything the machine's file
>   system will handle, but the disk address I get from fgetpos are
>   unliky to be usable on another system.
> (b) use ftell and fseek
>   Now these will solve the problem as long as my files stay small.
>   They provide byte counts from the start of the file, which are
>   semantically independent of the platform, but are just long int, which,
>   last I heard, was 32 bits almost everywhere (and, because of the sign
>   bit are limited to 31 bits in practise).
>
> Is there something else available?  Is there another way to use the tools
> I have already mentioned?  Is there a clean way to move to 64-bit
> relatively system-independent disk addresses?  Is there a standard way?

The very low-level function you are looking for is lseek or lseek64.
That won't play well with the stdio library, unfortunately, but you
may find fseeko() and ftello() will work.  They use a file position
that is of type "off_t", which is usually be 64-bit on newer Unixes
(or at least can be with the right compilation options).  See:

    http://www.unix.org/version2/whatsnew/lfs20mar.html

and the appropriate manpages, and I think that will set you on the
right track.

Good luck!

----Scott.


Reply to: